Module:IBox
Appearance
Documentation for this module may be created at Module:IBox/doc
local p = {}
local yn = require('Module:Yesno')
-- Start the table
function p.start(frame)
local args = frame:getParent().args
local mode = args.mode == 'infotable' and 'infotable' or 'infobox'
--CSS computations
local css = mode..' box colored bordered innerbordered fill-td type-'
if yn(args.type, true) then css = css..mw.text.split(args.type, " ")[1] else css = css..'basic' end
if not (args.bullets == 'on') then css = css..' list-noicon' end
if args.float == 'left' then css = css..' float-left-clear'
else css = css..' float-right-clear'
end
css = css..' '..(args.class or '')
--Start the box
local page = mw.title.getCurrentTitle().text
local text = '<table class="'..css..'"><tr><th colspan=2 class=mainheader>'
if mode == 'infotable' then
if yn(args.ref, true) then text = text..'<span class="ref">'..args.ref..'</span>' end
text = text ..'<span class="maintitle">'..page..'</span>'
if yn(args.subtitle, true) then text = text..'<span class="subtitle">'..args.subtitle..'</span>' end
text = text..'</th></tr><tr><td class="imagecell">'
if yn(args["image name"], true) then
text = text..'[[File"'..args["image name"]..'|'..(args["image size"] or '300px')..
'|'..(args["image caption"] or page)..']]'
elseif args.image then text = text..args.image
end
text = text..'</td><td class=infocell><table class=sub-infotable>'
else --Infobox
if args.editlink then
text = text..'<span class="plainlinks edit-infobox">['..
tostring(mw.uri.fullUrl(args.editlink..':'..page,'action=formedit'))..
' edit]</span>'
end
text = text..(args[1] or page)..(args.ref or '')..'</th></tr>'
if yn(args['image name'], true) then
text = text..'<tr><td colspan="2" class="imagecell">'..
frame:expandTemplate{ title = 'IBox/ImageFormat', args = {
args['image name'],
size = args['image size'],
caption = args['image caption']
} }..'</td></tr>'
elseif args.image then text = text..'<tr><td colspan="2" class="imagecell">'..args.image..'</td></tr>'
end
if yn(args.subtitle, true) then
text = text..'<tr><td colspan=2 class="mainheader lightheader">'..
args.subtitle..'</td></tr>'
end
end
return text
end
-- Generates a single row
function p.row(frame)
local args = frame:getParent().args
if args.condition == '' then return '' end
local tr
if args.class then tr = '<tr class="'..args.class..'">'
else tr = "<tr>"
end
local th = mw.html.create('th'):wikitext(args[1])
if args.labelclass then th:addClass(args.labelclass) end
local td = mw.html.create('td'):wikitext(args[2] or args.default)
if args.valueclass then td:addClass(args.valueclass) end
if args.lang then td:attr('lang', args.lang) end
return tr..tostring(th)..tostring(td)..'</tr>'
end
-- Generates a header
function p.header(frame)
local args = frame:getParent().args
if args.condition == '' then return '' end
local tr = mw.html.create('tr')
:tag('th'):attr('colspan', 2)
:addClass('mainheader '..(args.class or ''))
:wikitext(args[1]):done()
return tostring(tr)
end
-- Generates the ending part
function p.ending(frame)
local args = frame:getParent().args
if args.mode == 'infotable' then return '</table></table>'
else return '</table>'
end
end
-- Collapsible boxes
function p.box(frame)
local args = frame:getParent().args
if args.condition == '' then return '' end
local text = '<tr><td colspan="2" class=clearcell><table class="box cellbox '
local st = args.hide
if st == 'always' then text = text..'mw-collapsible mw-collapsed">'
elseif st == 'never' then text = text..'">'
else
text = text..'mw-collapsible'
if yn(args.collapsible) or args.collapsible == 'collapsed' then
text = text..' mw-collapsed">'
else text = text..'">'
end
end
text = text..'<tr><th class="mainheader '..(args.labelclass or '')..'">'..
(args[1] or '')..'</th></tr><tr><td class="'..(args.valueclass or args.default or '')..'">'..
(args[2] or '')..'</td></tr></table></td></tr>'
return text
end
return p
--[[Category:Lua Modules]]