Module:Magazine

local p = {}

local utilsArg = require("Module:UtilsArg") local utilsMarkup = require("Module:UtilsMarkup") 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 = args.magazine if err then return ""..magazine..""..err.categoryText end local result = ""..magazine.."" if showPublisher then local publisher = Data.magazinesByName[magazine].publisher result = result .. " by "..publisher end return result end

function p.publisher(magazine) local magazineData = Data.magazinesByName[magazine] return magazineData and magazineData.publisher 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 = utilsTable.merge({}, Data.magazineNames, {					reference = "Module:Magazine/Data",				}) },			[2] = {				name = "showPublisher", 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" }, },		},	} }

p.Documentation = { publisher = { desc = "Used by Template:Cite Magazine to retrieve the publisher of a magazine.", params = {"magazine"}, returns = "A link to the magazine's publisher, or  if no such magazine is defined at Module:Magazine/Data.", cases = { {				args = {"Nintendo Power"}, expect = "Nintendo of America", },			{				args = {"Cosmopolitan"}, expect = nil, },		},	}, }

return p