Extension:Capiunto/Infobox

From Linux Web Expert

Capiunto provides flexible Infobox functionality for Scribunto.

With Capiunto, Lua code to create a basic Infobox might look like this:

local capiunto = require 'capiunto'
capiunto.create( {
	title = 'Title of the Infobox'
} )
:addRow( 'A label', 'some data' )
:addHeader( 'A header between the data rows' )
:addRow( 'Another label', 'more data' )

After creating an Infobox using the create method, content can be added in the order it will appear on the page using the various add* functions explained below.

To convert the Infobox metatable to html either call infobox:getHtml (which will return a mw.html instance with the infobox) or Lua's tostring() can be used. Also just returning the Infobox metatable is ok as Scribunto will automatically convert it to a string in order to display it on the wiki page.

Functions documented as capiunto.name are available on the global capiunto table; functions documented as capiunto:name are methods of an capiunto object (see capiunto.create).

capiunto.create

capiunto.create( options )

Creates a new Infobox object, with the given options. Supported options are:

  • options.isChild: If set the Infobox will be made embeddable into another Infobox (it eg. wont have an own border).
  • options.isSubbox: If set the Infobox will also be made embeddable into another Infobox, but preserve an own border.

Options for an Infobox title

  • options.title: Text to put in the caption above the table (or as as section header before the whole content of this table, if this is a child Infobox marked with options.isChild).
  • options.titleClass: This parameter is inserted into the class attribute for the Infobox's options.title caption.
  • options.titleStyle: Applies only to the options.title caption. Adding a background color is usually inadvisable since the text is rendered "outside" the Infobox.

Options regarding text above the Infobox

  • options.top: Text to put within the topmost cell of the table (default font size is 125%).
  • options.topClass: This parameter is inserted into the class attribute for the Infobox's options.top cell.
  • options.topStyle: Applies only to the options.top cell at the top of the Infobox. The default style has font-size:125%; since this cell is usually used for a title.

Options specific to images

  • options.captionStyle: Style which applies to the text of image captions.
  • options.imageStyle: Applies to the cells the images are in. This includes the text of the image caption, but for captions, you should set properties instead with options.captionStyle instead
  • options.imageClass: This parameter is inserted into the class attribute of all cells wrapping images.

Options regarding text below the Infobox

  • options.bottom: Text to placed in the bottom cell, this could be used for footnotes, see-also, and other such information.
  • options.bottomClass: This parameter is inserted into the class attribute for the Infobox's options.bottom cell.
  • options.bottomStyle: Applies only to the options.bottom cell at the bottom of the Infobox.

Options regarding data styling

  • options.bodyClass: This parameter is inserted into the class attribute for the Infobox as a whole.
  • options.bodyStyle: Applies to the Infobox table as a whole.
  • options.headerStyle: Applies to all header cells.
  • options.labelStyle: Applies to all label cells.
  • options.dataStyle: Applies to all data cells.

capiunto:getHtml

infobox:getHtml()

Returns a mw.html object holding the html the Infobox consists of. This can easily be converted into a string using tostring().

Example:

local capiunto = require 'capiunto'
local infobx = capiunto.create( {
	-- ...
} )
local html = tostring( infobox:getHtml() )

capiunto:addSubHeader

infobox:addSubHeader( text )
infobox:addSubHeader( text, class )
infobox:addSubHeader( text, class, style )

Adds a subheader, which will show at the top of the infobox, below the title and top text, with the given text to the Infobox. Optionally it's possible to pass raw CSS in the style parameter and a CSS class in the class one.

capiunto:addImage

infobox:addImage( image )
infobox:addImage( image, caption )
infobox:addImage( image, caption, class )

Adds an image (passed as wikitext like [[File:Foo.png]]) to the Infobox. Optionally a caption can be added after the image. Also a CSS class can be passed which will be added to the table row wrapping the image.

capiunto:addRow

infobox:addRow( label, data )
infobox:addRow( label, data, class )
infobox:addRow( label, data, class, rowClass )

Adds a data row to the Infobox with the given label (can also be left empty) and data. Optionally a rowClass which will apply to the whole table row and a class which will only apply to data can be added.

Please note that the rows added with this function, capiunto:addWikitext and capiunto:addHeader will be rendered in the order they have been added to the Infobox.

capiunto:addHeader

infobox:addHeader( header )
infobox:addHeader( header, class )

Adds a header row to the Infobox with the given text (header). Optionally a class which will apply to header can be added.

Please note that the rows added with this function, capiunto:addWikitext and capiunto:addRow will be rendered in the order they have been added to the Infobox.

capiunto:addWikitext

infobox:addWikitext( text )

Adds arbitrary wikitext to the Infobox. This can eg. be a child capiunto instance which has been casted to string by using Lua's tostring().

Please note that the rows added with this function, capiunto:addHeader and capiunto:addRow will be rendered in the order they have been added to the Infobox.

CapiuntoInfoboxRender

CapiuntoInfoboxRender is a module internally used for the rendering the Infobox. It is not supposed to be used outside of Capiunto as its interfaces can change at any time.