Extension:Capiunto/Infobox/Basic usage
This page is currently a draft.
|
Capiunto is a MediaWiki extension based on Scribunto allowing to write flexible Infoboxes. For Capiunto a basic knowledge of Lua is necessary. To read up on Lua the Lua for beginners Help page or MediaWiki Lua reference manual is useful.
Create an Infobox module
editA Lua module is needed in order to set up an Infobox with Capiunto. This way you will be able to keep for example a certain design and structure and just pass data to the module which can be useful in various situations. For a complete documentation see Extension:Capiunto/Infobox.
Creating the first basic structure for the Infobox in Lua might look something like this |
---|
local p = {}
function p.run(frame)
local capiunto = require 'capiunto'
return capiunto.create( {
-- Some initial options, like global styles, go here
} )
end
return p
|
Setting options for capiunto.create
editYou have different options for styling your Infobox and setting some basic options in this step. You can get an overview here. The attributes are based on CSS therefore it allows easy changing styles of every element of the Infobox. Via the title
variable a title for the Infobox can be set. The Lua function mw.title.getCurrentTitle()
can be used to set the title of the Page as the title of the Infobox.
capiunto.create( {
-- …
title = tostring(mw.title.getCurrentTitle())
-- …
} )
Another example is setting the borders of a infobox's body to 10 pixels' thickness and color red with bodyStyle = 'border: 10px solid red'
It is possible to change most of the styling of the infoboxes this way if wanted but there are also very convenient defaults.
A working example for an Infobox without data |
---|
local p = {}
function p.run()
local capiunto = require 'capiunto'
return capiunto.create( {
title = tostring(mw.title.getCurrentTitle()) ,
top = 'Above text',
topStyle = 'background:#cfc;',
bottom = 'Below text'
} )
end
return p
|
Adding data to the Infobox
editAdding data to the Infobox is rather simple. With the help of
:addRow( label, data )
it's possible to add a new Row to the Infobox with a label and data.
In the example below, three chemical elements and their symbols are being added to the Infobox. This data is static and can't be changed from outside the module.
Example with static data |
---|
local p = {}
function p.run()
local capiunto = require 'capiunto'
return capiunto.create( {
title = tostring(mw.title.getCurrentTitle()) ,
top = 'Above text',
topStyle = 'background:#cfc;',
bottom = 'Below text'
} )
:addRow('H', 'Hydrogen')
:addRow('He','Helium')
:addRow('Li','Lithium')
:addImage(
'[[File:Keyhole Nebula - Hubble 1999.jpg|200px|alt=Keyhole Nebula - Hubble 1999]]',
'Caption displayed below'
)
end
return p
|
To add data to the rows when the module is called, the module could have arguments passed when invoked.
Example with dynamic data |
---|
local p = {}
function p.run(frame)
local capiunto = require 'capiunto'
return capiunto.create( {
title = tostring(mw.title.getCurrentTitle()) ,
top = 'Above text',
topStyle = 'background:#cfc;',
bottom = 'Below text'
} )
:addRow(frame.args[1], frame.args[2])
:addRow(frame.args[3], frame.args[4])
end
return p
|
The same way it's possible to add images, header, subheader and similar. An overview can be found at Extension:Capiunto/Infobox#capiunto:getHtml. This makes it possible to use templates with arguments and thereby define a style, change that style and add data as needed.
Using the Infobox module
editTo use the Infobox module, you have to go to the page where you want to use the module and depending on whether you have parameters, that you give the module invoke it this way;
{{#invoke:ModuleName|functionName}}
{{#invoke:ModuleName|functionName|parameter1|parameter2|moreParameters}}