Jump to content

Module:Jcon and Module:Jcon/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
fix text color in dark mode; this generally works but may cause problems, in which case revert or try specifying a different CSS value
 
Use 36px
 
Line 6: Line 6:
local yesno = require('Module:Yesno')
local yesno = require('Module:Yesno')
local parser = require('Module:Road data/parser').parser
local parser = require('Module:Road data/parser').parser
local roadData = require('Module:Road data/sandbox') -- REMOVE SANDBOX


local dataModuleName = 'Module:Jcon/data'
local data = mw.loadData('Module:Jcon/data/sandbox') -- REMOVE SANDBOX
local data = mw.loadData(dataModuleName)
local ON = mw.loadData('Module:Road data/strings/CAN/ON')


-- Normalize the given road type
-- Normalize the given road type
Line 14: Line 15:
roadType = (roadType or ''):lower() -- Make the road type lowercase
roadType = (roadType or ''):lower() -- Make the road type lowercase


for index, placeType in ipairs(data._placeTypes) do
for index, placeType in ipairs(data.placeTypes) do
roadType = roadType -- Remove the place types from the road type
roadType = roadType -- Remove the place types from the road type
:gsub('^' .. placeType .. ' of ', '')
:gsub('^' .. placeType .. ' of ', '')
Line 20: Line 21:
:gsub(' ' .. placeType .. ' road$', '')
:gsub(' ' .. placeType .. ' road$', '')
end
end

return roadType
return data.typeMap[roadType] or roadType
end
end


-- Generate wikitext to show an icon
-- Generate wikitext to show a MTO sign
local function showFile(fileName, args, sign)
local function showSign(fileName, size, args)
local size = args.size or '20px' -- Image size
local size = size:match('^%d+px$')
and size
or require('Module:Road data/size')._size{ style = size }
if sign then
fileName = data._signs[fileName] -- Get the file name from the sign definition
fileName = data.signs[fileName] -- Get the file name from the sign definition
else
local titleObj = mw.title.new('File:' .. fileName)
if not titleObj or not titleObj.file.exists then
return '' -- Return nothing if no existing file was found
end
end
return '[[File:' .. fileName .. '|alt=|link=|' .. size .. ']]' -- Return the file wikitext
return '[[File:' .. fileName .. '|alt=|link=|' .. size .. ']]' -- Return the file wikitext
end

-- Get the first defined shield from a table
local function getShield(parserArgs, shield, to)
-- Shield format for "to" routes
if to and shield then
local res = parser(parserArgs, 'shieldtomain', nil, dataModuleName)
if res then return res end
end
-- Guide format for "to" routes
if to then
local res = parser(parserArgs, 'shieldto', nil, dataModuleName)
if res then return res end
end
-- Shield format (used as reassurance marker)
if shield then
local res = parser(parserArgs, 'shieldlist', nil, dataModuleName)
if res then return res end
end
-- Guide format (used on guide signs)
local res = parser(parserArgs, 'shield', nil, dataModuleName)
if res then return res end
return ''
end

-- Generate the wikitext for the shield
local function shieldWikitext(parserArgs, args, prefix)
local shield = getShield(parserArgs, yesno(args.shield), prefix == 'to')
if type(shield) == 'table' then
local out = {}
for i, single in ipairs(shield) do
table.insert(out, showFile(single, args))
end
return table.concat(out, ' ') -- Add a space between multiple shields
end
return showFile(shield, args)
end
end


Line 104: Line 53:
-- Generate the text part of the output
-- Generate the text part of the output
local function getText(parserArgs, args, noSelfRedirect)
local function getText(parserArgs, args, noSelfRedirect)
local linkParserArgs = {}
local link = parser(parserArgs, 'link', nil, dataModuleName)
for k, v in pairs(parserArgs) do linkParserArgs[k] = v end
linkParserArgs.ignoreifexists = true
local link = parser(linkParserArgs, 'link', nil)
local display = ''
local display = ''
if yesno(args.fulltext) then
if yesno(args.fulltext) then
-- Display the full link title when requested
-- Display the full link title when requested
display = parser(parserArgs, 'name', nil, dataModuleName)
display = parser(parserArgs, 'name', nil)
else
else
display = parser(parserArgs, 'abbr', nil, dataModuleName)
display = parser(parserArgs, 'abbr', nil)
end
end
Line 123: Line 76:


