Module:VariantGrid
From Piñata Journal
More actions
Documentation for this module may be created at Module:VariantGrid/doc
local p = {}
local function notEmpty(val)
return val and mw.text.trim(val) ~= ""
end
local function renderImage(label, file)
if not notEmpty(file) then return "" end
local fileLink = '[[File:' .. file .. '|200px]]'
return '<div class="vp-variant-image">' ..
'<div class="vp-variant-image-label">' .. label .. '</div>' ..
fileLink ..
'</div>'
end
local function renderGameRequirement(frame, game, content)
if not notEmpty(content) then return "" end
return frame:expandTemplate{
title = "RequirementBox",
args = {
game = game,
evolve = content,
evolve_first = "true"
}
}
end
local function renderVariant(frame, args)
local name = args.name or "Unnamed Variant"
local html = '<div class="vp-variant-block">'
html = html .. '<h3 class="vp-variant-title">' .. name .. '</h3>'
-- Images
html = html .. '<div class="vp-variant-images">'
html = html .. renderImage("Console (VP1/TIP)", args.img_console)
html = html .. renderImage("Pocket Paradise", args.img_pp)
html = html .. renderImage("Pinarctic (TIP)", args.img_pinarctic)
html = html .. renderImage("Dessert Desert (TIP)", args.img_dessert)
html = html .. '</div>'
-- Requirements
html = html .. '<div class="vp-variant-requirements">'
html = html .. renderGameRequirement(frame, "vp1", args.vp1)
html = html .. renderGameRequirement(frame, "tip", args.tip)
html = html .. renderGameRequirement(frame, "pp", args.pp)
html = html .. '</div>'
html = html .. '</div>'
return html
end
function p.render(frame)
local args = frame:getParent().args
local output = '<div class="vp-variants-container">'
local i = 1
while args["variant" .. i] do
local variantFrame = frame:newChild{
title = "PinataVariant",
args = {}
}
-- Parse subtemplate manually
local variantArgs = frame:preprocess(args["variant" .. i])
output = output .. variantArgs
i = i + 1
end
output = output .. '</div>'
return output
end
return p