Module:Infobox: Difference between revisions
hack to parse the parameters in the 'correct' order
m>Mr. Stradivarius (tweak comment at the start) |
m>Mr. Stradivarius (hack to parse the parameters in the 'correct' order) |
||
Line 247: | Line 247: | ||
return tostring(root) | return tostring(root) | ||
end | |||
-- This function parses the parameters with the given prefixes, in order, in batches of 20. | |||
local function touchParameters(prefixTable, origArgs) | |||
if type(prefixTable) ~= 'table' or type(origArgs) ~= 'table' then | |||
error("Invalid input to the touchParameters function detected. Both parameters must be tables.", 2) | |||
end | |||
local temp | |||
local argumentCounter = 1 | |||
local moreArgumentsExist = true | |||
for j,v in ipairs(prefixTable) do | |||
if not type(v) == "string" then | |||
error("Non-string value detected in the prefix table in the touchParameters function.", 2) | |||
end | |||
temp = origArgs[v] | |||
end | |||
while moreArgumentsExist == true do | |||
moreArgumentsExist = false | |||
for i = argumentCounter, argumentCounter + 19 do | |||
for j,v in ipairs(prefixTable) do | |||
temp = origArgs[v .. tostring(i)] | |||
if temp then | |||
moreArgumentsExist = true | |||
end | |||
end | |||
end | |||
argumentCounter = argumentCounter + 20 | |||
end | |||
end | end | ||
Line 258: | Line 286: | ||
origArgs = frame | origArgs = frame | ||
end | end | ||
-- Parse the data parameters in the same order that the old {{infobox}} did, so that | |||
-- references etc. will display in the expected places. | |||
local temp | |||
temp = origArgs.title | |||
temp = origArgs.above | |||
touchParameters({'subheader'}, origArgs) | |||
touchParameters({'image', 'caption'}, origArgs) | |||
touchParameters({'header', 'label', 'data'}, origArgs) | |||
temp = origArgs.below | |||
-- ParserFunctions considers whitespace to be false, so to preserve the previous | -- ParserFunctions considers whitespace to be false, so to preserve the previous |