Module:Infocard: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 9: | Line 9: | ||
require('Module:No globals') | require('Module:No globals') | ||
local m_util = require('Module:Util') | local m_util = require('Module:Util') | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
Line 87: | Line 78: | ||
:node(args.below) | :node(args.below) | ||
end | end | ||
return | return tostring(html) | ||
end | end | ||
Line 99: | Line 88: | ||
p.main = m_util.misc.invoker_factory(_main, { | p.main = m_util.misc.invoker_factory(_main, { | ||
wrappers = | wrappers = { | ||
'Template:Infocard', | |||
}, | |||
}) | }) | ||
Latest revision as of 18:50, 1 January 2025
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:Infocard and is used by a number of other
-- modules to display info cards.
-------------------------------------------------------------------------------
require('Module:No globals')
local m_util = require('Module:Util')
-- ----------------------------------------------------------------------------
-- Main function
-- ----------------------------------------------------------------------------
local function _main(args)
args.heading = args.heading or args.header
args.subheading = args.subheading or args.subheader
local html = mw.html.create('div')
:addClass('info-card')
if args.class then
html:addClass(args.class)
end
if args.above then
html
:tag('div')
:addClass('info-card__above')
:node(args.above)
end
local card = mw.html.create('div')
:addClass('info-card__card')
local header = mw.html.create('div')
:addClass('info-card__header')
header
:tag('div')
:addClass('left')
:wikitext(args.headerleft or '')
local middle = mw.html.create('div')
:addClass('middle')
middle
:tag('div')
:addClass('heading')
:wikitext(args.heading)
if args.subheading then
middle
:tag('div')
:addClass('subheading')
:wikitext(args.subheading)
end
header
:node(middle)
header
:tag('div')
:addClass('right')
:wikitext(args.headerright or '')
card:node(header)
local body = mw.html.create('div')
:addClass('info-card__body')
local block
for i=1, math.huge do -- repeat until no more blocks are found
if args[i] == nil then
break
end
block = mw.html.create('div')
:addClass('block')
if args[i .. 'class'] then
block:addClass(args[i .. 'class'])
end
block:node(args[i])
body:node(block)
end
card:node(body)
html:node(card)
if args.below then
html
:tag('div')
:addClass('info-card__below')
:node(args.below)
end
return tostring(html)
end
-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------
local p = {}
p.main = m_util.misc.invoker_factory(_main, {
wrappers = {
'Template:Infocard',
},
})
p.infocard = p.main
p._main = p.main -- Contingency for modules that are still calling p._main()
return p