Module:Infobox road/sandbox: Difference between revisions

Content deleted Content added
move around
use sandbox subtemplate
 
(36 intermediate revisions by 3 users not shown)
Line 1:
local p = {}
local getArgs = require('Module:Arguments').getArgs
local roadDataModule = require("Module:Road data")
local util = require("Module:Road data/util")
local yesno = require('Module:Yesno')
local langModule = require('Module:Lang')
local routeModule = require("Module:Infobox road/route/sandbox")
local lengthModule = require("Module:Infobox road/length")
local parserModule = require("Module:Road data/parser")
local parser = parserModule.parser
Line 23 ⟶ 21:
-- HEADER COLORS
 
function p._headerStyleheaderStyle(argsframe)
local args = getArgs(frame)
local deleted = args.decommissioned or args.deleted
local header
local uc = args.header_type == "under construction" or args.header_type == "const" or args.header_type == "uc"
local minor = if args.header_type == "minor"nil then
header = args.header_type
local hist = args.header_type == "hist" or args.header_type == "historic" or args.header_type == "historical" or args.header_type == "scenic"
else
local color = parser(args, 'color')
header = string.lower(args.header_type)
end
local deleted = args.decommissioned or args.deleted or header == "former"
local uc = header == "under construction" or header == "const" or header == "uc"
local minor = header == "minor"
local hist = header == "hist" or header == "historic" or header == "historical" or header == "scenic"
local color = parser(args, 'color') or args['header_color']
local freeway = header == "freeway"
if ucfreeway then
return "header-MUTCDblue"
elseif uc then
return "header-uc"
elseif minor then
return "header-minor"
elseif deleted and header == 'hist' or deleted and color == 'hist' then
return "header-deleted-hist"
elseif deleted then
return "header-deleted"
Line 46 ⟶ 57:
return "header-default"
end
end
 
function p.headerStyle(frame)
local args = getArgs(frame)
return p._headerStyle(args)
end
 
Line 80 ⟶ 86:
local translation = args.translation or parser(args, 'translation') or ''
if translationcountry(args) ~== ''"PAK" and langtranslation =~= 'none' then
local route = args.route
if route ~= nil then
local arabicModule = require( "Module:Convert to eastern arabic numerals" )
local arabic = arabicModule._convert({route})
local translated = string.gsub( translation, route, arabic)
return frame:expandTemplate{title = 'Nastaliq', args = {translated}}
else
return frame:expandTemplate{title = 'Nastaliq', args = {translation}}
end
elseif translation ~= '' and lang == 'none' then
return translation
elseif country(args) == "CHN" and args.type == "Expwy" then
local trans = require( "Module:Road data/masks/CHN/Expwy translations" )
local route = args.route
return langModule._lang({lang, trans[route]})
elseif country(args) == "HUN" then
local nominal = require( "Module:Road data/masks/HUN" )
Line 104 ⟶ 127:
return langModule._lang({"hu", leading .. nominal[routeNum] .. " közút"})
end
elseif lang == "ar" and translation ~= '' then
local arabicModule = require( "Module:Convert to eastern arabic numerals" ).convert
local route = args.route
local arabicModule = require( "Module:Convert to eastern arabic numerals" )
local arabic = arabicModule[route]
local translationarabic = argsarabicModule.translation_convert({route})
local translated = string.gsub( translation, route, arabic)
Line 131 ⟶ 153:
 
local function maint(args)
local maint = args.maint or parser(args, 'maint') or nil''
if maint == "none" or nilmaint == '' then
return nil
else
return "Maintained by " .. maint
end
end
Line 147 ⟶ 169:
 
local function law(args)
local law = parser(args, 'law') or nil''
if lawargs.section == nil'' then
return nil
else
return "Defined by " .. law
end
end
Line 163 ⟶ 185:
 
function p._existed(args)
local formed = args.established or args.formed or nil''
local deleted = args.decommissioned or args.deleted or nil''
if formed == nil'' then
return nil
elseif deleted == nil'' then
return formed .. "–present"
else
Line 188 ⟶ 210:
infobox_args['bodystyle'] = 'display:inline-table;'
infobox_args['child'] = 'yes'
infobox_args['decat'] = 'yes'
infobox_args['label1'] = "Time period"
infobox_args['data1'] = args.time_period
Line 244 ⟶ 267:
 
local function spurOf(args)
local jctModule = require("Module:Jct")
local state = args.state or args.province
local country = args.country
Line 251 ⟶ 273:
local parentRoute = args.spur_of
local aux = parser(args, 'aux') or "Auxiliary route" or nil
local jct = frame:expandTemplate{
local jct = jctModule.roadlink({state = state, country = country, county1 = county, parentType, parentRoute})
title = 'jct', args = {
state = state,
country = country,
county1 = county,
parentType,
parentRoute,
noshield1 = "yes"
}
}
 
