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) |
local returnTable = {} | local returnTable = {} | ||
− | for | + | for _, v in pairs(iter) do |
− | returnTable | + | table.insert(returnTable, transform(v)) |
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 108: | Line 39: | ||
local function normaliseParams(parameters) | local function normaliseParams(parameters) | ||
− | local paramsNorm | + | local paramsNorm, paramIndex = {}, {} |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
for _, parameter in pairs(parameters) do | for _, parameter in pairs(parameters) do | ||
table.insert(paramsNorm, | table.insert(paramsNorm, | ||
string.lower(string.gsub(parameter, '%A', ''))) | string.lower(string.gsub(parameter, '%A', ''))) | ||
− | + | paramIndex[ | |
− | string.lower(string.gsub(parameter, '%A', ''))] | + | string.lower(string.gsub(parameter, '%A', ''))] = parameter |
end | end | ||
paramsNorm = removeDuplicates(paramsNorm) | paramsNorm = removeDuplicates(paramsNorm) | ||
− | |||
− | |||
− | |||
setmetatable(paramsNorm, {__index = paramIndex}) | setmetatable(paramsNorm, {__index = paramIndex}) | ||
return paramsNorm | return paramsNorm | ||
Line 149: | Line 67: | ||
function(v) return string.format('* %s\n', v) end), | function(v) return string.format('* %s\n', v) end), | ||
strMap(Set.valueIntersection(baseNormParams, otherNormParams), | strMap(Set.valueIntersection(baseNormParams, otherNormParams), | ||
− | function(v) return string.format('* %s < %s | + | function(v) return string.format('* %s < %s (%s)\n', |
− | + | baseNormParams[v], otherNormParams[v], v) end), | |
− | |||
− | |||
− | |||
strMap(Set.valueComplement(otherNormParams, baseNormParams), | strMap(Set.valueComplement(otherNormParams, baseNormParams), | ||
− | function(v | + | function(v) return string.format('* %s\n', baseNormParams[v]) end)) |
− | |||
− | |||
end | end | ||
Line 164: | Line 77: | ||
return string.format('{{Parameter names example%s|%s}}', title, | return string.format('{{Parameter names example%s|%s}}', title, | ||
table.concat(extractParams(args.base), '|')) | table.concat(extractParams(args.base), '|')) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 184: | Line 84: | ||
end | end | ||
− | |||
p.code = makeInvokeFunction('_code') | p.code = makeInvokeFunction('_code') | ||
p.compare = makeInvokeFunction('_compare') | p.compare = makeInvokeFunction('_compare') | ||
p.demo = makeInvokeFunction('_demo') | p.demo = makeInvokeFunction('_demo') | ||
− | |||
p.list = makeInvokeFunction('_list') | p.list = makeInvokeFunction('_list') | ||
return p | return p |