Module:Icon: Difference between revisions
From Terra Invicta Official Wiki
Created page with "-- This is a LUA version of the Template:Icon page. -- I'm making this because it should run way way way faster than the 100+ switch cases used by Template:Icon local p = {} local iconData = mw.loadData( 'Module:Icon/data' ) function p.Icon( frame ) local iconName = frame.args[1] if not iconName or not iconData[iconName] then return 'No such icon' end local bgcolor = frame.args['bgcolor'] if not bgcolor then bgcolor = 'transparent'..." |
No edit summary |
||
| Line 5: | Line 5: | ||
local iconData = mw.loadData( 'Module:Icon/data' ) | local iconData = mw.loadData( 'Module:Icon/data' ) | ||
local slower = string.lower | |||
function p.Icon( frame ) | function p.Icon( frame ) | ||
local iconName = frame.args[1] | local iconName = frame.args[1] | ||
if not iconName | if not iconName then | ||
return 'No such icon' | |||
end | |||
if not iconData[iconName] then | |||
iconName = slower(iconName) | |||
end | |||
if not iconData[iconName] then | |||
return 'No such icon' | return 'No such icon' | ||
end | end | ||
Revision as of 19:32, 27 September 2025
Documentation for this module may be created at Module:Icon/doc
-- This is a LUA version of the Template:Icon page.
-- I'm making this because it should run way way way faster than the 100+ switch cases used by Template:Icon
local p = {}
local iconData = mw.loadData( 'Module:Icon/data' )
local slower = string.lower
function p.Icon( frame )
local iconName = frame.args[1]
if not iconName then
return 'No such icon'
end
if not iconData[iconName] then
iconName = slower(iconName)
end
if not iconData[iconName] then
return 'No such icon'
end
local bgcolor = frame.args['bgcolor']
if not bgcolor then
bgcolor = 'transparent'
end
local size = frame.args['size']
if not size then
size = '20px'
end
local retstart = '<span style="background-color: ' .. bgcolor .. '; display: inline-block;">[[File:'
local retmid = '|' .. size .. '|'
local retend = ']]</span>'
-- iconData[iconName][1] is the file name.
-- iconData[iconName][2] is the caption.
return retstart .. iconData[iconName][1] .. retmid .. iconData[iconName][2] .. retend
end
return p


