From Arms of God Wiki
bot: Phase 12 grade-S (comparison tables + tier theming) |
bot: operator iteration 2026-06-10 |
||
| Line 1: | Line 1: | ||
-- Module:Compare — | -- Module:Compare — comparison-table renderer (Arms of God). | ||
-- Reads Data:Compare_< | -- Reads Data:Compare_<dataset>.json (headers + rows of {t=display, s=sortval}). | ||
-- | -- Cell `t` is pre-rendered wikitext (icon+link, colored chips) — rendered | ||
-- | -- verbatim. `s` becomes data-sort-value. Dark-theme inline styles carry | ||
-- var(--token, fallback) so the operator's Common.css tokens win once pasted. | |||
local p = {} | local p = {} | ||
local function cell(c | local TBL_STYLE = 'font-size:0.92em;background:var(--table-row-odd, #1b1c20);color:var(--table-text, #e6e6e6);border-color:var(--table-border, #3a3c44);' | ||
local TH_STYLE = 'background:var(--table-header-bg, #26272e);color:var(--infobox-header-fg, #f1e9d2);' | |||
local function cell(c) | |||
local t = tostring(c.t or '—') | local t = tostring(c.t or '—') | ||
if c.s ~= nil then | if c.s ~= nil then | ||
return '| data-sort-value="' .. tostring(c.s) .. '" | ' .. t | return '| data-sort-value="' .. tostring(c.s) .. '" | ' .. t | ||
| Line 19: | Line 18: | ||
function p.render(frame) | function p.render(frame) | ||
local | local ds = frame.args[1] or frame.args.cat | ||
if not | if not ds or ds == '' then | ||
return '<strong class="error">Module:Compare: missing | return '<strong class="error">Module:Compare: missing dataset arg</strong>' | ||
end | end | ||
local ok, data = pcall(mw.loadJsonData, 'Data:Compare_' .. | ds = ds:gsub('^%s+', ''):gsub('%s+$', '') | ||
local ok, data = pcall(mw.loadJsonData, 'Data:Compare_' .. ds .. '.json') | |||
if not ok or type(data) ~= 'table' or not data.rows then | if not ok or type(data) ~= 'table' or not data.rows then | ||
return '<strong class="error">Module:Compare: cannot load Data:Compare_' | return '<strong class="error">Module:Compare: cannot load Data:Compare_' | ||
.. | .. ds .. '.json</strong>' | ||
end | end | ||
local out = { '{| class="wikitable sortable" style=" | local out = { '{| class="wikitable sortable" style="' .. TBL_STYLE .. '"' } | ||
out[#out+1] = '|-' | out[#out+1] = '|-' | ||
for _, h in ipairs(data.headers or {}) do | for _, h in ipairs(data.headers or {}) do | ||
out[#out+1] = '! ' .. tostring(h) | out[#out+1] = '! style="' .. TH_STYLE .. '" | ' .. tostring(h) | ||
end | end | ||
for _, row in ipairs(data.rows) do | for _, row in ipairs(data.rows) do | ||
out[#out+1] = '|-' | out[#out+1] = '|-' | ||
for | for _, c in ipairs(row) do | ||
out[#out+1] = cell(c | out[#out+1] = cell(c) | ||
end | end | ||
end | end | ||
Revision as of 03:52, 10 June 2026
Documentation for this module may be created at Module:Compare/doc
-- Module:Compare — comparison-table renderer (Arms of God).
-- Reads Data:Compare_<dataset>.json (headers + rows of {t=display, s=sortval}).
-- Cell `t` is pre-rendered wikitext (icon+link, colored chips) — rendered
-- verbatim. `s` becomes data-sort-value. Dark-theme inline styles carry
-- var(--token, fallback) so the operator's Common.css tokens win once pasted.
local p = {}
local TBL_STYLE = 'font-size:0.92em;background:var(--table-row-odd, #1b1c20);color:var(--table-text, #e6e6e6);border-color:var(--table-border, #3a3c44);'
local TH_STYLE = 'background:var(--table-header-bg, #26272e);color:var(--infobox-header-fg, #f1e9d2);'
local function cell(c)
local t = tostring(c.t or '—')
if c.s ~= nil then
return '| data-sort-value="' .. tostring(c.s) .. '" | ' .. t
end
return '| ' .. t
end
function p.render(frame)
local ds = frame.args[1] or frame.args.cat
if not ds or ds == '' then
return '<strong class="error">Module:Compare: missing dataset arg</strong>'
end
ds = ds:gsub('^%s+', ''):gsub('%s+$', '')
local ok, data = pcall(mw.loadJsonData, 'Data:Compare_' .. ds .. '.json')
if not ok or type(data) ~= 'table' or not data.rows then
return '<strong class="error">Module:Compare: cannot load Data:Compare_'
.. ds .. '.json</strong>'
end
local out = { '{| class="wikitable sortable" style="' .. TBL_STYLE .. '"' }
out[#out+1] = '|-'
for _, h in ipairs(data.headers or {}) do
out[#out+1] = '! style="' .. TH_STYLE .. '" | ' .. tostring(h)
end
for _, row in ipairs(data.rows) do
out[#out+1] = '|-'
for _, c in ipairs(row) do
out[#out+1] = cell(c)
end
end
out[#out+1] = '|}'
return table.concat(out, '\n')
end
return p