Module:Infobox road/sections

local p = {}local getArgs = require('Module:Arguments').getArgslocal lengthModule = require("Module:Infobox road/length")local parserModule = require("Module:Road data/parser")local parser = parserModule.parserlocal frame = mw.getCurrentFrame()local function country(args)local state = args.state or args.provincelocal countrylocal countryModule = mw.loadData("Module:Road data/countrymask")local country = args.country or countryModule[state]return countryend-- HEADER COLORSfunction p.headerStyle(args)local deleted = args.decommissioned or args.deletedlocal uc = args.header_type == "under construction" or args.header_type == "const" or args.header_type == "uc"local minor = args.header_type == "minor"local hist = args.header_type == "hist" or args.header_type == "historic" or args.header_type == "historical" or args.header_type == "scenic"local color = parser(args, 'color')if freeway thenreturn "header-MUTCDblue"elseif uc thenreturn "header-uc"elseif minor thenreturn "header-minor"elseif deleted and header == 'hist' or deleted and color == 'hist' thenreturn "header-deleted-hist"elseif deleted thenreturn "header-deleted"elseif hist thenreturn "header-hist"elseif color thenreturn "header-" .. colorelseif args.state or args.province or args.country thenlocal country = country(args)return "header-" .. country or "header-default"elsereturn "header-default"endendfunction p._section(args)if args.section1 or args.length_km1 or args.length_mi1 or args.length_notes1 or args.direction_a1 orargs.terminus_a1 or args.junction1 or args.junctions1 or args.direction_b1 or args.terminus_b1 thenlocal infobox_args = {['child'] = "yes",['decat'] = "yes",['headerclass'] = p.headerStyle(args)}local i = 1while (1) dolocal num = ilocal j = ((i - 1) * 5) + 1local headern = "header" .. jlocal lengthLabeln = "label" .. (j + 1)local lengthDatan = "data" .. (j + 1)local directionAn = "label" .. (j + 2)local terminusAn = "data" .. (j + 2)local jctClassn = "class" .. (j + 3)local jctLabeln = "label" .. (j + 3)local jctDatan = "data" .. (j + 3)local directionBn = "label" .. (j + 4)local terminusBn = "data" .. (j + 4)if args['section' .. i] or args["length_km" .. i] or args["length_mi" .. i] or args["length_notes" .. i] or args["direction_a" .. i] orargs["terminus_a" .. i] or args["junction" .. i] or args["junctions" .. i] or args["direction_b" .. i] or args["terminus_b" .. i] thenif i == 1 theninfobox_args['title'] = args['section' .. i] or "Section " .. ielseinfobox_args[headern] = args['section' .. i] or "Section " .. iendendinfobox_args[lengthLabeln] = "Length"infobox_args[lengthDatan] = lengthModule._length(num, args)local dir_a = args["direction_a" .. i] or args.direction_a or ''if dir_a ~= '' theninfobox_args[directionAn] = dir_a .. "&nbsp;end"elseinfobox_args[directionAn] = "From"endinfobox_args[terminusAn] = args["terminus_a" .. i]infobox_args[jctClassn] = "plainlist"infobox_args[jctLabeln] = "Major intersections"infobox_args[jctDatan] = args["junction" .. i] or args["junctions" .. i]local dir_b = args["direction_b" .. i] or args.direction_b or ''if dir_b ~= '' theninfobox_args[directionBn] = dir_b .. "&nbsp;end"elseinfobox_args[directionBn] = "From"endinfobox_args[terminusBn] = args["terminus_b" .. i]if i == 25 thenbreakelsei = i + 1endendreturn frame:expandTemplate ({title='Infobox', args = infobox_args})else return nilendendfunction p.section(frame)args = getArgs(frame)return p._section(args)endlocal function loop(args)local ring_road = args.ring_road or ''if ring_road ~= '' thenreturn "[[Ring road]] around " .. ring_roadendlocal beltway_city = args.beltway_city or ''if beltway_city ~= '' thenreturn "[[Beltway]] around " .. beltway_cityendlocal orbital = args.orbital or ''if orbital ~= '' thenreturn "[[Orbital road|Orbital]] around " .. orbitalendlocal loop = args.loop or ''if loop ~= '' thenreturn "[[Loop road|Loop]] around " .. loopendlocal tloop = args.tloop or ''if tloop == 'none' thenreturn "Tourist loop"elseif tloop ~= '' thenreturn "Tourist loop around " .. tloopendreturn nilendfunction p._main(args)if args.terminus_a or args.junction or args.junctions or args.terminus_b or args.ring_road or args.beltway_city orargs.orbital or args.loop or args.tloop thenlocal infobox_args = {['child'] = "yes",['decat'] = "yes",}infobox_args['title'] = args.section0 or "Major junctions"infobox_args['data1'] = loop(args)local dir_a = args.direction_a or ''if dir_a ~= '' theninfobox_args['label2'] = dir_a .. "&nbsp;end"elseinfobox_args['label2'] = "From"endinfobox_args['data2'] = args.terminus_ainfobox_args['class3'] = "plainlist"infobox_args['label3'] = "<span style='display:none;'>Major intersections</span>"infobox_args['data3'] = args.junction or args.junctionslocal dir_b = args.direction_b or ''if dir_b ~= '' theninfobox_args['label4'] = dir_b .. "&nbsp;end"elseinfobox_args['label4'] = "To"endinfobox_args['data4'] = args.terminus_breturn frame:expandTemplate ({title='Infobox', args = infobox_args})elsereturn nilendendfunction p.main(frame)args = getArgs(frame)return p._main(args)endreturn p