Module:Infobox/doc: Difference between revisions

Document class config
No edit summary
(Document class config)
 
(8 intermediate revisions by the same user not shown)
Line 11:
===Unpack the frame arguments from the Template===
<syntaxhighlight lang="lua">
local p = {}
 
function p.main(frame)
local args = frame:getParent().args
Line 20 ⟶ 22:
local config = {
infobox_name = 'Scenery',
class = {Infobox.smw_param('episode')}, -- Add css class with episode name to colorize Infobox
}
</syntaxhighlight>
Line 25 ⟶ 28:
===Map your arguments to parsing functions===
{{Main|Module:Param Parse}}
Use the functionsparams in [[Module:Param Parse]] to validate and format the data - feel free to create your own new params in [[Module:Param Parse]].
<syntaxhighlight lang="lua">
local params = {
parse.name,
{name = 'name', func = parse.has_content, smw_property = 'Name'},
parse.image,
{name = 'image', func = parse.image, smw_property = 'Image', smw_func = parse.image_smw, category_incomplete = 'Scenery missing Image'},
{name = 'examine', func = parse.has_content, smw_property = 'Examine'}, -- Custom param
parse.episode,
{name = 'episode', func = parse.episode, smw_property = 'Episode', smw_func = parse.episode_smw, category_incomplete = 'Scenery missing Episode'},
...
}
Line 47 ⟶ 50:
infobox
:add_row{
{tag='th', content=Infobox.param('name'), class='infobox.subheader-header', colspan='220'},
}
:add_row{
{tag='td', content=Infobox.param('image'), class='infobox-image', colspan='220'},
}
:pad(2"20")
:add_row{
{tag='td', content='[[Examine]]Info', class='infobox-subheader', colspan='20'},
{tag='td', content=Infobox.param('examine')},
}
:pad("20")
:add_row{
{tag='tdth', content='[[Episode]]Examine', colspan="6"},
{tag='td', content=Infobox.param('episodeexamine'), colspan="14"},
}
:add_row{
{tag='th', content='[[Episode]]', colspan="6"},
{tag='td', content=Infobox.param('examineepisode'), colspan="14"},
}
...
Line 69 ⟶ 76:
return infobox
end
 
return p
</syntaxhighlight>
 
==Functions==
=== Special params ===
You don't need to do anything about these special parameters, but they may be used as parameters within the Template:
{| class="wikitable"
! param
! explanation
|-
| version1, version2, version3
| Button label and SMW name for each switch version of the infobox
|-
| default_version
| The default version to display when the page is loaded
|-
| version
| If there is only a single version, you can use version to set the SMW name (default SMW name is "DEFAULT")
|}
 
=== Referring to params ===
Each parameter can have a different value for each version. In addition, there are 3 different representations of each value. Therefore, a parameter must be accessed via one of the 3 helper functions:
Line 98 ⟶ 123:
</syntaxhighlight>
==== config ====
There are only 23 parameters for config
<syntaxhighlight lang="lua">
local config = {
infobox_name = 'Scenery', -- mandatory unique identifier for css
class = {'CustomClass', Infobox.smw_param('episode')} -- optional, defaults to {}. Adds css classes to infobox table: {'infobox-CustomClass', 'infobox-[default version parameter's value]'}
max_buttons = 6, -- optional, defaults to 6, max number of switch buttons before using a dropdown list instead
}
Line 148 ⟶ 174:
|-
| category_partial (optional)
| ategorycategory to add if func returns nil for some versions, but a value for other versions
|-
| category_incomplete (optional)
Line 225 ⟶ 251:
|-
| class (optional)
| a string with a class to add, or a table of classes to add. '''infobox-header''', '''infobox-subheader''' isand '''infobox-image''' are commonly used.
mw.html:addClass(...)
|-
Line 243 ⟶ 269:
 
=== Infobox:pad(colspan, class) ===
Adds a blank row of padding spanning the given number of columns. Will always add the class '''infobox-padding''', but can optionally add another class:
<syntaxhighlight lang="lua">
infobox:pad("10", class=<class>)
Line 254 ⟶ 280:
infobox:addClass(class)
</syntaxhighlight>
 
 
=== Infobox:dump() ===
Logs all the values into the Debug console for debugging purposes. You can also dump all the values in an Infobox template by setting a template parameter "__dump = Yes".