Module:Infobox
Jump to navigation
Jump to search
Want an adless experience? Log in or Create an account.
Documentation for this module may be created at Module:Infobox/doc
local Args = require( 'Module:Args' ) local Box = require( 'Module:Box' ).Box local Infobox = Box.new() Infobox.__index = Infobox setmetatable( Infobox, Box ) local p, mt = {}, {} p.Infobox = Infobox function Infobox.new( type, args ) local obj = Box.new( 'light', { class = 'zdw-infobox zdw-infobox--' .. type, title = args.title } ) obj.infoboxArgs = args -- TODO don't like this. would it make sense to preprocess args here and store some other structure(s) on obj? or pass all args to box (more flexibility for callers but breaks encapsulation)? return setmetatable( obj, Infobox ) end -- override function Infobox:renderContent() local args = self.infoboxArgs local content = mw.html.create( 'div' ) -- add logo (TODO better way of loading images?) if args.logo then content:tag( 'div' ) :addClass( 'zdw-label center' ) :wikitext( args.logo ) end -- add image/boxart (TODO better way of loading images?) if args.boxart or args.image then content:tag( 'div' ) :addClass( 'center' ) :wikitext( args.boxart or args.image ) end -- TODO table return tostring( content ) end -- function Infobox:renderContent() function p._main( type, args ) local infobox = Infobox.new( type, args ) return infobox:render() end -- translates p.function( frame ) to p._main( function, args ) function mt.__index( table, key ) return function ( frame ) return table._main( key, Args.fromFrame( frame ) ) end end -- for use in the debug console: -- =p.infoboxType(p.debugFrame) p.debugFrame = { args = { -- #invoke args }, getParent = function() return { args = { -- template args title = 'The Legend of Zelda' } } end } return setmetatable( p, mt )