Jump to content

Module:Track gauge: Difference between revisions

Created page with "-- This module implements the {{Track gauge}} template. -- Data is in Module:Track gauge/data local p = {} local gaugeDataAll = nil local dataPageName = 'Module:Track gauge/da..."
m (1 revision imported)
en>Centrist16
(Created page with "-- This module implements the {{Track gauge}} template. -- Data is in Module:Track gauge/data local p = {} local gaugeDataAll = nil local dataPageName = 'Module:Track gauge/da...")
 
Line 3:
local p = {}
local gaugeDataAll = nil
local dataPageName = 'Module:Track gauge/data' -- set /data/sandbox here
-----------------------------------------------------------------------------------
-- prepareArgs -- Normalise Arguments coming from an #invoke or from a module
Line 110:
-----------------------------------------------------------------------------------
local function frac(whole, num, den)
local templatestyles = mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = 'Screen reader-only/styles.css' }
}
return mw.ustring.format(
'<span class="frac">%s%s<sup>%s</sup>&frasl;<sub>%s</sub></span>',
whole or '', whole and (templatestyles .. '<span class="visualhidesr-only">&nbsp;</span>') or '',
num, den)
end
Line 212 ⟶ 215:
-- formatAltName
-----------------------------------------------------------------------------------
function formatAltName(tgEntry, addArticleLinkaddGaugeName, addGaugeNameLink, disp, setNowrap, engvar)
-- Assumed: at least one to add is true.
-- Asserted: al=on
if tgEntry.name == nil then
-- Not checked: link does exist alone
return ''
end
local retAlt = {}
if disp == 'br' then
table.insert(retAlt, '<br />')
else
table.insert(retAlt, ' ')
Line 226 ⟶ 230:
table.insert(retAlt, '<span class="nowrap">')
end
if addArticleLinkaddGaugeNameLink then
if engvar == 'en-us' then
-- Current implementations (2016): metER for metRE (1000-met, 1009-met)
table.insert(retAlt, tgEntry.en_US_link or tgEntry.link or tgEntry.name)
else
if table.insert(retAlt, tgEntry.link then -- If not defined then fallback to unlinkedor tgEntry.name)
end
table.insert(retAlt, tgEntry.link)
else -- so must be unlinked .name to add
else
if engvar == 'en-us' then
table.insert(retAlt, tgEntry.name)
-- Current implementations (2016): metER for metRE (1000-met, 1009-met)
end
table.insert(retAlt, tgEntry.en_US_name or tgEntry.name)
else
table.insert(retAlt, tgEntry.linkname)
end
end
Line 247 ⟶ 254:
-----------------------------------------------------------------------------------
function p.main(frame)
-- In general: the tgEntry object (from TG/data) is passed to the functions, while arguments are processed here.
local title = mw.title.getCurrentTitle()
local args = prepareArgs(frame)
local tgEntry = p.getTrackGaugeEntry(args.searchAlias)
 
-- Categorise the& pagepreview ifwarning when no track gauge informationdefinition was found.
if tgEntry == nil then
local categoryinput = args[1] or ''
local errorTail = ''
if title:inNamespaces(0, 14) then
local sort1
if frame:preprocess(args[1] or ''"{{REVISIONID}}") == ''"" then -- Blank input, sort top.
errorTail = '<div class="hatnote" style="color:red"><strong>Warning:</strong> ' .. 'Track gauge ' .. (input .. ' ' or '') .. 'not in [[:Template:Track_gauge#List_of_defined_track_gauges|List of defined track gauges]] ([[Template talk:Track gauge|talk]]).' .. ' (This message is shown only in preview.)</div>'
sort1 = ' '
elseend
 
sort1 = args[1] .. ', '
if title:inNamespaces(0, 14) then -- mainspace and category space
end
errorTail = errorTail .. "[[Category:Articles using template 'Track gauge' with unrecognized input|%s%s]]",
category = mw.ustring.format(
"[[Category:Articles using template 'Track gauge' with unrecognized input|%s%s]]",
sort1, title.text)
end
return (args[1] or '')input .. categoryerrorTail
end
 
Line 303 ⟶ 308:
local closeDisp = ''
if disp == 's' or disp == '/' then
joinText = '/&#x200bnbsp;/ ' --spaces
elseif disp == 'br' then
joinText = '<br />('
closeDisp = ')'
elseif disp == '[' or disp == '[]' then
Line 330 ⟶ 335:
end
-- Alternative name
if args.al == 'on' or args.allk ~== nil'on' then
local setNowrapAltname = (nowrap == '' or nowrap == 'on') -- Logic applied to prevent nested nowrap tags
table.insert(ret, formatAltName(tgEntry, args.al == 'on', args.allk == 'on', disp, setNowrapAltname, args.engvar))
end
-- Closing nowrap tag
Line 354 ⟶ 359:
return p
--20161219: maintenance categorisation switched off per CfD
--20170602: fix bug, show name when al=on
--20180708: show preview warning when gauge is not in list
--20190124: with disp=/ (slash) value separator: surround by spaces
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.