Documentation for this module may be created at Module:Infobox/doc
-- <nowiki>
--
-- Implements {{Infobox}} and [[Category:Infobox templates|other infoboxes]]
--
local p = {}
local main = require( 'Module:Mainonly' )._main
--
-- Every method here is kept public, even if it's not for use through #invoke
-- this is so they can be used in other infobox modules if absolutely necessary
-- @example [[Module:Infobox/Monster]]
--
function p._insertRow( tbl )
return tbl
:tag( 'tr' )
end
function p._createTbl( args )
local tbl = mw.html.create( 'table' )
:addClass( 'wikia-infobox' )
:css( 'width', '100%' )
:cssText( args.tstyle or '' )
return tbl
end
function p._caption( tbl, name )
return tbl
:tag( 'caption' )
:wikitext( name )
:done()
end
function p._row( tbl, title, info, tstyle, istyle )
local tr = p._insertRow( tbl )
if title then
tr
:tag( 'th' )
:wikitext( title )
:css( 'white-space', 'nowrap' )
:cssText( tstyle or '' )
:done()
:tag( 'td' )
:wikitext( info )
:cssText( istyle or '' )
:done()
else
tr
:tag( 'td' )
:attr( 'colspan', '2' )
:wikitext( info )
:cssText( istyle or '' )
:done()
end
return tr
:allDone()
end
function p._navlinks( tbl, args, frame )
local links = args.text
if not links and args.page then
links = frame:preprocess( '[[Template:' ..
args.page .. '|[view]]] • [{{fullurl:Template talk:' ..
args.page .. '}} [talk]]' )
else
links = ''
end
tbl = p._insertRow( tbl )
:tag( 'td' )
:attr( 'colspan', '2' )
:addClass( 'infobox-bottom-links' )
:css( {
['font-size'] = 'xx-small',
['text-align'] = 'right',
['background-color'] = '#fff8dc',
['border-color'] = '#fff8dc',
['border-top-color'] = '#aaa'
} )
:cssText( args.nstyle or '' )
:wikitext( links )
return tbl
:allDone()
end
--
-- For use by other infobox modules
--
function p._infobox( _args )
local args = {}
for k, v in pairs( _args ) do
if v ~= '' then
args[k] = v
end
end
local frame = mw.getCurrentFrame()
local wrapper = mw.html.create( 'div' )
:addClass( 'infobox-wrapper' )
:css( {
float = 'right',
width = '33%',
display = 'table',
clear = 'right'
} )
local tbl = p._createTbl( args )
tbl = p._caption( tbl, ( args.name or frame:preprocess( '{{PAGENAME}}' ) ) )
local j
for i = 1, 20 do
j = tostring( i )
if args['r' .. j .. 'info'] then
tbl = p._row(
tbl, args['r' .. j .. 'title'],
args['r' .. j .. 'info'], args['r' .. j .. 'tstyle'],
args['r' .. j .. 'istyle']
)
else
break
end
end
tbl = p._navlinks( tbl, args, frame )
-- end
wrapper
:wikitext( tostring( tbl ) )
return tostring( wrapper )
end
--
-- For use in {{Infobox}}
--
function p.infobox( frame )
local args = frame:getParent().args
return p._infobox( args )
end
return p