Module:Routelist row: Difference between revisions

Content deleted Content added
Rewriting gathering of arguments
Refactoring route states; adding function for "Removed" column
Line 1:
local p = { }
local lang = mw.getContentLanguage()
mw = require("Module:mw"),
 
lang = mw.getContentLanguage()
local routeStates = { }
}
routeStates.current = {row = "|- \n", removed = "present"}
routeStates.future = {row return= "|- style=\"background-color:#ffdead;\" title=\"Future route\"\n", removed = "proposed"}
routeStates.former = {row = return '"|- style=\"background-color:#d3d3d3;\" title=\"Former route\"\n'"}
 
function getRouteState(args)
local established = args.established
elseiflocal decommissioned ~= '' then --this is a args.decommissioned route
if decommissioned ~= '' then
return '|- \n'routeStates.former
ifelseif p.lang:formatDate('"Y-m-d'") < established then --this is a future route
return routeStates.future
endelse
return routeStates.current
end
end
 
--This function determines if this is a future route, present route, or decommissioned route, and colors the row appropriately.
Line 13 ⟶ 28:
local established = config[1]
local decommissioned = config[2]
local dates = {["established"] = established, ["decommissioned"] = decommissioned}
local routeState = getRouteState(dates)
 
return routeState.row
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
 
Line 40 ⟶ 52:
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