Module:Template invocation: Difference between revisions

m
11 revisions imported from wikipedia:Module:Template_invocation
m (update top comment)
m (11 revisions imported from wikipedia:Module:Template_invocation)
 
(8 intermediate revisions by 6 users not shown)
Line 12:
-- object has been passed in, and uses that to find a
-- template name as it is used in template invocations.
-- Parameters: title - full page name or mw.title obejctobject for the
-- template (string or mw.title object)
-- Returns: String
Line 41:
-- name and the arguments given. Note that it isn't
-- perfect: we have no way of knowing what whitespace was
-- in the original invocation, the ordernamed ofparameters thewill parametersbe
-- mayalphabetically be changedsorted, and any parameters with duplicate keys
-- will be removed.
-- Parameters: name - the template name, formatted as it will appear
Line 93:
ret[#ret + 1] = name
for k, v in ipairs(invArgs) do
if type(v) == 'string' and v:find('=', 1, true) then
-- Likely something like 1=foo=bar, we need to do it as a named arg
break
Line 101:
invArgs[k] = nil -- Erase the key so that we don't add the value twice
end
local invArgs_list = {} -- sort a parameter list; preferable to randomly sorted output
for k, v in pairs(invArgs) do
invArgs_list[#invArgs_list + 1] = k
end
table.sort(invArgs_list)
for i, v in ipairs(invArgs_list) do -- Add named args based on sorted parameter list
ret[#ret + 1] = seps.pipe
ret[#ret + 1] = k
ret[#ret + 1] = seps.equals
ret[#ret + 1] = v
ret[#ret + 1] = seps.equals
ret[#ret + 1] = kinvArgs[v]
end
ret[#ret + 1] = seps.closeb