Module:CargoQuery

local h = {}

-- This function on Leaguepedia is part of Module:ArgsUtil but is copied here to avoid dependencies

function h.merge(norm) local f = mw.getCurrentFrame local origArgs = f.args local parentArgs = f:getParent.args

local args = {} for k, v in pairs(origArgs) do		v = mw.text.trim(tostring(v)) if norm and v ~= '' or not norm then args[k] = v		end end for k, v in pairs(parentArgs) do		v = mw.text.trim(v) if norm and v ~= '' or not norm then args[k] = v		end end return args end

local p = {} function p.main(frame) local args = h.merge(true) local query = {} for k, v in pairs(args) do		if string.sub(k, 0, 2) == 'q?' then query[string.sub(k, 3)] = v		end end local result = mw.ext.cargo.query(query.tables, query.fields, query) if not next(result) then return frame:preprocess(args.default or '') end local tbl = {} for _, row in ipairs(result) do		tbl[#tbl+1] = frame:expandTemplate{ title = args.template, args = row } end local intro = frame:preprocess(args.intro or '') local outro = frame:preprocess(args.outro or '') return intro .. table.concat(tbl,args.delimiter or '') .. outro end return p