Module:Labeled icon
From Space Station 14 Wiki
Module documentation
|
---|
View or edit this documentation • (about module documentation) |
Implements {{Labeled icon}}.
local p = {}
local getArgs = require('Module:Arguments').getArgs
local function assert_not_nil(value, error_message)
if value == nil then
if error_message == nil then
error("value is nil")
else
error(error_message)
end
end
end
local function numeric_table_length(t)
local count = 0
for _ in ipairs(t) do count = count + 1 end
return count
end
local function table_length(t)
local count = 0
for _ in pairs(t) do count = count + 1 end
return count
end
local function map_table(t, f)
local newt = {}
for k, v in pairs(t) do
newt[k] = f(k, v, t)
end
return newt
end
-- ===================
function p.main(frame)
local args = getArgs(frame)
-- [REQUIRED]
local icon = args[1]
assert_not_nil(icon, "failed to generate labeled icon: icon not provided");
local icon_size = args[2]
assert_not_nil(icon, "failed to generate labeled icon: icon size not provided");
local label = args[3]
assert_not_nil(icon, "failed to generate labeled icon: label not provided");
-- [OPTIONAL]
local link = args[4]
local zoom = args.zoom
-- ============
local label_el = mw.html.create('span')
:addClass("lc-l")
:wikitext(link and "[[" .. link .. "|" .. label .. "]]" or label)
local container_el = mw.html.create('div')
:addClass("li-c")
:wikitext("[[File:" .. icon .. "|" .. icon_size .. "|link=" .. (link or "") .. "|class=lc-i]]")
:node(label_el)
return container_el
end
return p