8,756
edits
mNo edit summary |
mNo edit summary |
||
Line 29: | Line 29: | ||
function p.query(args) | function p.query(args) | ||
local frame = mw.getCurrentFrame() | |||
local query = {} | |||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
if string.sub(k, 0, 2) == 'q?' then | if string.sub(k, 0, 2) == 'q?' then | ||
local key = string.sub(k, 3) | local key = string.sub(k, 3) | ||
query[PARAM_LOOKUP[key] or key] = v | |||
elseif PARAM_LOOKUP[k] then | elseif PARAM_LOOKUP[k] then | ||
query[PARAM_LOOKUP[k]] = v | query[PARAM_LOOKUP[k]] = v | ||
Line 59: | Line 59: | ||
-- This function on Leaguepedia is part of Module:ArgsUtil but is copied here to avoid dependencies | -- This function on Leaguepedia is part of Module:ArgsUtil but is copied here to avoid dependencies | ||
function h.merge(mergeParent) | function h.merge(mergeParent) | ||
mergeParent = mergeParent or true | |||
local f = mw.getCurrentFrame() | local f = mw.getCurrentFrame() | ||
local origArgs = f.args | local origArgs = f.args | ||
Line 65: | Line 65: | ||
local args = {} | local args = {} | ||
if mergeParent then | if mergeParent then | ||
local parentArgs = f:getParent().args | |||
for k, v in pairs(parentArgs) do | for k, v in pairs(parentArgs) do | ||
v = mw.text.trim(tostring(v)) | |||
if v ~= '' then | |||
args[k] = v | |||
end | |||
end | end | ||
end | end | ||
Line 155: | Line 155: | ||
function p.compound(frame) | function p.compound(frame) | ||
local args = h.merge(false) | local args = h.merge(false) | ||
local splitargs = {} | |||
for a, b in ipairs(args) do | for a, b in ipairs(args) do | ||
splitargs[a] = util_args.splitNamedArgs(frame:preprocess(b), '%s*;%s*') | |||
end | end | ||
template = frame:preprocess(args['template'] or '') | |||
delimiter = frame:preprocess(args['delimiter'] or '') | |||
if template == nil or template == '' then | |||
error('A template must be specified!') | |||
end | |||
splitargs['default'] = '' | |||
template = frame:preprocess(args['template'] or '') | |||
delimiter = frame:preprocess(args['delimiter'] or '') | |||
if template == nil or template == '' then | |||
end | |||
local result = {} | |||
for a, b in ipairs(splitargs) do | |||
tempresult = p.query(b) | |||
if tempresult ~= nil and tempresult ~= '' then | |||
result[#result+1] = p.query(b) | |||
end | |||
end | |||
resulttbl = util_table.mergeArrays(nil, unpack(result)) | |||
local tbl = {} | |||
for i, row in ipairs(resulttbl) do | for i, row in ipairs(resulttbl) do | ||
row.index = i | row.index = i | ||
tbl[#tbl+1] = frame:expandTemplate{ title = args['template'], args = row } | tbl[#tbl+1] = frame:expandTemplate{title = args['template'], args = row} | ||
end | end | ||
if #tbl == 0 then | if #tbl == 0 then | ||
Line 191: | Line 186: | ||
local outro = frame:preprocess(args['outro'] or '') | local outro = frame:preprocess(args['outro'] or '') | ||
return intro .. table.concat(tbl, delimiter) .. outro | return intro .. table.concat(tbl, delimiter) .. outro | ||
end | end | ||
return p | return p |