Jump to content

Module:Infobox road/sections

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Happy5214 (talk | contribs) at 15:08, 4 August 2013 (Created page with 'local p = {} local function terminus_a(num, args) local direction = args["direction_a" .. num] or args.direction_a or '' local label if direction ~=...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

local function terminus_a(num, args)
    local direction = args["direction_a" .. num] or args.direction_a or ''
    local label
    if direction ~= '' then
        label = direction .. " end:"
    else
        label = "From:"
    end
    local data = args["terminus_a" .. num]
    return label, data
end

local function terminus_b(num, args)
    local direction = args["direction_b" .. num] or args.direction_b or ''
    local label
    if direction ~= '' then
        label = direction .. " end:"
    else
        label = "To:"
    end
    local data = args["terminus_b" .. num]
    return label, data
end

local function _section(num, args)
    local parameters = {label1 = "Length:", label3 = "Major<br>junctions:", child = "yes", decat = "yes", labelstyle = "text-align:right", title = "Section " .. num}
    local data = {}
    
    local lengthModule = require "Module:Infobox road/length"
    data[1] = lengthModule._length(num, args)
    parameters.label2, data[2] = terminus_a(num, args)
    data[3] = args["junction" .. num]
    parameters.label4, data[4] = terminus_b(num, args)
    
    local hasData = false
    for k,v in pairs(data) do
        hasData = true
        break
    end
    if not(hasData) then
        return ''
    end
    
    for k,v in pairs(data) do
        parameters["data" .. k] = v
    end
    
    local infoboxModule = require 'Module:Infobox'
    return infoboxModule.infobox(parameters)
end

function p.section(frame)
    local pframe = frame:getParent()
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
    
    local num = config.num
    return _section(num, args)
end

return p