26x26px | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
-- This module implements [[Template:Parameters]].
-- [SublimeLinter luacheck-globals:mw]
local p = {}
local function makeInvokeFunction(funcName)
return function(frame)
local getArgs = require('Module:Arguments').getArgs
return p[funcName](getArgs(frame))
end
end
local function extractParams(args)
local removeDuplicates = require('Module:TableTools').removeDuplicates
local parameters = {}
for parameter in string.gmatch(args.base, '{{{(.-)%f[}|<>]') do
table.insert(parameters, parameter)
end
return removeDuplicates(parameters)
end
function p._demo(args)
return string.format('{{Parameter names example|_template=%s|%s}}',
args._base or '', table.concat(extractParams(args), '|'))
end
function p._list(args)
local parameters = extractParams(args)
for k, v in pairs(parameters) do
parameters[k] = string.format('* %s\n', v)
end
return table.concat(parameters)
end
p.demo = makeInvokeFunction('_demo')
p.list = makeInvokeFunction('_list')
return p