Module:InfoboxHero: Difference between revisions

Jump to navigation Jump to search
Vergir (talk | contribs)
Create Lua implementation of the hero infobox, to replace the wikitext in Template:Infobox hero (with help from vergir-bot LLM)
 
Vergir (talk | contribs)
Fix parameter resolution for direct #invoke, and set DISPLAYTITLE via parser function instead of returning it as wikitext (with help from vergir-bot LLM)
Line 27: Line 27:


local util        = require('Module:Utilities')
local util        = require('Module:Utilities')
local lang_module = require('Module:Lang')
local lang_module = require('Module:Lang')
local dict_module = require('Module:Dictionary')
local dict_module = require('Module:Dictionary')
local hero_module = require('Module:HeroData')
local hero_module = require('Module:HeroData')


-- Defined below the CONFIG block; declared here so config closures can see them.
-- Defined below the CONFIG block; declared here so config closures can see them.
Line 732: Line 732:
function p.render(frame)
function p.render(frame)
local parent = frame:getParent()
local parent = frame:getParent()
local raw_args = parent and parent.args or frame.args
local invoke_args = frame.args
local template_args = parent and parent.args or {}


-- Missing parameters read as '' so callers never have to nil-check.
-- Missing parameters read as '' so callers never have to nil-check.
local args = setmetatable({}, { __index = function(_, k) return raw_args[k] or '' end })
local args = setmetatable({}, { __index = function(_, k)
local value = invoke_args[k]
if value == nil then value = template_args[k] end
return value or ''
end })


local hero_key = resolve_hero_key(args.key)
local hero_key = resolve_hero_key(args.key)
Line 776: Line 781:
render_information(ctx, tbl)
render_information(ctx, tbl)


local out = tostring(root)
if mw.title.getCurrentTitle().nsText ~= 'Template' then
if mw.title.getCurrentTitle().nsText ~= 'Template' then
out = out .. '{{DISPLAYTITLE:' .. ctx.display_name .. '}}'
frame:callParserFunction('DISPLAYTITLE', ctx.display_name)
end
end
return out .. render_categories(ctx)
return tostring(root) .. render_categories(ctx)
end
end


return p
return p