Module:Adjacent stations/sandbox: Difference between revisions

Content deleted Content added
color: inherit
sync with live template
 
(3 intermediate revisions by 2 users not shown)
Line 237:
local line = data[v]['lines'] and (mw.clone(data[v]['lines'][lineN]) or error(i18n[lang]['error_unknown'](args[v]['line']))) or error(i18n[lang]['error_line'])
local default = data[v]['lines']['_default'] or {}
line['title'] = line['title'] or default['title'] or ''
line['title'] = mw.ustring.gsub(line['title'], '%%1', lineN)
 
Line 390:
return function (frame)
local args = getArgs(frame, {parentOnly = true})
return p[funcName](args, frame)
end
end
 
local function makeTemplateFunction(funcName)
-- makes a function that can be returned from #invoke, using
-- [[Module:Arguments]]
return function (frame)
local args = getArgs(frame, {frameOnly = true})
return p[funcName](args, frame)
end
Line 453 ⟶ 462:
 
if not inline then -- [[Template:Legend]]
result = '<div class="legend" style="page-break-inside:avoid;break-inside:avoid-column"><span class="legend-color" style="display:inline-block;min-width:1.25em;height:1.25em;line-height:1.25;margin:1px 0;border:1px solid black;color:inherit;background-color:#' .. color .. '"> </span> ' .. line .. result .. '</div>'
elseif inline == 'yes' then
result = '<span style="color:inherit;background-color:#' .. color .. ';border:1px solid #000">    </span>&nbsp;' .. line .. result
elseif inline == 'box' then
result = '<span style="color:inherit;background-color:#' .. color .. ';border:1px solid #000">    </span>' .. result
elseif inline == 'link' then
local link = args.link or mw.ustring.match(line, '%[%[([^%[:|%]]+)[|%]]')
if link then
result = '[[' .. link .. '|<span style="color:inherit;background-color:#' .. color .. ';border:1px solid #000">    </span>]]' .. result
else
result = '<span style="color:inherit;background-color:#' .. color .. ';border:1px solid #000">    </span>' .. result
end
elseif inline == 'square' then
Line 484 ⟶ 493:
end
elseif inline == 'small' then
result = '<span style="color:inherit;background-color:#' .. color .. '"> </span>' .. ' ' .. line .. result
else
local yesno = require("Module:Yesno")
Line 517 ⟶ 526:
if inline == 'route' then -- [[Template:RouteBox]]
if link then
result = '<span style="color:inherit;background-color:#' .. color .. ';border:.075em solid #' .. border_color .. ';padding:0 .3em">[[' .. link .. '|<span style="color:' .. text_color .. bold .. ';font-size:inherit;white-space:nowrap">' .. lineN .. '</span>]]</span>'
else
result = '<span style="background-color:#' .. color .. ';border:.075em solid #' .. border_color .. ';padding:0 .3em;color:' .. text_color .. bold .. ';font-size:inherit;white-space:nowrap">' .. lineN .. '</span>'
Line 523 ⟶ 532:
elseif inline == 'croute' then -- [[Template:Bahnlinie]]
if link then
result = '<span style="color:inherit;background-color:#' .. color .. ';border:.075em solid #' .. border_color .. ';border-radius:.5em;padding:0 .3em">[[' .. link .. '|<span style="color:' .. text_color .. bold .. ';font-size:inherit;white-space:nowrap">' .. lineN .. '</span>]]</span>'
else
result = '<span style="color:inherit;background-color:#' .. color .. ';border:.075em solid #' .. border_color .. ';border-radius:.5em;padding:0 .3em;color:' .. text_color .. bold .. ';font-size:inherit;white-space:nowrap">' .. lineN .. '</span>'
end
elseif inline == 'xroute' then -- [[Template:Bahnlinie]]
Line 535 ⟶ 544:
elseif inline == 'broute' then
if link then
result = '<span style="color:inherit;background-color:#' .. color .. ';border:.075em solid #000;padding:0 .3em">[[' .. link .. '|<span style="color:' .. text_color .. bold .. ';font-size:inherit;white-space:nowrap">' .. lineN .. '</span>]]</span>'
else
result = '<span style="background-color:#' .. color .. ';border:.075em solid #000;padding:0 .3em;color:' .. text_color .. bold .. ';font-size:inherit;white-space:nowrap">' .. lineN .. '</span>'
end
else -- [[Template:Legend]] (fallback; duplication to simplify logic)
result = '<div class="legend" style="page-break-inside:avoid;break-inside:avoid-column"><span class="legend-color" style="display:inline-block;min-width:1.25em;height:1.25em;line-height:1.25;margin:1px 0;border:1px solid black;color:inherit;background-color:#' .. color .. '"> </span> ' .. line .. result .. '</div>'
end
end
Line 666 ⟶ 675:
 