if not parentType and not parentRoute then
Line 276 ⟶ 307:
infobox_args['bodystyle'] = 'display:inline-table;'
infobox_args['child'] = 'yes'
infobox_args['decat'] = 'yes'
 
if args["e-road"] then
Line 287 ⟶ 319:
if args.tahn then
local tshield = args["tahn-shield"] or ''
infobox_args['data2data3'] = tshield .. " Part of " .. args.tahn
end
if args.mrn then
local mshield = args["mrn-shield"] or ''
infobox_args['data2data4'] = mshield .. " Part of " .. args.mrn
end
Line 307 ⟶ 339:
--BROWSE LINKS
 
local function browseLinksbrowse(args)
if args.nobrowse then return nil end
local ntitlepreviousRoute = parser(args, 'nbrowse') or nil.previous_route
local nlistnextRoute = parser(args, 'nbrowselinks') or nil.next_route
if previousRoute or nextRoute then
local title = parser(args, 'browse') or nil
local boxModule = require "Module:Road data/browse/sandbox"
local list = parser(args, 'browselinks') or nil
local primary = boxModule._browse(args)
local tblModule = require "Module:Road data/browsetable"
return tblModule._browsetable(primary)
if not ntitle and not title then
end
return nil end
end
 
local box = mw.html.create('div'):addClass("hlist")
function p.browse(frame)
if ntitle ~= nil then
local args = getArgs(frame)
box:tag('div'):cssText("font-weight: bold"):wikitext(ntitle )
return browse(args)
end
if nlist ~= nil then
 
local nlinks = mw.html.create('ul')
local function extended(args)
for i,v in pairs(nlist) do
local extended = args.browse
nlinks:tag('li'):wikitext(v)
if args.nobrowse or extended == nil then
end
return nil
box:tag('div'):addClass("noprint"):node(nlinks)
else
local tblModule = require "Module:Road data/browsetable"
-- Negative margin to counteract infobox border-spacing
return tblModule._browsetable(extended, 'margin-top:-3px')
end
end
 
function p.extended(frame)
local args = getArgs(frame)
return extended(args)
end
 
-- HIGHWAY SYSTEM LINKS
 
local function system(args)
if args.system1 then
local infobox_args = {
['child'] = "yes",
['decat'] = "yes",
['bodystyle'] = "border-collapse:collapse;"
}
local i = 1
while (1) do
local systemClassn = "class" .. i
local systemDatan = "data" .. i
local systemArgn = args['system' .. i]
infobox_args[systemClassn] = "hlist"
infobox_args[systemDatan] = systemArgn
if i == 10 then
break
else
i = i + 1
end
end
return frame:expandTemplate ({title='Infobox', args = infobox_args})
if title ~= nil then
end
box:tag('div'):cssText("font-weight: bold;"):wikitext(title )
if list ~= nil then
local links = mw.html.create('ul')
for i,v in pairs(list) do
links:tag('li'):wikitext(v)
end
box:tag('div'):addClass("noprint"):node(links)
end
end
return tostring(box)
end
 
function p.browseLinkssystem(frame)
local args = getArgs(frame)
return browseLinkssystem(args)
end
 
Line 357 ⟶ 416:
local law = law(args)
local period = period_params(args)
local existed = pargs._existed(established or args).formed or nil
local spur = spurOf(args).spur_type or args.spur_of or nil
local part = partOf(args)
Line 375 ⟶ 434:
-- HIGHWAY SYSTEM HEADER
 
local function systemhighwaySystem(args)
if args.nobrowse then return nil end
local country = country(args) or args.countries
if country == nil then
Line 390 ⟶ 449:
end
 
function p.systemhighwaySystem(frame)
local args = getArgs(frame)
return systemhighwaySystem(args)
end
 
-- PREVIOUS ROUTE AND NEXT ROUTE BROWSE
 
local function browse(args)
if args.nobrowse then return nil end
local previousRoute = args.previous_route
local nextRoute = args.next_route
-- TODO What happens if neither are present??
if previousRoute or nextRoute then
local box = mw.html.create('table'):cssText("width:100%; background:none; border-collapse:collapse; display:inline-table;")
local boxModule = require "Module:Road data/browse/sandbox" -- remove "/sandbox" when live!
local primary = boxModule._browse(args)
box:wikitext(primary)
return tostring(box)
end
end
 
function p.browse(frame)
local args = getArgs(frame)
return browse(args)
end
 
local function extended(args)
local extended = args.browse
if args.nobrowse or extended == nil then
return nil
else
local box = mw.html.create('table'):cssText("width:100%; background:none; border-collapse:collapse; display:inline-table;")
box:wikitext(extended)
return tostring(box)
end
end
 
function p.extended(frame)
local args = getArgs(frame)
return extended(args)
end