Module:Infobox: Difference between revisions
Content added Content deleted
(use tostring() in getArgNums() - this is quicker than forcing concatenation of numbers) |
(better comments) |
||
Line 11:
function union(t1, t2)
--
local vals = {}
for k, v in pairs(t1) do
Line 27:
local function getArgNums(prefix)
-- Returns a table containing the numbers of the arguments that exist
-- for the specified prefix. For example, if the prefix was 'data', and
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
local nums = {}
for k, v in pairs(args) do
Line 37 ⟶ 40:
local function addRow(rowArgs)
-- Adds a row to the infobox, with either a header cell
-- or a label/data cell combination.
if rowArgs.header then
root
Line 159 ⟶ 164:
local function renderRows()
-- Gets the union of the header and data argument numbers,
-- and renders them all in order using addRow.
local rownums = union(getArgNums('header'), getArgNums('data'))
table.sort(rownums)
Line 206 ⟶ 213:
local function _infobox()
-- Specify the overall layout of the infobox, with special settings
-- if the infobox is used as a 'child' inside another infobox.
if args.child ~= 'yes' then
root = HtmlBuilder.create('table')
Line 249 ⟶ 258:
end
-- This function parses the parameters with the given prefixes, in order, in batches of the step size specified.▼
local function touchParameters(prefixTable, origArgs, step)
▲ --
-- of the step size specified. This is to prevent references etc. from
-- appearing in the wrong order.
if type(prefixTable) ~= 'table' or type(origArgs) ~= 'table' then
error("Invalid input to the touchParameters function detected. Both parameters must be tables.", 2)
Line 259 ⟶ 269:
end
step = step or 20 -- If the step size is not given, the default is 20.
local temp
local a = 1 -- Counter variable.
local moreArgumentsExist = true
for j,v in ipairs(prefixTable) do
|