Module:CTA header
Appearance
Implements {{Infobox Station/Header CTA}}
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.main(frame)
local args = getArgs(frame, {parentOnly = true})
local function getArgNums(prefix)
-- Returns a table containing the numbers of the arguments that exist
-- for the specified prefix. For example, if the prefix was 'data', and
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
local nums = {}
for k, v in pairs(args) do
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
if num then table.insert(nums, tonumber(num)) end
end
table.sort(nums)
return nums
end
local colors, total = getArgNums('line'), 0
for k, v in ipairs(colors) do
colors[k] = frame:expandTemplate{ title = 'CTA color', args = {args['line'..v]} }
total = total + 1
end
local gradient = 'linear-gradient(to bottom'
for k, v in ipairs(colors) do
gradient = gradient..', #'..colors[k]..' '..((k-1)/total)..'%, #'..colors[k]..' '..(k/total)..'%'
end
gradient = gradient..') 0.1%'
local name = args.name or ''
local coord = args.coord or ''
local size, length, br, size1 = '100%', mw.ustring.len(name), mw.ustring.match(name, '< *\/? *[Bb] [Rr] *\/? *>'), '200%'
if br then
size1 = '100%'
elseif length > 6 then
size = 100*((1/0.35*(length-6)+1.7)+0.4) .. '%'
end
return '<div style="color:white;background:dimgray;height:38px;display:block;vertical-align:middle;line-height:38px;border-left:50px solid #'..(colors[1] or '000000')..';border-right:50px solid #'..(colors[1] or '000000')..';font-size:'..size..';border-image:'..gradient..'"><div style="display:inline-block;vertical-align:middle;font-size:'..size1..'">'..name..'</div><div style="display:inline-block;vertical-align:middle;line-height:0.9;text-align:right;padding-left:3px">'..coord..'</div></div>'
end
return p