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)*100/total..'%, #'..colors[k]..' '..k*100/total..'%'
end
gradient = gradient..') 0.1%'
local name = args.name or mw.ustring.gsub(mw.ustring.gsub(mw.title.getCurrentTitle().text, '%s+%b()$', '', 1), ' station', '', 1)
local coord = (args.coord and ' <div style="display:inline-block;vertical-align:middle;line-height:0.9;text-align:right">'..args.coord..'</div>') or ''
local size, length, br, size1, align = '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 class="fn org" style="display:inline-block;vertical-align:middle;line-height:1;font-size:'..size1..';text-align:left">'..name..'</div>'..coord..'</div>'
end
return p