Module:Constants: Difference between revisions
Jump to navigation
Jump to search
no edit summary
PhantomCaleb (talk | contribs) No edit summary |
PhantomCaleb (talk | contribs) No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local | local utilsLayout = require("Module:UtilsLayout") | ||
local utilsPage = require("Module:UtilsPage") | |||
local utilsTable = require("Module:UtilsTable") | |||
function p. | function p.Documentation(frame) | ||
local templateName = frame.args[1] | |||
local | local categories | ||
if mw.title.getCurrentTitle().subpageText == "Documentation" then | |||
categories = "[[Category:Module Documentation]]" | |||
else | |||
categories = "[[Category:Module Constants]]" | |||
end | 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 | end | ||
local wikitable = utilsLayout.table({ | |||
return | headers = {"Input", "Output"}, | ||
rows = tableData, | |||
}) | |||
return wikitable | |||
end | end | ||
return p | return p |