Module:Font
From Fallen London Wiki
Documentation for this module may be created at Module:Font/doc
local p = {}
-- defined below
local span, I, IL
-- a hack to delay evaluation until span() is redefined
span = function(text, link, foreground, background)
return function(frame)
return span(text, link, foreground, background)
end
end
-- 1: synonyms (for input matching)
-- long: long version (a function or a string)
-- short: short version (a function or a string)
-- image: image-only version (a function or a string)
local data = {
{
{'Bag a Legend', 'BaL'},
long=function(frame) return IL(frame, 'Bag a Legend') end,
short=function(frame) return I(frame, 'Bag a Legend') end,
image=function(frame) return I(frame, 'Bag a Legend') end
},
{
{'Fruits of the Zee', 'Fruits', 'FotZ'},
long=span('FRUITS OF THE ZEE', 'Fruits of the Zee Festival', 'greenyellow', '#3B4C11'),
short=span('FRUITS', 'Fruits of the Zee Festival', 'greenyellow', '#3B4C11'),
image=function(frame) return I(frame, 'Fruits of the Zee Festival') end
}
}
span = function(text, link, foreground, background)
local s = '<span style="'
if foreground ~= nil then
s = s .. 'color:' .. foreground .. ';'
end
if background ~= nil then
s = s .. 'background:' .. background .. ';'
end
s = s .. '">' .. "'''"
if link ~= nil then
s = s .. '[[' .. link .. '|' .. text .. ']]'
else
s = s .. text
end
s = s .. "'''" .. '</span>'
return s
end
I = function(frame, page)
return frame:expandTemplate{
title='I',
args={page}
}
end
IL = function(frame, page, caption)
return frame:expandTemplate{
title='IL',
args={page, Appearance=caption}
}
end
local function find_at(frame, arg, idx)
if arg == nil then
return span('No input provided', nil, 'red', nil)
end
for _, entry in ipairs(data) do
local matched = false
for _, abbr in ipairs(entry[1]) do
matched = matched or (abbr:lower() == arg:lower())
end
if matched then
local result = entry[idx]
if type(result) == 'function' then
return result(frame)
elseif type(result) == 'string' then
return result
end
end
end
return span('Unknown input: ' .. arg, nil, 'red', nil)
end
function p.long(frame)
local arg = frame.args[1]
return find_at(frame, arg, 'long')
end
function p.short(frame)
local arg = frame.args[1]
return find_at(frame, arg, 'short')
end
function p.image(frame)
local arg = frame.args[1]
return find_at(frame, arg, 'image')
end
return p