Module:Routelist row

This is an old revision of this page, as edited by Happy5214 (talk | contribs) at 13:02, 27 February 2013 (Refactoring route states; adding function for "Removed" column). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = { }
local lang = mw.getContentLanguage()

local routeStates = { }
routeStates.current = {row = "|- \n", removed = "present"}
routeStates.future = {row = "|- style=\"background-color:#ffdead;\" title=\"Future route\"\n", removed = "proposed"}
routeStates.former = {row = "|- style=\"background-color:#d3d3d3;\" title=\"Former route\"\n"}

function getRouteState(args)
    local established = args.established
    local decommissioned = args.decommissioned
    if decommissioned ~= '' then
        return routeStates.former
    elseif lang:formatDate("Y-m-d") < established then
        return routeStates.future
    else
        return routeStates.current
    end
end

--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]
    
    local dates = {["established"] = established, ["decommissioned"] = decommissioned}
    local routeState = getRouteState(dates)

    return routeState.row
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

--This function determines the proper value for the removed column, and then displays it.
function p.removed(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]
    
    local dates = {["established"] = established, ["decommissioned"] = decommissioned}
    local routeState = getRouteState(dates)
    return routeState.removed or lang:formatDate('Y', decommissioned)
end

return p