Module:Entry: Difference between revisions
Jump to navigation
Jump to search
HyperNervie (talk | contribs) (A module that, when you feed it a console-stage-number triplet, yields the title of, the icon of or a link to that entry.) |
HyperNervie (talk | contribs) (Prevent {{}} from being preprocessed in frame:extensionTag("tabber", ...), by the way why doesn't TabberNeue on this wiki provide mw.ext.tabber???) |
||
| Line 48: | Line 48: | ||
wikitable:tag("tr") | wikitable:tag("tr") | ||
:tag("td"):tag("code") | :tag("td"):tag("code") | ||
:wikitext(mw.ustring.format(" | :wikitext(mw.ustring.format("{{%s|%s|%s|%s}}", | ||
template, entry.console, entry.stage, entry.number)) | template, entry.console, entry.stage, entry.number)) | ||
:done():done() | :done():done() | ||
Revision as of 06:27, 7 August 2025
Documentation for this module may be created at Module:Entry/doc
local entryMT = require("Module:Entry/metatable")
local p = {}
function p.new(console, stage, number)
if type(console) == "table" and stage == nil and number == nil then
stage = console[2] or console.stage
number = console[3] or console.number
console = console[1] or console.console
end
return setmetatable({
console = console,
stage = stage,
number = number
}, entryMT)
end
local function trim(s)
if s == nil then return nil end
s = mw.text.trim(s)
return s == "" and nil or s
end
trim()
function p.main(frame)
local args = frame:getParent().args
local entry = p.new(trim(args[1]), trim(args[2]), trim(args[3]))
local result = entry[trim(frame.args[1])]
if type(result) == "function" then
return result(entry, trim(args[4]), trim(args[5]))
end
return result
end
function p.doclist(frame)
local template = ({
textWithTempoUp = "entry",
title = "et",
link = "el",
iconName = "ein",
icon = "ei",
iconAndLink = "eil",
})[trim(frame.args[1])]
local wikitable
local function addRow(entry)
local result = entry[trim(frame.args[1])]
if type(result) == "function" then result = result(entry) end
wikitable:tag("tr")
:tag("td"):tag("code")
:wikitext(mw.ustring.format("{{%s|%s|%s|%s}}",
template, entry.console, entry.stage, entry.number))
:done():done()
:tag("td"):wikitext(result):done()
:done()
end
local tabs = ""
for console, rhtitle in pairs(require("Module:Entry/titles")) do
tabs = tabs .. "|-|" .. console .. "="
wikitable = mw.html.create("table")
:addClass("wikitable")
:css("white-space", "nowrap")
:css("max-width", "100%")
:css("overflow-x", "auto")
:tag("tr")
:tag("th"):wikitext("Source"):done()
:tag("th"):wikitext("Output"):done()
:done()
for stage, titles in pairs(rhtitle) do
for number, _ in ipairs(titles) do
addRow(p.new(console, stage, number))
end
end
tabs = tabs .. tostring(wikitable) .. "\n"
end
return frame:extensionTag("tabber", tabs)
end
return p