p.icon = makeInvokeFunction('_icon')
p['rail icon'] = makeTemplateFunction('_icon')
 
function p._line(args, frame)
Line 794 ⟶ 804:
 
p.station = makeInvokeFunction('_station')
p['station link'] = makeTemplateFunction('_station')
 
function p._terminusTable(args, frame)
Line 843 ⟶ 854:
local result = {}
local data = args.data
local default = 'background-color:#efefef; color: black;' -- Default background color for {{Infobox station}}
 
local default = 'background-color:#efefef; color: black;' -- Default background color for {{Infobox station}}
if style ~= 'subheader' then default = 'color: inherit' end -- Workaround .notheme setting black text color
 
if system or data then
data = data or getData(system, true)
Line 861 ⟶ 869:
end
 
if style == 'header' or style == 'subheader' then
local tmp = data['name format'] and getValue(data['name format'])
local nameFormat = ''
if color ~= ''tmp then table.insert(result, 'color:' .. colortmp) end
local useBackground = true
ifelseif style == 'headersubheader' then
nameFormatlocal tmp = data['nameheader formatbackground color'] and getValue(data['nameheader background formatcolor'])
if nameFormattmp then
if background ~= '' then table.insert(result, 'background-color:#' .. backgroundtmp) end
-- HACK for dark mode support
local color = data['#header text color'] ..and getValue(data['header text color'])
if mw.ustring.match( nameFormat, '(background%-?c?o?l?o?r?: ?)transparent(;?)' ) then
local if color = ''then
useBackground = false
table.insert(result, nameFormat'color:#' .. color)
nameFormat = mw.ustring.gsub( nameFormat, '(background%-?c?o?l?o?r?: ?)transparent(;?)', '' )
nameFormat = mw.ustring.gsub( nameFormat, 'color: ?black(;?)', 'color: inherit%1' )
end
 
table.insert(result, nameFormat)
end
end
 
local background = ''
if not mw.ustring.match( nameFormat, 'background' ) and useBackground then
if data['header background color'] then
background = '#' .. getValue(data['header background color'])
elseif style ~= 'header' then
background = '#efefef'
else
background = '#f8f9fa'
end
end
 
local color = ''
if not ( mw.ustring.match( nameFormat, '^color' ) or mw.ustring.match( nameFormat, ' color' ) or mw.ustring.match( nameFormat, ';color' ) ) then
if data['header text color'] then
color = '#' .. getValue(data['header text color'])
elseif background ~= '' then
local greatercontrast = require('Module:Color contrast')._greatercontrast
color =if greatercontrast{backgroundtmp} == '#FFFFFF' then table.insert(result, 'color:#FFFFFF') end
 
if color == '' then color = '#ffffff' end
else
color = 'inherit'
end
else
table.insert(result =, default)
backgroundlocal color = data['#header text color'] ..and getValue(data['header backgroundtext color'])
if color then table.insert(result, 'color:#' .. color) end
end
 
if background ~= '' then table.insert(result, 'background-color:' .. background) end
if color ~= '' then table.insert(result, 'color:' .. color) end
end
result = table.concat(result, ';')
Line 936 ⟶ 919:
result = table.concat(result, ';')
else
elseifif style ~== 'headersubheader' then
result = default
result = default
else
result = ''
end
end
else
if style == 'subheader' then
result = default
result = default
else
result = ''
end
end