Module:RequirementBox: Difference between revisions

From Piñata Journal
(Created page with "local p = {} function p.render(frame) local title = frame.args.title or "Game" local game = frame.args.game or "" local state = frame.args.state or "" -- Grab content for each category local appear = frame.args.appear or "" local visit = frame.args.visit or "" local resident = frame.args.resident or "" local romance = frame.args.romance or "" local tricks = frame.args.tricks or "" -- Helper to render a category...")
 
No edit summary
Line 1: Line 1:
-- Module:RequirementBox
local p = {}
local p = {}


function p.render(frame)
-- Helper: render a category block
    local title = frame.args.title or "Game"
local function renderCategory(title, list)
    local game  = frame.args.game or ""
    if list == "" then return "" end
    local state = frame.args.state or ""
    return string.format([[
   
    -- Grab content for each category
    local appear  = frame.args.appear or ""
    local visit    = frame.args.visit or ""
    local resident = frame.args.resident or ""
    local romance  = frame.args.romance or ""
    local tricks  = frame.args.tricks or ""
   
    -- Helper to render a category
    local function renderCategory(title, list)
        if list == "" then return "" end
        return string.format([[
<div class="vp-requirements-category">
<div class="vp-requirements-category">
   <div class="requirements-header">%s</div>
   <div class="requirements-header">%s</div>
   <ul class="vp-requirements-list">
   <ul class="vp-requirements-list">
    %s
%s
   </ul>
   </ul>
</div>
</div>]], title, list)
]], title, list)
end
     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 content to allow full wiki markup
    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 the requirements HTML
     -- Build the requirements HTML
     local requirementsHTML = '<div class="vp-requirements">\n'
     local html = renderCategory("Appear", appear)
    requirementsHTML = requirementsHTML .. renderCategory("Appear", appear)
     html = html .. renderCategory("Visit", visit)
     requirementsHTML = requirementsHTML .. renderCategory("Visit", visit)
     html = html .. renderCategory("Resident", resident)
     requirementsHTML = requirementsHTML .. renderCategory("Resident", resident)
     html = html .. renderCategory("Romance", romance)
     requirementsHTML = requirementsHTML .. renderCategory("Romance", romance)
     html = html .. renderCategory("Tricks", tricks)
     requirementsHTML = requirementsHTML .. renderCategory("Tricks", tricks)
 
    requirementsHTML = requirementsHTML .. '\n</div>'
     -- Details open attribute
   
     -- Build the top-level <details>
     local openAttr = ""
     local openAttr = ""
     if state ~= "mw-collapsed" and state ~= "" then
     if state ~= "mw-collapsed" then
         openAttr = ' open="open"'
         openAttr = ' open="open"'
    elseif state == "" then
        openAttr = ' open="open"'  -- default open
     end
     end
      
 
     local html = string.format([[
     -- Build final <details> box
<details class="vp-gamebox"%s>
     local details = string.format([[
<details class="vp-gamebox"%s data-game="%s">
   <summary class="vp-gamebox-header">%s</summary>
   <summary class="vp-gamebox-header">%s</summary>
   <div class="vp-gamebox-content">
   <div class="vp-gamebox-content">
    %s
%s
   </div>
   </div>
</details>
</details>]], openAttr, game, title, html)
]], openAttr, title, requirementsHTML)
 
   
     return details
     return html
end
end


return p
return p

Revision as of 02:45, 3 January 2026

Documentation for this module may be created at Module:RequirementBox/doc

-- Module:RequirementBox
local p = {}

-- Helper: render a category block
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 content to allow full wiki markup
    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 the 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)

    -- Details open attribute
    local openAttr = ""
    if state ~= "mw-collapsed" then
        openAttr = ' open="open"'
    end

    -- Build 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)

    return details
end

return p