Module:RequirementBox: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1: Line 1:
-- Module:RequirementBox
local p = {}
local p = {}


-- Helper: render a category block
local function renderCategory(title, list)
local function renderCategory(title, list)
     if list == "" then return "" end
     if list == "" then return "" end
Line 16: Line 14:
function p.render(frame)
function p.render(frame)
     local args = frame.args
     local args = frame.args
     local title    = args.title or "Game"
     local title    = args.title or "Game"
     local game    = args.game or ""
     local game    = args.game or ""
     local state    = args.state or ""
     local state    = args.state or ""


     -- Preprocess content to allow full wiki markup
     -- preprocess each category to allow raw wikitext
     local appear  = frame:preprocess(args.appear or "")
     local appear  = frame:preprocess(args.appear or "")
     local visit    = frame:preprocess(args.visit or "")
     local visit    = frame:preprocess(args.visit or "")
Line 28: Line 25:
     local tricks  = frame:preprocess(args.tricks or "")
     local tricks  = frame:preprocess(args.tricks or "")


     -- Build the requirements HTML
     -- build requirements HTML
     local html = renderCategory("Appear", appear)
     local html = renderCategory("Appear", appear)
     html = html .. renderCategory("Visit", visit)
     html = html .. renderCategory("Visit", visit)
Line 35: Line 32:
     html = html .. renderCategory("Tricks", tricks)
     html = html .. renderCategory("Tricks", tricks)


     -- Details open attribute
     -- decide whether <details> is open
     local openAttr = ""
     local openAttr = ""
     if state ~= "mw-collapsed" then
     if state ~= "mw-collapsed" then
Line 41: Line 38:
     end
     end


     -- Build final <details> box
     -- final details box
     local details = string.format([[
     local details = string.format([[
<details class="vp-gamebox"%s data-game="%s">
<details class="vp-gamebox"%s data-game="%s">
Line 50: Line 47:
</details>]], openAttr, game, title, html)
</details>]], openAttr, game, title, html)


     return details
    -- <<< THIS IS THE KEY: RETURN RAW HTML >>>
     return mw.html.create("div"):html(details):allDone()
end
end


return p
return p