--[[ A Lua helper module for rendering Capiunto infoboxes. Originally written on the English Wikipedia by Toohool and Mr. Stradivarius. Code released under the GPL v2+ as per: https://en.wikipedia.org/w/index.php?diff=next&oldid=581399786 https://en.wikipedia.org/w/index.php?diff=next&oldid=581403025 @license GNU GPL v2+ @author Marius Hoch < hoo@online.de > ]] local render = {} -- Renders the outer wrapper for an infobox. -- Returns the mw.html object for the new infobox -- -- @param html -- @param args function render.renderWrapper( html, args ) if not args.isChild then local table = html :tag( 'table' ) :addClass( 'mw-capiunto-infobox' ) :attr( 'cellspacing', 3 ) if args.bodyClass then table :addClass( args.bodyClass ) end if args.isSubbox then table :addClass( 'mw-capiunto-infobox-subbox' ) end if args.bodyStyle then table :cssText( args.bodyStyle ) end return table else html :wikitext( args.title ) return html end end -- Adds a table header to html -- -- @param html -- @param args -- @param header -- @param class function render.renderHeader( html, args, header, class ) local th = html:tag( 'tr' ) :tag( 'th' ) :attr( 'colspan', 2 ) :addClass( 'mw-capiunto-infobox-header' ) :wikitext( header ) if class then th:addClass( class ) end if args.headerStyle then th:cssText( args.headerStyle ) end end -- Adds a row to the infobox, with either a header cell -- or a label/data cell combination. -- -- @param html -- @param args -- @param row function render.renderRow( html, args, row ) local tr = html:tag( 'tr' ) if row.rowClass then tr:addClass( row.rowClass ) end if row.label then local th = tr:tag( 'th' ) :attr( 'scope', 'row' ) :addClass( 'mw-capiunto-infobox-label' ) :wikitext( row.label ) if args.labelStyle then th:cssText( args.labelStyle ) end end local dataCell = tr:tag( 'td' ) if not row.label then dataCell :attr( 'colspan', 2 ) :addClass( 'mw-capiunto-infobox-spanning' ) end if row.class then dataCell :addClass( row.class ) end if row.dataStyle then dataCell :cssText( row.dataStyle ) end dataCell :newline() :wikitext( row.data ) end -- Adds arbitrary wikitext -- -- @param html -- @param text function render.renderWikitext( html, text ) render.renderRow( html, {}, { data = text } ) end -- Renders the title of the infobox into a caption -- -- @param args function render.renderTitle( html, args ) if not args.title then return end local caption = html :tag( 'caption' ) :wikitext( args.title ) if args.titleClass then caption:addClass( args.titleClass ) end if args.titleStyle then caption:cssText( args.titleStyle ) end end -- Adds a