Module:RequirementBox
Documentation for this module may be created at Module:RequirementBox/doc
local p = {}
local function renderCategory(title, list)
if list == "" then return "" end
return string.format([[
<div class="vp-requirements-category">
<div class="requirements-header">%s</div>
<ul class="vp-requirements-list">
%s
</ul>
</div>]], title, list)
end
function p.render(frame)
local args = frame.args
local title = args.title or "Game"
local game = args.game or ""
local state = args.state or ""
-- preprocess each category to allow raw wikitext
local appear = frame:preprocess(args.appear or "")
local visit = frame:preprocess(args.visit or "")
local resident = frame:preprocess(args.resident or "")
local romance = frame:preprocess(args.romance or "")
local tricks = frame:preprocess(args.tricks or "")
-- build requirements HTML
local html = renderCategory("Appear", appear)
html = html .. renderCategory("Visit", visit)
html = html .. renderCategory("Resident", resident)
html = html .. renderCategory("Romance", romance)
html = html .. renderCategory("Tricks", tricks)
-- decide whether <details> is open
local openAttr = ""
if state ~= "mw-collapsed" then
openAttr = ' open="open"'
end
-- final details box
local details = string.format([[
<details class="vp-gamebox"%s data-game="%s">
<summary class="vp-gamebox-header">%s</summary>
<div class="vp-gamebox-content">
%s
</div>
</details>]], openAttr, game, title, html)
-- <<< THIS IS THE KEY: RETURN RAW HTML >>>
return mw.html.create("div"):html(details):allDone()
end
return p