Module:Constants: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


local Constants = mw.loadData("Module:Constants/Data")
local utilsLayout = require("Module:UtilsLayout")
local utilsPage = require("Module:UtilsPage")
local utilsTable = require("Module:UtilsTable")


function p.Main(frame)
function p.Documentation(frame)
if frame.args == nil then
local templateName = frame.args[1]
error("No constant name provided")
end
local constant
local categories
local path
if mw.title.getCurrentTitle().subpageText == "Documentation" then
for i, key in ipairs(frame.args) do
categories = "[[Category:Module Documentation]]"
if i == 1 then
else
constant = Constants[key]
categories = "[[Category:Module Constants]]"
path = key
else
constant = constant and constant[key]
path = path.."."..key
end
end
end
if constant == nil then
local msg = string.format("This module allows other modules to import the {{Template|%s}} [[:Category:Constants|constant]].", templateName)
error(string.format("Constant '%s' does not exist", path))
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
end
local wikitable = utilsLayout.table({
return constant
headers = {"Input", "Output"},
rows = tableData,
})
return wikitable
end
end


return p
return p

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