Module:Definitions: Difference between revisions
From SpiritVale Wiki
More actions
No edit summary Tags: Reverted Mobile edit Mobile web edit |
No edit summary Tags: Manual revert Mobile edit Mobile web edit |
||
| Line 67: | Line 67: | ||
if DB ~= nil then return DB end | if DB ~= nil then return DB end | ||
local title = mw.title.new(DATA_TITLE) | local title = mw.title.new(DATA_TITLE) | ||
if not title then | if not title then | ||
| Line 87: | Line 79: | ||
end | end | ||
local | local ok, obj = pcall(mw.text.jsonDecode, raw) | ||
if not | if not ok or type(obj) ~= "table" then | ||
DB = {} | DB = {} | ||
return DB | return DB | ||
end | end | ||
DB = | DB = obj | ||
return DB | return DB | ||
end | end | ||
| Line 154: | Line 146: | ||
-- ============================================================================= | -- ============================================================================= | ||
-- | -- Render | ||
-- ============================================================================= | -- ============================================================================= | ||
local function | local function render(domain, key) | ||
local db = load_db() | local db = load_db() | ||
domain = norm_domain(db, domain) | domain = norm_domain(db, domain) | ||
| Line 257: | Line 205: | ||
'<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>' | '</span>' | ||
end | end | ||
| Line 267: | Line 215: | ||
function p.def(frame) | function p.def(frame) | ||
local a = frame.args or {} | local a = frame.args or {} | ||
return | return render(a[1] or a.Domain or a.domain, a[2] or a.Key or a.key) | ||
end | end | ||
function p.render(domain, key) | |||
return render(domain, key) | |||
function p.render( | |||
return | |||
end | end | ||
return p | return p | ||