Editing Module:Template invocation
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
-- This module | -- This module makes a template invocation from a template name and a table | ||
-- of arguments. | |||
local checkType = require('libraryUtil').checkType | local checkType = require('libraryUtil').checkType | ||
Line 12: | Line 13: | ||
-- object has been passed in, and uses that to find a | -- object has been passed in, and uses that to find a | ||
-- template name as it is used in template invocations. | -- template name as it is used in template invocations. | ||
-- Parameters: title - full page name or mw.title | -- Parameters: title - full page name or mw.title obejct for the | ||
-- template (string or mw.title object) | -- template (string or mw.title object) | ||
-- Returns: String | -- Returns: String | ||
Line 41: | Line 42: | ||
-- name and the arguments given. Note that it isn't | -- name and the arguments given. Note that it isn't | ||
-- perfect: we have no way of knowing what whitespace was | -- perfect: we have no way of knowing what whitespace was | ||
-- in the original invocation, the | -- in the original invocation, the order of the parameters | ||
-- | -- may be changed, and any parameters with duplicate keys | ||
-- will be removed. | -- will be removed. | ||
-- Parameters: name - the template name, formatted as it will appear | -- Parameters: name - the template name, formatted as it will appear | ||
Line 59: | Line 60: | ||
checkType('invocation', 3, format, 'string', true) | checkType('invocation', 3, format, 'string', true) | ||
-- | -- Copy the invocation args and convert magic words. | ||
-- make a copy of the table rather than just using the original, | -- We need to make a copy of the table rather than just using the original, | ||
-- some of the values may be erased when building the invocation. | -- as some of the values may be erased when building the invocation. | ||
local invArgs = {} | local invArgs = {} | ||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
invArgs[k] = v | invArgs[k] = v | ||
end | end | ||
Line 93: | Line 86: | ||
ret[#ret + 1] = name | ret[#ret + 1] = name | ||
for k, v in ipairs(invArgs) do | for k, v in ipairs(invArgs) do | ||
if | if v:find('=', 1, true) then | ||
-- Likely something like 1=foo=bar | -- Likely something like 1=foo=bar, we need to do it as a named arg | ||
break | |||
end | end | ||
ret[#ret + 1] = seps.pipe | |||
ret[#ret + 1] = v | |||
invArgs[k] = nil -- Erase the key so that we don't add the value twice | |||
end | end | ||
for k, v in pairs(invArgs) do | |||
for k, | |||
ret[#ret + 1] = seps.pipe | ret[#ret + 1] = seps.pipe | ||
ret[#ret + 1] = | ret[#ret + 1] = k | ||
ret[#ret + 1] = seps.equals | ret[#ret + 1] = seps.equals | ||
ret[#ret + 1] = | ret[#ret + 1] = v | ||
end | end | ||
ret[#ret + 1] = seps.closeb | ret[#ret + 1] = seps.closeb |