Module:Constants: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 4: Line 4:
local utilsPage = require("Module:UtilsPage")
local utilsPage = require("Module:UtilsPage")
local utilsTable = require("Module:UtilsTable")
local utilsTable = require("Module:UtilsTable")
function p.Documentation(frame)
local templateName = frame.args[1]
local categories
if mw.title.getCurrentTitle().subpageText == "Documentation" then
categories = "[[Category:Module Documentation]]"
else
categories = "[[Category:Module Constants]]"
end
local msg = string.format("This module allows other modules to import the {{Template|%s}} [[:Category:Constants|constant]].", templateName)
msg = frame:preprocess(msg)
return msg, categories
end


function p.List(frame)
function p.List(frame)

Latest revision as of 20:39, 5 November 2022

This module simplifies the use of templated constants in Lua modules.

Usage

local CATEGORY_INVALID_ARGS = require("Module:Constants/constantType/constantName")

List of Constants

InputOutput
require("Module:Constants/Data")
table#1 {
    ["category"] = table#2 {
        ["deprecatedParams"] = "Articles using deprecated parameters in template calls",
        ["invalidArgs"] = "Articles using invalid arguments in template calls",
        ["templateErrors"] = "Pages with template errors",
    },
    ["class"] = table#3 {
        ["hatnote"] = "hatnote",
        ["plainlist"] = "plainlist",
    },
    ["url"] = table#4 {
        ["discord"] = "https://discord.gg/wJJY8Na4eP",
    },
}
require("Module:Constants/category/deprecatedParams")
"Articles using deprecated parameters in template calls"
require("Module:Constants/category/invalidArgs")
"Articles using invalid arguments in template calls"
require("Module:Constants/category/templateErrors")
"Pages with template errors"
require("Module:Constants/class/noexcerpt")
"noexcerpt"
require("Module:Constants/class/pixelArt")
"pixel-art"
require("Module:Constants/class/tooltip")
"tooltip"
require("Module:Constants/number/maxImageArea")
12500000
require("Module:Constants/number/maxNavboxPartitionSize")
16
require("Module:Constants/url/discord")
"https://discord.com/invite/eJnnvYb"

local p = {}

local utilsLayout = require("Module:UtilsLayout")
local utilsPage = require("Module:UtilsPage")
local utilsTable = require("Module:UtilsTable")

function p.Documentation(frame)
	local templateName = frame.args[1]
	
	local categories
	if mw.title.getCurrentTitle().subpageText == "Documentation" then
		categories = "[[Category:Module Documentation]]"
	else
		categories = "[[Category:Module Constants]]"
	end
	local msg = string.format("This module allows other modules to import the {{Template|%s}} [[:Category:Constants|constant]].", templateName)
	msg = frame:preprocess(msg)
	return msg, categories
end

function p.List(frame)
	local subpages = utilsPage.getSubpages("Module:Constants")
	subpages = utilsTable.filter(subpages, function(subpage)
		return string.find(subpage, "/Documentation") == nil
	end)
	local tableData = {}
	for i, subpage in ipairs(subpages) do
		local input = frame:extensionTag({
			name = "syntaxhighlight",
			args = { lang = "lua" },
			content = string.format('require("%s")', subpage),
		})
		local output = frame:extensionTag({
			name = "syntaxhighlight",
			args = { lang = "lua" },
			content = mw.dumpObject(require(subpage))
		})
		table.insert(tableData, {input, output})
	end
	local wikitable = utilsLayout.table({
		headers = {"Input", "Output"},
		rows = tableData,
	})
	return wikitable
end

return p