Module:Definitions: Difference between revisions
From SpiritVale Wiki
More actions
No edit summary |
No edit summary |
||
| Line 5: | Line 5: | ||
-- Module:Definitions/Definitions.json | -- Module:Definitions/Definitions.json | ||
-- | -- | ||
-- JSON shape | -- JSON shape: | ||
-- { | -- { | ||
-- "Schema": 1, | -- "Schema": 1, | ||
| Line 17: | Line 17: | ||
-- - Domains + keys are discovered from JSON (no hardcoded domain lists). | -- - Domains + keys are discovered from JSON (no hardcoded domain lists). | ||
-- - CSS namespace: ONLY "sv-def" (plus sv-def--* modifiers). | -- - CSS namespace: ONLY "sv-def" (plus sv-def--* modifiers). | ||
-- - | -- - Output classes: sv-def, sv-def-icon, sv-def-icon-img, sv-def-text. | ||
-- | |||
local p = {} | local p = {} | ||
| Line 25: | Line 24: | ||
-- ============================================================================= | -- ============================================================================= | ||
-- | -- Helpers | ||
-- ============================================================================= | -- ============================================================================= | ||
| Line 103: | Line 102: | ||
end | end | ||
-- Case-insensitive match across top-level keys | -- Case-insensitive match across top-level keys that are tables | ||
local want = lc(domain) | local want = lc(domain) | ||
for k, v in pairs(db) do | for k, v in pairs(db) do | ||
if type(v) == "table" and lc(k) == want then | if type(v) == "table" and lc(k) == want then | ||
return k | |||
end | end | ||
end | end | ||
| Line 124: | Line 121: | ||
-- ============================================================================= | -- ============================================================================= | ||
-- Icon rendering | -- Icon rendering | ||
-- - Blank icon: | -- - Blank icon: render nothing (no generic dot/circle) | ||
-- - Missing file: | -- - Missing file: render "?" badge (no redlink image) | ||
-- ============================================================================= | -- ============================================================================= | ||
| Line 131: | Line 128: | ||
icon = trim(icon) | icon = trim(icon) | ||
if icon == "" then | if icon == "" then | ||
return "" | return "" | ||
| Line 143: | Line 139: | ||
local t = mw.title.new(fileTitle) | local t = mw.title.new(fileTitle) | ||
if not t or not t.exists then | if not t or not t.exists then | ||
return '<span class="sv-def-icon sv-def-icon--missing" aria-hidden="true">?</span>' | return '<span class="sv-def-icon sv-def-icon--missing" aria-hidden="true">?</span>' | ||
end | end | ||
return '<span class="sv-def-icon-img">[[' .. fileTitle .. '|16px|link=]]</span>' | return '<span class="sv-def-icon-img">[[' .. fileTitle .. '|16px|link=]]</span>' | ||
end | end | ||
| Line 179: | Line 173: | ||
local d_lc = lc(domain) | local d_lc = lc(domain) | ||
-- Missing record: show a visible hint but NO tooltip/link data. | |||
if rec == nil then | |||
return | |||
'<span class="sv-def sv-def--missing sv-def--' .. enc_attr(d_lc) .. '"' .. | |||
' data-sv-def-domain="' .. enc_attr(domain) .. '"' .. | |||
' data-sv-def-key="' .. enc_attr(key) .. '"' .. | |||
'>' .. | |||
'<span class="sv-def-icon sv-def-icon--missing" aria-hidden="true">?</span>' .. | |||
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' .. | |||
'</span>' | |||
end | |||
local attrs = { | local attrs = { | ||
| Line 186: | Line 192: | ||
} | } | ||
-- Only include tooltip/link attributes when populated. | |||
if defn ~= "" then | if defn ~= "" then | ||
attrs[#attrs + 1] = 'data-sv-def-tip="' .. enc_attr(defn) .. '"' | attrs[#attrs + 1] = 'data-sv-def-tip="' .. enc_attr(defn) .. '"' | ||
| Line 195: | Line 202: | ||
local title_attr = (defn ~= "") and (' title="' .. enc_attr(defn) .. '"') or "" | local title_attr = (defn ~= "") and (' title="' .. enc_attr(defn) .. '"') or "" | ||
return | |||
'<span ' .. table.concat(attrs, " ") .. title_attr .. '>' .. | '<span ' .. table.concat(attrs, " ") .. title_attr .. '>' .. | ||
icon_html(icon) .. | icon_html(icon) .. | ||
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' .. | '<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' .. | ||
'</span>' | '</span>' | ||
end | end | ||
| Line 214: | Line 213: | ||
-- ============================================================================= | -- ============================================================================= | ||
function p.def(frame) | function p.def(frame) | ||
local a = frame.args or {} | local a = frame.args or {} | ||
| Line 220: | Line 218: | ||
end | end | ||
function p.render(domain, key) | function p.render(domain, key) | ||
return render(domain, key) | return render(domain, key) | ||