Module:Icon
Appearance
Documentation for this module may be created at Module:Icon/doc
local p = {}
local function getIconData(iconName)
local iconData = require("Module:Icon/data")
iconName = iconName:lower()
for storedName, data in pairs(iconData) do
if storedName:lower() == iconName then
return data
elseif data.alt then
for altName in string.gmatch(data.alt, "([^|]+)") do
if altName:lower() == iconName then
return data
end
end
end
end
return nil, "[[Module:Icon/data|Icon not found.]] [[Category:Module:Icon ERROR]]"
end
function p.render(frame)
local name = frame.args[1]
local customText = frame.args.l1 or ""
local iconData, err = getIconData(name)
if not iconData then
return "Error: " .. err
end
local imagePath = iconData.image or "Icon missing.png"
local link = iconData.link or name
local displayName = iconData.name or name
local alt = iconData.alt
local class = iconData.class or ""
-- Default style if no class is provided
local style = 'style="white-space:nowrap; position:relative; bottom:2px;"'
if class == "item" then
style = 'style="white-space:nowrap; position:relative; bottom:2px; filter:brightness(0) saturate(100%);"'
elseif class == "ability" then
style = 'style="white-space:nowrap; position:relative; bottom:2px; filter:brightness(0);"'
elseif class == "hero" then
style = 'style="white-space:nowrap; position:relative; bottom:2px;"'
end
if alt then
for altName in string.gmatch(alt, "([^|]+)") do
if altName:lower() == name:lower() then
displayName = altName
break
end
end
end
local finalText = customText ~= "" and customText or displayName
return string.format('<span %s>[[File:%s|20px]]</span> [[%s|%s]]', style, imagePath, link, finalText)
end
return p