Zelda Wiki

Want to contribute to this wiki?
Sign up for an account, and get started!

Come join the Zelda Wiki community Discord server!

READ MORE

Zelda Wiki
This is the main module for the following templates: In addition, this module exports the following functions.

enum

enum()

Used by Template:Cite Magazine to validate input.

Returns

  • A list of magazine names.

Examples

#InputOutput
1
enum()
{
  "CD Interactief",
  "Official Nintendo Magazine",
  "Nintendo Fun Club News",
  "Nintendo Magazine",
  "Nintendo Power",
  reference = "[[Template:Magazine#Supported Magazines]]",
}

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#Supported Magazines]]",
	})
end

function p.Data(frame)
	local utilsLayout = require("Module:UtilsLayout")
	local rows = utilsTable.map(Data.magazines, function(magazine)
		local input = string.format("<code><nowiki>{{Magazine|%s}}</nowiki></code>", 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 = {""}
			},
		},
	},
}

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

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

return p