Module:Routelist row

This is an old revision of this page, as edited by Happy5214 (talk | contribs) at 12:01, 27 February 2013 (Rewriting gathering of arguments). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {
    mw = require("Module:mw"),
    lang = mw.getContentLanguage()
}

--This function determines if this is a future route, present route, or decommissioned route, and colors the row appropriately.
function p.rowcolor(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
    
    --Import parameters from template
    local established = config[1]
    local decommissioned = config[2]

    if p.lang:formatDate('Y-m-d') < established then --this is a future route
        return "|- style=\"background-color:#ffdead;\" title=\"Future route\"\n"
    elseif decommissioned ~= '' then --this is a decommissioned route
        return '|- style=\"background-color:#d3d3d3;\" title=\"Former route\"\n'
    else --this is a normal route
        return '|- \n'
    end
end

--This function determines if this is a beltway or not, and displays the termini columns appropriately.
function p.termini(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
    
    --Import parameters from template
    local beltway = config[1]
    local terminus_a = config[2]
    local terminus_b = config[3]

    --The template passes this function an empty string if {{{beltway}}} is not specified by the template user. 
    if beltway ~= '' then
        return "|colspan=2 align=center|" .. beltway
    else
       return '|' .. terminus_a .. '||' .. terminus_b
    end
end

return p