Module:Adjacent stations/sandbox: Difference between revisions

Content deleted Content added
m T_T
sync with live template
 
(39 intermediate revisions by 7 users not shown)
Line 72:
table.insert(formatKeys, k)
end
if not key then return name .. ' was not specified nor a default was found. Choices were: ' .. table.concat(formatKeys, ', ') end
return name .. ' was "' .. key .. '" but neither an entry for it nor a default was found. Choices were: ' .. table.concat(formatKeys, ', ')
end
Line 178 ⟶ 177:
['header midcell'] = 'colspan="3" class="hmA"|',
['body cell'] = 'class="bcA"|',
['body banner'] = 'class="bbA notheme" style="color:inherit;background-color:#',
}
 
Line 238 ⟶ 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 264 ⟶ 263:
color = Type['color']
color_2 = Type['color2'] or color
elseif Type['background color'] then
background_color = Type['background color']
color = line['color'] or default['color'] or ''
color_2 = line['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 395 ⟶ 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 415 ⟶ 419:
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
local inline = args[3] or args.inline
Line 422 ⟶ 426:
if system or data then
data = data or getData(system, true)
local color, station
if data then
local default = data['lines']['_default'] or {}
Line 432 ⟶ 436:
color = getColor(data, nil, lineN, typeN)
if inline ~= 'box' then
line_data = line or error(i18n[lang]['error_unknown'](lineN))
if args.station then
line = line_data['title'] or default['title'] or error(i18n[lang]['error_missing']('title'))
if mw.ustring.match(inline, 'route') then return '' end
line = mw.ustring.gsub(line, '%%1', lineN)
local _Format = data['station format'][args.station] or data['station format'][1]
station = _Format and getStation(args.station, _Format) or args.station or ''
else
line_data = next(line) and 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
end
else
Line 464 ⟶ 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> ' .. (station or line) .. result .. '</div>'
elseif inline == 'yes' then
result = '<span style="color:inherit;background-color:#' .. color .. ';border:1px solid #000">    </span>&nbsp;' .. (station or 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(station or 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
result = '<span style="color:#' .. color .. ';line-height:initial">■</span>&nbsp;' .. (station or line) .. result
elseif inline == 'lsquare' then
local link = args.link or mw.ustring.match(station or line, '%[%[([^%[:|%]]+)[|%]]')
if link then
result = '[[' .. link .. '|<span style="color:#' .. color .. ';line-height:initial">■</span>]]'
Line 486 ⟶ 484:
end
elseif inline == 'dot' then
result = '<span style="color:#' .. color .. ';line-height:initial">●</span> ' .. (station or line) .. result
elseif inline == 'ldot' then
local link = args.link or mw.ustring.match(station or line, '%[%[([^%[:|%]]+)[|%]]')
if link then
result = '[[' .. link .. '|<span style="color:#' .. color .. ';line-height:initial">●</span>]]'
Line 495 ⟶ 493:
end
elseif inline == 'small' then
result = '<span style="color:inherit;background-color:#' .. color .. '"> </span>' .. ' ' .. (station or line) .. result
else
local yesno = require("Module:Yesno")
Line 524 ⟶ 522:
end
text_color = text_color and '#' .. text_color or require('Module:Color contrast')._greatercontrast{color}
local bold = (yesno(args.bold) == false) and '' or ';font-weight: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> ' .. (station or line) .. result .. '</div>'
end
end
Line 581 ⟶ 579:
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
icon_format = line_type['icon format'] or data['type icon format']
Line 677 ⟶ 675:
 
p.icon = makeInvokeFunction('_icon')
p['rail icon'] = makeTemplateFunction('_icon')
 
function p._line(args, frame)
Line 687 ⟶ 686:
data = data or getData(system, true)
if data then
line = (getLine(data, line)) or error(i18n[lang]['error_unknown'](line))
if not next(line) then error(i18n[lang]['error_unknown'](args[2] or args.line)) end
if Type then
Type = data['aliases'] and data['aliases'][mw.ustring.lower(Type)] or Type
Line 711 ⟶ 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 745 ⟶ 804:
 
p.station = makeInvokeFunction('_station')
p['station link'] = makeTemplateFunction('_station')
 
function p._terminus_terminusTable(args, frame)
local system = args[1] or args.system
lineN = args[2] or args.line
if not lineN then return '' end
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
local terminus
 
if system or data then
Line 760 ⟶ 818:
end
if data then
local line = getLine(data, lineN) or error(i18n[lang]['error_unknown'](lineN))
local line, Type
if typeN and data and data['aliases'] then typeN = data['aliases'][mw.ustring.lower(typeN)] or typeN end
line, lineN = getLine(data, lineN)
local Type = line['types'] and line['types'][typeN]
if not next(line) then error(i18n[lang]['error_unknown'](lineN)) end
if typeN then
typeN = data['aliases'] and data['aliases'][mw.ustring.lower(typeN)] or typeN
Type = line['types'] and line['types'][typeN]
end
 
local circular
if Type then
if Type['circular'] then
terminus = Type[prefix .. ' terminus'] or line[prefix .. ' terminus']
-- Type may override the circular status of the line
if circular = Type['circular'] then return terminus end
end
else
terminuscircular = line[prefix .. ' terminuscircular']
if line['circular'] then return terminus end
end
 
return getTerminusText(Type and Type[prefix .. ' terminus'] or line[prefix .. ' terminus'], data['station format'] or i18n[lang]['error_format']), circular
else
local terminus = frame:expandTemplate{ title = 'S-line/' .. system .. ' ' .. prefix .. '/' .. lineN, args = { ['type'] = typeN} }
return frame:expandTemplate{ title = system mw.ustring. ' stations', args = {['station'] = gsub(terminus, ['line{{{type}}}'] = lineN, ['branch'] = typeN} })
end
end
 
function p._terminus(args, frame)
local var, Format, circular = p._terminusTable(args, frame)
 
return circular and var or getTerminusText(var, Format)
end