Module:Franchise List
Jump to navigation
Jump to search
This is the main module for the following templates:
local p = {}
local Franchise = require("Module:Franchise")
local Util = {
strings = {
split = require("Module:Util/strings/split"),
trim = require("Module:Util/strings/trim"),
}
}
function warn(msg, details)
local Error = require("Module:Error")
local cat = require("Module:Constants/category/invalidArgs")
local err = Error.warning(msg, details)
return err.."[[Category:"..cat.."]]"
end
function p.Main(frame)
local prop = frame:getParent().args[1]
local formatStr = frame:getParent().args[2]
local codes = frame:getParent().args[3]
prop = prop and Util.strings.trim(prop)
codes = codes and Util.strings.trim(codes)
if codes == nil or codes == "" then
return ""
end
codes = Util.strings.split(codes)
local res = ""
local err = {}
for i, code in ipairs(codes) do
local propValue = Franchise.prop(code, prop)
if not propValue then
table.insert(err, string.format("Invalid franchise code <code>%s</code>. See [[:Category:Franchise codes]] for accepted codes.", code))
else
res = res..string.format(formatStr, propValue)
end
end
if #err > 0 then
return res, warn("Invalid arguments", err)
end
return res
end
p.Templates = {
["Franchise List"] = {}
}
return p