Content deleted Content added
No edit summary |
sync with live template |
||
(28 intermediate revisions by 7 users not shown) | |||
Line 72:
table.insert(formatKeys, k)
end
return name .. ' was "' .. key .. '" but neither an entry for it nor a default was found. Choices were: ' .. table.concat(formatKeys, ', ')
end
Line 132 ⟶ 131:
function p._main(_args) -- Arguments are processed here instead of the main function
local yesno = require('Module:Yesno')
local trimq = require('Module:Trim quotes')._trim
local boolean = {
Line 145 ⟶ 147:
for k, v in pairs(_args) do -- Maps each raw argument to processed arguments by string matching
if _args[k] and _args[k] ~= '' then
local a = mw.ustring.match(k, '^(.*%D)%d+$') or k -- The parameter; address 1 can be omitted
local b = tonumber(mw.ustring.match(k, '^.*%D(%d+)$')) or 1 -- The address for a given argument; address 1 can be omitted
if boolean[a] then
v =
end
if not args[b] then
args[b] = {[a] = v}
table.insert(index, b)
elseif args[b][a] then
return error(i18n[lang]['error_duplicate'](a .. b))
else
args[b][a] = v
end
end
end
Line 172 ⟶ 177:
['header midcell'] = 'colspan="3" class="hmA"|',
['body cell'] = 'class="bcA"|',
['body banner'] = 'class="bbA notheme" style="color:inherit;background-color:#',
}
Line 232 ⟶ 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 258 ⟶ 263:
color = Type['color']
color_2 = Type['color2'] or color
else
background_color = Type['background color'] or line['background color']
color = line['color'] or default['color'] or ''
color_2 = line['color2'] or color
Line 282 ⟶ 283:
for i, b in ipairs({'left', 'right'}) do
if not args[v][b] then -- If no station is given on one side, the station is assumed to be the terminus on that side
local _through = args[v]['through-' .. b] or args[v]['through']
local _through_data = getLine(data[v], _through)
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 411 ⟶ 420:
lineN = args[2] or args.line
if not (system or lineN) then return '' end
local line, Type, line_data
local inline = args[3] or args.inline
typeN = args.type
local data = args.data
if system or data then
Line 420 ⟶ 428:
local color
if data then
local default = data['lines']['_default'] or {}
line, lineN = getLine(data, lineN)
if typeN then
Line 427 ⟶ 436:
color = getColor(data, nil, lineN, typeN)
if inline ~= 'box' then
line_data = line or error(i18n[lang]['error_unknown'](lineN))
line = line_data['title'] or default['title'] or error(i18n[lang]['error_missing']('title'))
line = mw.ustring.gsub(line, '%%1', lineN)
end
else
color = getColor(nil, system, lineN, typeN, frame)
if inline ~= 'box' then
if mw.text.trim(
end
Type = typeN
Line 450 ⟶ 451:
local result
if Type and Type ~= '' and inline ~= 'box'
if
else
result = ' – ' .. Type
Line 461 ⟶ 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> ' ..
elseif inline == 'yes' then
result = '<span style="color:inherit;background-color:#' .. color .. ';border:1px solid #000"> </span> ' ..
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(
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
result = '<span style="color:#' .. color .. ';line-height:initial">■</span> ' ..
elseif inline == 'lsquare' then
local link = args.link or mw.ustring.match(
if link then
result = '[[' .. link .. '|<span style="color:#' .. color .. ';line-height:initial">■</span>]]'
Line 483 ⟶ 484:
end
elseif inline == 'dot' then
result = '<span style="color:#' .. color .. ';line-height:initial">●</span> ' ..
elseif inline == 'ldot' then
local link = args.link or mw.ustring.match(
if link then
result = '[[' .. link .. '|<span style="color:#' .. color .. ';line-height:initial">●</span>]]'
Line 492 ⟶ 493:
end
elseif inline == 'small' then
result = '<span style="color:inherit;background-color:#' .. color .. '"> </span>' .. ' ' ..
else
local yesno = require("Module:Yesno")
local link = args.link or mw.ustring.match(
local border_color, text_color
local color_box = data['color box format'] or data['rail box format'] or {}
if line_data then
if line_data['types'] and line_data['types'][typeN] then
local Type_data = line_data['types'][typeN]
Line 504 ⟶ 505:
text_color = Type_data['text color'] or line_data['text color']
if color_box == 'title' and not args[4] then
lineN = Type_data['short name'] or line_data['short name'] or require('Module:Delink')._delink{
else
lineN = Type_data['short name'] or line_data['short name'] or lineN
Line 512 ⟶ 513:
text_color = line_data['text color']
if color_box == 'title' and not args[4] then
lineN = line_data['short name'] or require('Module:Delink')._delink{
else
lineN = line_data['short name'] or lineN
Line 518 ⟶ 519:
end
else
border_color = color
end
text_color = text_color and '#' .. text_color or require('Module:Color contrast')._greatercontrast{color}
local bold =
if (yesno(args.bold) == false) then bold = '' end
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 534 ⟶ 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 546 ⟶ 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> ' ..
end
end
Line 566 ⟶ 564:
local system = args[1] or args.system
local data = args.data
if not system and not data then
return
end
data = data or getData(system)
local
local icon
local icon_format
if line then
local line_type = args[3] or args.type
if line_type then
line_type = data.aliases and data.aliases[mw.ustring.lower(line_type)] or line_type
line_type = line.types and line.types[line_type] -- If there's no type table or entry for this type, then it can't have its own icon
if line_type.icon then
icon = line_type.icon
end
end
if not icon then
icon = line.icon
end
-- Only if there is no icon use the icon_format.
if not icon and not icon_format then
icon_format = line['icon format'] or data['line icon format'] end local default = data.lines._default or {}
if icon and string.find(icon, "%%1") and default and default.icon then
icon = mw.ustring.gsub(default.icon, '%%1', line_name)
end
end
if not icon then
icon = data['system icon']
end
if not icon_format then
icon_format = data['system icon format']
end
if icon_format then
if icon_format ~= 'image' then
icon = p._box({data = data, [2] =
if args.name then
return icon .. " " .. line.title
end
return
end
end
end
local size = args.size
Line 635 ⟶ 647:
end
local link = args.link
if link then
if mw.ustring.match(icon, '|%s*link=[^%]|]*[%]|]') then
Line 652 ⟶ 665:
end
if args.name then
if line and line.title then
return icon .. " " .. line.title
end
return icon .. " " ..
end
return icon
Line 664 ⟶ 675:
p.icon = makeInvokeFunction('_icon')
p['rail icon'] = makeTemplateFunction('_icon')
function p._line(args, frame)
Line 674 ⟶ 686:
data = data or getData(system, true)
if data then
line = (getLine(data, line)) or error(i18n[lang]['error_unknown'](line))
if Type then
Type = data['aliases'] and data['aliases'][mw.ustring.lower(Type)] or Type
Line 698 ⟶ 709:
p.line = makeInvokeFunction('_line')
function p._shortline(args, frame)
local system = args[1] or args.system
lineN = args[2] or args.line
if not (system or lineN) then return '' end
local line, Type, line_data
typeN = args.type
local data = args.data
if system or data then
data = data or getData(system, true)
if data then
local default = data['lines']['_default'] or {}
line, lineN = getLine(data, lineN)
if typeN then
typeN = data['aliases'] and data['aliases'][mw.ustring.lower(typeN)] or typeN
Type = line['types'] and line['types'][typeN] and line['types'][typeN]['title'] or typeN
end
line_data = line or error(i18n[lang]['error_unknown'](lineN))
line = line_data['title'] or default['title'] or error(i18n[lang]['error_missing']('title'))
line = mw.ustring.gsub(line, '%%1', lineN)
else
line = frame:expandTemplate{ title = system .. ' lines', args = {lineN, ['branch'] = typeN} }
if mw.text.trim(line) == '' then return error(i18n[lang]['error_unknown'](lineN)) end
Type = typeN
end
local result
if Type and Type ~= '' then
if line == '' then
line = Type
else
result = ' – ' .. Type
end
end
if args.note then result = (result or '') .. ' ' .. args.note end
result = result or ''
local link = args.link or mw.ustring.match(line, '%[%[([^%[:|%]]+)[|%]]')
if line_data then
if line_data['types'] and line_data['types'][typeN] then
local Type_data = line_data['types'][typeN]
lineN = Type_data['short name'] or line_data['short name'] or lineN
else
lineN = line_data['short name'] or lineN
end
end
if link then
result = '[[' .. link .. '|' .. lineN .. ']]'
else
result = lineN
end
result = mw.ustring.gsub(result, ':%s*#transparent', ':transparent')
return result
end
end
p.shortline = makeInvokeFunction('_shortline')
function p._station(args, frame)
Line 732 ⟶ 804:
p.station = makeInvokeFunction('_station')
p['station link'] = makeTemplateFunction('_station')
function p.
local system = args[1] or args.system
lineN = args[2] or args.line
local side = mw.ustring.sub(mw.ustring.lower(args[3] or args.side or ''), 1, 1)
typeN = args.type
local prefix = (side == 'r') and 'right' or 'left'
local data = args.data
if system or data then
Line 747 ⟶ 818:
end
if data then
local line = getLine(data, lineN) or error(i18n[lang]['error_unknown'](lineN))
if typeN and data and data['aliases'] then typeN = data['aliases'][mw.ustring.lower(typeN)] or typeN end
local Type = line['types'] and line['types'][typeN]
local circular
if Type then
if Type['circular'] then
-- Type may override the circular status of the line
end
else
end
return
else
local terminus = frame:expandTemplate{ title = 'S-line/' .. system .. ' ' .. prefix .. '/' .. lineN
return
end
end
function p._terminus(args, frame)
local var, Format, circular = p._terminusTable(args, frame)
return circular and var or getTerminusText(var, Format)
end
|