Module:Infobox

local p = {}

local Franchise = require("Module:Franchise") local utilsArg = require("Module:UtilsArg") local utilsError = require("Module:UtilsError") local utilsMarkup = require("Module:UtilsMarkup") local utilsString = require("Module:UtilsString") local utilsTable = require("Module:UtilsTable")

local CATEGORY_PARAM_CAPTION = "" local CATEGORY_PARAM_NAME = "" local CATEGORY_BR_TAGS = ""

function p.Main(frame) local templateName = "Infobox "..frame:getParent:getTitle local args, err, categories local templateSpec = p.Templates[templateName] if templateSpec then args, err = utilsArg.parse(frame:getParent.args, templateSpec) else args = frame:getParent.args end categories = err and err.categoryText or "" if args.name and args.name ~= "" then categories = categories..CATEGORY_PARAM_NAME end if args.caption and args.caption ~= "" then categories = categories..CATEGORY_PARAM_CAPTION end return categories end

function p.List(frame) listItems = frame.args[1] or "" if string.find(listItems, "<br") then return listItems..CATEGORY_BR_TAGS end listItems = utilsString.trim(listItems) listItems = utilsString.split(listItems) if #listItems <= 1 then return listItems[1] end return utilsMarkup.list(listItems) end

function p.Games(frame) local games = frame.args[1] or "" if string.find(games, "<br") then return games..CATEGORY_BR_TAGS end games = utilsString.trim(games) games = utilsString.split(games) if #games <= 1 then return games[1] end games = utilsTable.map(games, p.link) games = utilsTable.compact(games) games = utilsMarkup.list(games) return games end function p.link(game) if utilsMarkup.containsLink(game) then return game end local link = Franchise.link(game) local properCode = Franchise.code(game) if not link then utilsError.warn(string.format("Invalid entry . See Data:Franchise for a list of valid entries.", game)) elseif properCode and properCode ~= game then utilsError.warn(string.format(" should be written as  ", game, properCode)) end return link end

local templateSpec = function(args) local singular = args.singular local plural = args.plural local params = args.params local productionParams = args.productionParams local imageSuchAs = args.imageSuchAs

local spec = { format = "block", purpose = string.format("Infobox for %s.", plural, string.lower(plural)), categories = {"Infobox Templates"}, boilerplate = { separateRequiredParams = false, },		paramOrder = {"name", "image", "caption"}, params = { name = { desc = " Name to use in the infobox header. Defaults to . In general, this parameter should be omitted unless the title requires italics. ", type = "content", },			image = { desc = string.format("An image to represent the %s, such as %s.", singular, imageSuchAs), type = "wiki-file-name", },			caption = { desc = "A caption for the image.", type = "content", }		},	}	for i, param in ipairs(params or {}) do		spec.params[param.name] = param table.insert(spec.paramOrder, param.name) end for i, param in ipairs(productionParams or {}) do		spec.params[param.name] = param table.insert(spec.paramOrder, param.name) end return spec end

local released = { name = "released", desc = "Release date(s) of the film. Use Template:Release.", type = "content", }

p.Templates = { ["Infobox Film"] = templateSpec({		singular = "film",		plural = "films",		imageSuchAs = "a release poster or a DVD cover",		params = {			{				name = "director",				desc = "The director(s) of the film.",				type = "content",			},			{				name = "producer",				desc = "The producer(s) of the film.",				type = "content",			},			{				name = "country",				desc = "Country or countries of production.",				},			released,		}	}), ["Infobox Television"] = templateSpec({		singular = "television",		plural = "television",		imageSuchAs = "the series' logo or title card",		params = {			{				name = "basedOn",				type = "string",				desc = "Comma separated list of games that the series is based on.",				enum = Franchise.enum,				trim = true,				split = true,			},			{				name = "seasons",				type = "content",				desc = "Number of seasons.",			},			{				name = "episodes",				type = "content",				desc = "Number of total episodes.",			},			{				name = "company",				type = "content",				desc = "Production comapany or companies.",			},			{				name = "distributor",				type = "content",				desc = "Distributor(s) of the television series.",			},			released,		}	}) }

return p