This is the documentation page for Module:InfoboxBuilder
This is a documentation subpage for Module:InfoboxBuilder. It contains usage information, categories and other content that is not part of the original module page. |
This module depends on the following other modules: |
Building an Infobox
Import the module
local InfoboxBuilder = require('Module:InfoboxBuilder')
Unpack the frame arguments
function p.main(frame)
local args = frame:getParent().args
...
Create the infobox object
local infobox = InfoboxBuilder.new()
Set the infobox name
Setting the infobox name sets the template that the infobox links to inside of the navbar.
infobox:setName('Infobox')
Define the parameters
When defining the parameters, the arguments will be processed and postprocessed when given a function or table. pFunc is an optional processing function or table that will transform the raw argument value into a specific format. dFunc is an optional postprocessing function or table that will transform the processed argument for display purposes. An optional default value for the raw argument can be set using the default option.
An example of using pFunc and dFunc would be to have pFunc be a function that splits a comma separated list into a table in Lua and have dFunc be a function that turns a table into an unordered list in HTML.
infobox:setParams {
...
}
Pass in the arguments
infobox:setArgs(args)
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.
infobox:processArgs()
Specify a category map
A category map can be optionally set. This uses the processed (not postprocessed) argument and generates the correct categories.
infobox:setCategoryMap({
...
})
Prepare
Create the look of the infobox by adding headers, images, or rows. If the values shown in these cells use the value from parameters, it will use the postprocessed value.
-- add a header or subheader
infobox:addHeader(
{...},
{...}
)
-- add an image
infobox:addImage(
{...},
{...}
)
-- add a row
infobox:addRow(
{...},
{...}
)
Build
To build the infobox from data into an HTML table, call the tostring() function.
infobox:tostring()
Get the categories from the category map
To get the categories, call the getCategories() function.
infobox:getCategories()