Module:Magazine

local p = {}

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

local Data = require("Module:Magazine/Data")

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates.Magazine) local magazine, noPublisher = args.magazine, args.noPublisher if utilsString.isBlank(magazine) then return utilsError.error("magazine name required")..err.categoryText elseif err then return ""..magazine..""..err.categoryText end local result = ""..magazine.."" if not noPublisher then local publisher = Data.magazinesByName[magazine].publisher result = result .. " by "..publisher end return result end

function p.enum return utilsTable.merge({}, Data.magazineNames, {		reference = "Template:Magazine",	}) end

function p.Data(frame) local utilsLayout = require("Module:UtilsLayout") local rows = utilsTable.map(Data.magazineNames, function(magazine)		local input = string.format(" ", magazine)		local output = frame:expandTemplate({ title = "Magazine", args = {magazine} })		return {input, output}	end) local wikitable = utilsLayout.table({		headers = {"Input", "Output"},		rows = rows,	}) return wikitable end

p.Templates = { ["Magazine"] = { params = { [1] = {				name = "magazine", required = true, desc = "A magazine name.", enum = p.enum, },			[2] = {				name = "noPublisher", desc = "If present, only the magazine is shown without the publisher.", type = "boolean", },		},		examples = { {"Nintendo Power"}, {"Nintendo Power", "-"}, {				desc = "Error handling", args = {"Cosmopolitan"}, },			{				args = {""} },		},	}, }

p.Schemas = { Data = { type = "record", required = true, properties = { {				name = "magazines", type = "array", required = true, items = { type = "record", _id = "#magazine", properties = { {							name = "name", required = true, type = "string", },						{							name = "publisher", required = true, type = "string", },					},				},			},			{				name = "magazineNames", required = true, type = "array", items = { type = "string" }, },			{				name = "magazinesByName", required = true, type = "map", keys = { type = "string" }, values = { _ref = "#magazine", _hideSubkeys = true, }, },		},	} }

p.Documentation = { enum = { desc = "Used by Template:Cite Magazine to validate input.", params = {}, returns = "A list of magazine names.", cases = { {				args = {}, },		},	}, }

return p