This module depends on the following other modules: |
The above documentation is transcluded from Module:Infocard/doc.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
-------------------------------------------------------------------------------
--
-- Module:Infocard
--
-- This module implements Template:Infocard2 and is used by a number of other
-- modules to display info cards.
-------------------------------------------------------------------------------
local getArgs -- Lazy load require('Module:Arguments').getArgs
local cfg = {}
-- Wrapper templates
cfg.wrappers = {
'Template:Infocard',
'Template:Infocard2',
}
-- ----------------------------------------------------------------------------
-- Main function
-- ----------------------------------------------------------------------------
local function _main(args)
local container = mw.html.create('div')
:attr( 'class', 'infocard ' .. (args.class or '') )
local topbar = mw.html.create('div')
:attr('class', 'topbar')
topbar
:tag('div')
:attr('class', 'left')
:wikitext(args.headerleft)
:done()
local middle = mw.html.create('div')
:attr('class', 'middle')
middle
:tag('div')
:attr('class', 'header')
:wikitext(args.header)
:done()
if args.subheader then
middle
:tag('div')
:attr('class', 'subheader')
:wikitext(args.subheader)
:done()
end
topbar
:node(middle)
topbar
:tag('div')
:attr('class', 'right')
:wikitext(args.headerright)
:done()
container
:node(topbar)
local inner = mw.html.create('div')
:attr('class', 'inner')
local block
local i = 1
while args[i] do
block = mw.html.create('div')
:attr( 'class', 'block ' .. (args[i .. 'class'] or '') )
if type(args[i]) == 'table' then
block:node(args[i])
elseif type(args[i]) == 'string' then
block:wikitext(args[i])
end
inner:node(block)
i = i + 1
end
container:node(inner)
return tostring(container)
end
-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------
local p = {}
function p.main(frame)
local args
if type(frame.args) == 'table' then
-- Called via #invoke, so use getArgs().
getArgs = require('Module:Arguments').getArgs
args = getArgs(frame, {
wrappers = cfg.wrappers
})
else
-- Called from another module or from the debug console, so assume args
-- are passed in directly.
args = frame
end
return _main(args)
end
p.infocard = p.main
p._main = p.main -- Contingency for modules that are still calling p._main()
return p