Module:InfoboxBuilder/doc
| This is a documentation subpage for Module:InfoboxBuilder. It may contain usage information, categories and other content that is not part of the original module page. |
| This module is rated as alpha. It is ready for limited use and third-party feedback. It may be used on a small number of pages, but should be monitored closely. Suggestions for new features or adjustments to input and output are welcome. |
This module provides a builder-style interface to Module:Infobox, which allows you to dynamically construct infoboxes without having to wrangle row numbers. Currently this can only be used by other modules.
Overview
[edit]This module provides a single class named InfoboxBuilder, which you can create an instance of by calling .new().
local InfoboxBuilder = require('Module:InfoboxBuilder').InfoboxBuilder
-- later on in the module:
function p.someFunction( frame )
local builder = InfoboxBuilder.new()
end
| Above | |
|---|---|
| Below |
InfoboxBuilder has two basic features: firstly, it functions as an accumulator for arguments to Module:Infobox, e.g.
InfoboxBuilder.new()
:bodystyle("background-color: #FFD3D3")
:title("Title")
:above("Above")
:below("Below")
:build()
is the equivalent of
frame:expandTemplate{ title = 'Infobox', args = {
["bodystyle"] = "background-color: #FFD3D3",
["title"] = "Title",
["above"] = "Above",
["below"] = "Below"
}}
and secondly, it takes care of numbering your subheaders/images/rows for you, e.g.
| Subheader 1 | |
| Subheader 2 | |
This image has a caption | |
| Header 1 | |
|---|---|
| Label | Data |
| Only Data | |
| Header 2 | |
| Fancy Row? | Yes |
InfoboxBuilder.new()
:title("Title")
:subheader("Subheader 1")
:subheader{
subheader = "Subheader 2",
subheaderstyle = "color: red"
}
:image("[[File:Example.jpg|upright=0.4]]")
:image{
image = "[[File:Example-serious.jpg|upright=0.4]]",
caption = "This image has a caption"
}
:header("Header 1")
:row("Data", "Label")
:row("Only Data")
:header{
header = "Header 2",
rowstyle = "background-color: #FF746C"
}
:row{
data = "Yes",
label = "Fancy Row?",
rowstyle = "background-color: #FFFFC5"
}
:build()
is the equivalent of
frame:expandTemplate{ title = 'Infobox', args = {
["title"] = "Title",
["subheader1"] = "Subheader 1",
["subheader2"] = "Subheader 2",
["subheaderstyle2"] = "color: red"
["image1"] = "[[File:Example.jpg|upright=0.4]]",
["image2"] = "[[File:Example-serious.jpg|upright=0.4]]",
["caption2"] = "This image has a caption",
["header1"] = "Header 1",
["label2"] = "Label",
["data2"] = "Data",
["data3"] = "Only Data",
["header4"] = "Header 2",
["rowstyle4"] = "background-color: #FF746C"
["label5"] = "Fancy Row?",
["data5"] = "Yes",
["rowstyle5"] = "background-color: #FFFFC5"
}}
Usage
[edit]The InfoboxBuilder class acts as an accumulator for parameters to Module:Infobox which will be passed along once you invoke the InfoboxBuilder:build() function. All non-repeated parameters (e.g., title, below, subheaderstyle) can be set by calling InfoboxBuilder:parameter(value) where parameter is the parameter name and value is the parameter value[a] (note that italic title should be passed along using InfoboxBuilder:italicTitle(value) as a special case since it contains a space. Similarly, all repeated parameters (e.g., header(n), label(n), etc.) can be set using the subheader, image, header, and row functions, each of which accept all parameters which should be linked together at the same time (these parameters can be passed as either positional arguments or named arguments, see below. All functions support chaining.
InfoboxBuilder:subheaderInfoboxBuilder:subheader(subheader, subheaderstyle, subheaderrowclass)InfoboxBuilder:subheader{ subheader = subheader, subheaderstyle = subheaderstyle, subheaderrowclass = subheaderrowclass }
InfoboxBuilder:imageInfoboxBuilder:image(image, caption, imagerowclass)InfoboxBuilder:image{ image = image, caption = caption, imagerowclass = imagerowclass }
InfoboxBuilder:headerInfoboxBuilder:header(header, rowclass, rowstyle)InfoboxBuilder:header{ header = header, rowclass = rowclass, rowstyle = rowstyle }
InfoboxBuilder:rowInfoboxBuilder:row(data, label, class, rowclass, rowstyle, rowcellstyle)InfoboxBuilder:row{ data = data, label = label, class = class, rowclass = rowclass, rowstyle = rowstyle, rowcellstyle = rowcellstyle }
- ↑ This module supports all parameters supported by Module:Infobox.