Editing Parameters
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
-- This module implements [[Template:Parameters]]. | -- This module implements [[Template:Parameters]]. | ||
-- [SublimeLinter luacheck-globals:mw] | -- [SublimeLinter luacheck-globals:mw] | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local p = {} | local p = {} | ||
local removeDuplicates = require('Module:TableTools').removeDuplicates | local removeDuplicates = require('Module:TableTools').removeDuplicates | ||
− | |||
local function makeInvokeFunction(funcName) | local function makeInvokeFunction(funcName) | ||
return function(frame) | return function(frame) | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
− | return p[funcName](getArgs(frame | + | return p[funcName](getArgs(frame)) |
end | end | ||
end | end | ||
− | local function extractParams( | + | local function extractParams(source) |
− | |||
− | |||
local parameters = {} | local parameters = {} | ||
for parameter in string.gmatch(source, '{{{(.-)%f[}|<>]') do | for parameter in string.gmatch(source, '{{{(.-)%f[}|<>]') do | ||
Line 54: | Line 20: | ||
end | end | ||
− | local function | + | local function strMap(iter, transform, sort) |
local returnTable = {} | local returnTable = {} | ||
− | for | + | for _, v in pairs(iter) do |
− | returnTable | + | table.insert(returnTable, transform(v)) |
+ | end | ||
+ | if sort then | ||
+ | table.sort(returnTable) | ||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
return table.concat(returnTable) | return table.concat(returnTable) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
function p._code(args) | function p._code(args) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local title = args._base or mw.title.getCurrentTitle().baseText | local title = args._base or mw.title.getCurrentTitle().baseText | ||
return string.format([[{{%s | return string.format([[{{%s | ||
− | %s}}]], title, strMap( | + | %s}}]], title, strMap(extractParams(args.base), |
− | function(s) | + | function(s) return string.format('| %s = \n', s) end)) |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 147: | Line 81: | ||
%s]], | %s]], | ||
strMap(Set.valueIntersection(baseParams, otherParams), | strMap(Set.valueIntersection(baseParams, otherParams), | ||
− | function(v) return string.format('* %s\n', v) end), | + | function(v) return string.format('* %s\n', v) end, true), |
strMap(Set.valueIntersection(baseNormParams, otherNormParams), | strMap(Set.valueIntersection(baseNormParams, otherNormParams), | ||
function(v) return string.format('* %s < %s [%s]\n', | function(v) return string.format('* %s < %s [%s]\n', | ||
Line 153: | Line 87: | ||
table.concat(otherNormParams[v], '; '), | table.concat(otherNormParams[v], '; '), | ||
v) | v) | ||
− | end), | + | end, true), |
strMap(Set.valueComplement(otherNormParams, baseNormParams), | strMap(Set.valueComplement(otherNormParams, baseNormParams), | ||
function(v) return strMap(baseNormParams[v], | function(v) return strMap(baseNormParams[v], | ||
− | function(s) return string.format('* %s\n', s) end) | + | function(s) return string.format('* %s\n', s) end, true) |
− | end)) | + | end, true)) |
end | end | ||
Line 167: | Line 101: | ||
function p._dlist(args) | function p._dlist(args) | ||
− | |||
return strMap(extractParams(args.base), | return strMap(extractParams(args.base), | ||
− | function(s) | + | function(s) return string.format('; %s: \n', s) end) |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 184: | Line 110: | ||
end | end | ||
− | |||
p.code = makeInvokeFunction('_code') | p.code = makeInvokeFunction('_code') | ||
p.compare = makeInvokeFunction('_compare') | p.compare = makeInvokeFunction('_compare') |