-- Process routes present in the provided arguments
-- Process routes present in the provided arguments
local function processRoutes(roadType, showShield, showText, args, prefix, name)
local function processRoutes(roadType, size, showShield, showText, args, prefix, name)
local shield = '' -- Generated shield wikitext
local shield = '' -- Generated shield wikitext
local text = '' -- Generated text/link wikitext
local text = '' -- Generated text/link wikitext
Line 142: Line 95:
-- Arguments for the road data parser
-- Arguments for the road data parser
local parserArgs = {
local parserArgs = {
to = prefix == 'to',
ignoreifexists = true,
country = 'CAN',
country = 'CAN',
province = 'ON',
province = 'ON',
Line 150: Line 103:
if showShield then
if showShield then
local routeShield = shieldWikitext(parserArgs, args, prefix) -- Generate route shield
local routeShield = roadData.shield(parserArgs, yesno(args.shield) and 'list', size) -- Generate route shield
if routeShield ~= '' then
if routeShield ~= '' then
if shield ~= '' then shield = shield .. ' ' end -- Add space after existing shields
if shield ~= '' then shield = shield .. ' ' end -- Add space after existing shields
shield = shield .. routeShield -- Add the shield
shield = shield .. routeShield -- Add the shield
end
end
Line 203: Line 156:
local showText = not yesno(args.notext)
local showText = not yesno(args.notext)
local shieldAfter = yesno(args.picaft or args['pic aft'])
local shieldAfter = yesno(args.picaft or args['pic aft'])
local size = args.size or 'jct'
local shield = nil -- Generated shield wikitext
local shield = nil -- Generated shield wikitext
local text = nil -- Generated text/name wikitext
local text = nil -- Generated text/name wikitext
if data._signs[roadType] then
if data.signs[roadType] then
-- Handle MTO signs
-- Handle MTO signs
shield = showFile(roadType, args, true)
shield = showSign(roadType, size, args)
text = args[2] or ''
text = args[2] or ''
elseif data[roadType] then
elseif ON[roadType] then
-- Handle numbered roads
-- Handle numbered roads
shield, text = processRoutes(roadType, showShield, showText, args, 'con', args[3])
shield, text = processRoutes(roadType, size, showShield, showText, args, 'con', args[3])
-- Handle to and via parameters
-- Handle to and via parameters
local toShield, toText = processRoutes(roadType, showShield, showText, args, 'to', args.toname)
local toShield, toText = processRoutes(roadType, size, showShield, showText, args, 'to', args.toname)
local viaShield, viaText = processRoutes(roadType, showShield, showText, args, 'via', args.vianame)
local viaShield, viaText = processRoutes(roadType, size, showShield, showText, args, 'via', args.vianame)
if toShield ~= '' then
if toShield ~= '' then
Line 243: Line 197:
if shield ~= '' then shield = shield .. ' ' end -- Add space after existing shields
if shield ~= '' then shield = shield .. ' ' end -- Add space after existing shields
-- Add the MTO sign if provided
-- Add the MTO sign if provided
shield = shield .. showFile(args.sign, args, true)
shield = shield .. showSign(args.sign, size, args)
end
end
Line 249: Line 203:
if showShield then
if showShield then
if shield ~= '' then shield = shield .. ' ' end -- Add space after existing shields
if shield ~= '' then shield = shield .. ' ' end -- Add space after existing shields
shield = shield .. showFile('tch', args, true) -- Add the TCH shield
shield = shield .. showSign('tch', size, args) -- Add the TCH shield
end
end


Line 296: Line 250:
local type = normalizeType(args[1])
local type = normalizeType(args[1])
local route = args[2]
local route = args[2]
local size = args.size or '36px'
if not data[type] then return '' end
if not ON[type] then return '' end
-- Add table
-- Add table
local out = '<table style="margin: 0; padding: 0; width: 100%; align: left;">'
local out = '<table style="background: transparent; margin: 0; padding: 0; width: 100%; align: left;">'
-- Add a table row
-- Add a table row
Line 308: Line 261:
-- Arguments for the road data parser
-- Arguments for the road data parser
local parserArgs = {
local parserArgs = {
ignoreifexists = true,
country = 'CAN',
country = 'CAN',
province = 'ON',
province = 'ON',
Line 316: Line 268:
-- Generate route shield
-- Generate route shield
local routeShield = shieldWikitext(parserArgs, { size = size, shield = true })
local routeShield = roadData.shield(parserArgs, 'list', '36px')
if routeShield ~= '' then
if routeShield ~= '' then
out = out .. '<td style="border: 0px; margin: 0px; padding: 0px;">' .. routeShield .. '</td>'
out = out .. '<td style="background: transparent; border: 0px; margin: 0px; padding: 0px;">' .. routeShield .. '</td>'
end
end
-- Generate route text
-- Generate route text
local routeText = getText(parserArgs, { fulltext = true }, true)
local routeText = getText(parserArgs, { fulltext = true }, true)
if routeText ~= '' then
if routeText ~= '' then
out = out .. '<td style="border: 0px; margin: 0px; padding: 0px; text-align: center;">' .. routeText .. '</td>'
out = out .. '<td style="background: transparent; border: 0px; margin: 0px; padding: 0px; text-align: center;">' .. routeText .. '</td>'
end
end