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 = mw.loadData("Module:Magazine/Data")

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates.Magazine) local magazine = args.magazine if utilsString.isBlank(magazine) then return utilsError.error("magazine name required")..err.categoryText elseif err then return ""..magazine..""..err.categoryText else return ""..magazine.."" end end

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

function p.Data(frame) local utilsLayout = require("Module:UtilsLayout") local rows = utilsTable.map(Data.magazines, 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, },		},		examples = { {"Nintendo Power"}, {				desc = "Error handling", args = {"Cosmopolitan"}, },			{				args = {""} },		},	}, }

function p.Schemas return { Data = { type = "record", required = true, properties = { {					name = "magazines", type = "array", required = true, items = { type = "string", },				},			},		}	} end

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

return p