Module:Constants: Difference between revisions

Jump to navigation Jump to search
no edit summary
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

Navigation menu