Module:InfoboxBuilder/doc

This module creates an infobox using the builder pattern. All infoboxes using this module can be found at Category:Infobox modules.

Building an infobox
For an infobox to be built without errors, certain essential functions must be called before others. The following table details groups of functions and their priorities. The lower the number, the higher the priority. The functions  and   are not required, but their CSS changes will not be applied if called later. In addition, the functions that add rows to the table,,  , and   are not all required, but is it recommended to use at least   and.

Set the infobox name
Setting the infobox name sets the template that the infobox links to inside of the navbar.

Define the parameters
When defining the parameters, the arguments will be processed when given a function or table. is an optional processing function or table that will transform the raw argument value into a specific format. An optional default value for the raw argument can be set using the  option.

An example of using  would be to have   be a function that splits a comma separated list into a table in Lua.

Process the arguments
Processing the arguments will set default value (if it exists) and turn the raw argument passed in from setArgs(args) into a processed format for each parameter. This step is required or else the infobox will not work.

Specify a category map
A category map can be optionally set. This uses the processed argument and generates the correct categories.

Prepare
Create the look of the infobox by adding headers, images, or rows. If the values shown in these cells use values from parameters, an optional postprocessing function or table  will transform the processed arguments for display purposes.

Build
To build the infobox from data into an HTML table, call the tostring function.

Get the categories from the category map
To get the categories, call the  function.

Functions
For the following functions, assume an InfoboxBuilder object called "infobox" already exists.

new
This function is required.

Creates a new InfoboxBuilder object.

↓ Jump to definition

setName
This function is required. This function is chainable.


 * arg

should be a. Setting the infobox name will link the navbar to the correct template page and template talk page.

↓ Jump to definition

setHeaderTextColor
This function is optional. This function is chainable.


 * arg

should be a  that contains a valid CSS color (hex code, rgb value, hsl value, etc.). Calling this function will change the color of the text in the infobox's headers and subheaders. The changes will not apply to headers added before this function is called, so it is recommended to call this function early.

↓ Jump to definition

setHeaderBackgroundColor
This function is optional. This function is chainable.


 * arg

should be a  that contains a valid CSS color (hex code, rgb value, hsl value, etc.). Calling this function will change the background color of the infobox's headers and subheaders. The changes will not apply to headers added before this function is called, so it is recommended to call this function early.

↓ Jump to definition

setParams
This function is required. This function is chainable.

This function sets the valid parameters, their default values, and their formatting.

The arguments passed in should be tables of format:


 * paramName

should be a valid  that is unique. This name serves the key used to grab the raw values from the  table passed in from. It also serves as the key for each parameter and will be referenced later.


 * processingFn

should be a  or a   that transforms the raw value of the argument passed in. This value is optional.

A collection of predefined processing functions can be found at Module:ProcessingFunctions.


 * default

should be a string that serves as the default value if no raw value is present for the key in the  table. This value is optional.

↓ Jump to definition

setArgs
This function is required. This function is chainable.


 * args

should be a  with key value pairs representing parameter names and values.

↓ Jump to definition

getRawArgs
This function returns the "private"  associative array containing the raw values passed in from.

↓ Jump to definition

getProcessedArgs
This function returns the "private"  associative array after being processed.

↓ Jump to definition

getArgs

 * which

should be a  that is either "raw" or "processed" for the raw argument values or processed argument values, respectively.

This function returns the "private"  or   associative arrays depending on the value of.

↓ Jump to definition

setCategoryMap
This function is optional. This function is chainable.


 * catMap

should be a  of  s, where the key of the outer table corresponds with a parameter name and the key of the inner tables correspond with possible values of the associated parameter. The inner table values should be the category name related to each parameter value.

↓ Jump to definition

getCategories
This function returns a  with autogenerated categories in wikitext form.

↓ Jump to definition

processArgs
This function is required. This function is chainable.

This function processes the all the arguments passed in with the given processing functions defined when setting parameters.

↓ Jump to definition

addHeader
This function is optional, but recommended. This function is chainable.

This functions adds a header or subheader to the infobox, depending on the option set.


 * arg

should be a  of the following format:


 * tag

should be a  of value "argth" or "th".


 * content

When  is set to "th",   should contain the wikitext that will show up.

When  is set to "argth",   should be a   or   of parameter names. This value will be passed into  if it is set.


 * displayFn

