Module:Proglan
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Proglan/doc
-- https://wowpedia.fandom.com/wiki/Template:Proglan
local m = {}
local colors = {
b = "b", black = "b",
d = "d", dark = "d", brown = "d",
y = "y", yellow = "y",
w = "w", white = "w",
}
local map = {}
for i = 1, 36 do
if i <= 10 then
map[i] = tostring(i-1)
else
map[i] = string.char(97-11+i)
end
end
local map_reverse = {}
for k, v in pairs(map) do
map_reverse[v] = k
end
local function GetIconText(args, v, isReverse)
local t = {}
t[1] = "File:Proglan-"
if colors[args.color] then
t[1] = t[1]..colors[args.color].."-"
end
t[1] = t[1]..(isReverse and map_reverse[v] or v)..".png"
if args.size == "{{{size}}}" then
args.size = 16
end
table.insert(t, args.size.."x"..args.size.. "px")
table.insert(t, "link=")
table.insert(t, isReverse and v or map[tonumber(v)]) -- hover text
return string.format("[[%s]]", table.concat(t, "|"))
end
local function GetText(f)
local args = f.args
if args.reverse == "{{{reverse}}}" then
local t = mw.text.split(args[1], ":")
for i, v in pairs(t) do
if tonumber(v) then
t[i] = GetIconText(args, v)
else -- must be text
t[i] = v
end
end
return table.concat(t)
else
local t = {}
local s = f.args[1]:lower()
for i = 1, #s do
local letter = s:sub(i, i)
if map_reverse[letter] then
t[i] = GetIconText(args, letter, true)
else
t[i] = letter
end
end
local text = table.concat(t)
text = text:gsub("%s", string.rep(" ", 3))
return text
end
end
function m.main(f)
return GetText(f)
end
return m