should be a  that transforms one or more processed arguments (based on   into something that can be displayed (ex. an HTML list). The order of the parameters in this function is the same as the order of, if   is a  . This value is optional.

A collection of predefined display functions can be found at Module:DisplayFunctions.


 * attr

should be a  containing HTML attributes. The value gets passed into the mw.html:attr function. This value is optional.


 * colspan

should be a  or   denoting the number of columns this header spans. This value is optional.


 * rowspan

should be a  or   denoting the number of rows this header spans. This value is optional.


 * css

should be a  of CSS names and values. The value gets passed into the mw.html:css function. This value is optional.


 * options

should be a  of the following format:


 * hideIfEmpty

should be a  containing strings of parameter names. If all values for those parameters are empty, then the header or subheader is hidden. This value is optional.


 * subheader

should be a  denoting whether the header should be a subheader or not. The default value is false. This value is optional.

↓ Jump to definition

addImage
This function is optional, but recommended. This function is chainable.

This function adds a single image or multiple images inside of a row. For multiple images, it selectively hides all but one image using TabberNeue.


 * cols

should be a  that is a numeric array. Each entry in this table should have the following format:


 * tag

should be a  of value "argtd" or "td".


 * content

When  is set to "td",   should be a   that shows up as the wikitext.

When  is set to "argtd",   should be a   or   of parameter names. This value will be passed into  if it is set.


 * displayFn

should be a  that transforms one or more processed arguments (based on   into something that can be displayed (ex. an HTML list). The order of the parameters in this function is the same as the order of, if   is a  . This value is optional.


 * tabName

should be a  if there are multiple images. The value of this does nothing if there's only one image.


 * required

should be a  if the tab is required. This means that even if no value is provided, the tab will show up with a '?'.


 * options

should be a  of the following format:


 * hideIfEmpty

should be a containing strings of parameter names. If all values for those parameters are empty, then the image section is hidden. This value is optional.

↓ Jump to definition

addRow
This function is optional, but recommended. This function is chainable.

This function adds anywhere from 1 to 30 cells to a row. The colspan for each cell is automatically set to be evenly split so that all cells are the same width. The exception is when there are two cells, where the first cell spans 12 columns and the second cell spans 18 cells.


 * cols

should be a  that is a numeric array. Each entry in this table should have the following format:


 * tag

should be a  of value "argth", "argtd", "th", or "td".


 * content

When  is set to "td" or "th",   should contain the wikitext that will show up.

When  is set to "argtd" or "argth",   should be a   or   of parameter names. This value will be passed into  if it is set.


 * displayFn

should be a  that transforms one or more processed arguments (based on   into something that can be displayed (ex. an HTML list). The order of the parameters in this function is the same as the order of, if   is a  . This value is optional.

A collection of predefined display functions can be found at Module:DisplayFunctions.


 * attr

should be a  containing HTML attributes. The value gets passed into the mw.html:attr function. This value is optional.


 * colspan

should be a  or   denoting the number of columns this header spans. This value is optional.


 * rowspan

should be a  or   denoting the number of rows this header spans. This value is optional.


 * css

should be a  of CSS names and values. The value gets passed into the mw.html:css function. This value is optional.


 * class

should be either a  with a class name or   (numeric array) containing class names. Each class name gets passed into the mw.html:addClass function. This value is optional.


 * cssFns

should be a  of functions. Each function takes the processed value of parameter  as input and should output a valid CSS. This value only applies to cells with tag "argth" or "argtd". This value is optional.


 * classFns

should be a  of functions. Each function takes the processed value of parameter  as input and should output a class name. This value only applies to cells with tag "argth" or "argtd". This value is optional.


 * options

should be a  of the following format:


 * hideIfEmpty

should be a  containing strings of parameter names. If all values for those parameters are empty, then the cell is hidden. This value is optional.


 * defaultCss

should be a  of CSS names and values. This CSS applies to all cells in this row. This value is optional.

↓ Jump to definition

tostring
This function is required.

This function "finishes" the infobox and returns an output HTML table with all styles automatically applied from Template:Infobox/styles.css. In order to generate an infobox, this function must be called.

↓ Jump to definition

Private functions
While these are not necessarily "private", these functions are not intended to be called externally.

getContent
Gets the content for display for a specified parameter. If the value for a parameter has not been postprocessed, then the  for that parameter, if it exists, will be called.

↓ Jump to definition

shouldShow
This is a helper function to tell if a certain cell should be visible depending on the parameter names given. If all values for the parameters given have no value, then a cell should not show.

↓ Jump to definition

addSpacer
This function sets up the 30 column layout by inserting an empty row. It also serves as a spacer.

↓ Jump to definition

addLinks
This function adds the navbar at the end of the infobox. This navbar contains links to the template page and the template talk page for this infobox. This uses the page using the value passed in from the  function.

↓ Jump to definition