Module:Cenrail: Difference between revisions

From Nguhcraft Wiki
Jump to navigation Jump to search
(first draft of table generator)
 
(add date formating)
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
local line_data = require( 'Module:Data/Cenrail/Lines' )
local line_data = require( 'Module:Data/Cenrail/Lines' )
local stop_data = require( 'Module:Data/Cenrail/Stops' )
local stop_data = require( 'Module:Data/Cenrail/Stops' )
local function formatDate (d)
tbl = {
year = tonumber(d:sub(1,4)),
month = tonumber(d:sub(6,7)),
day = tonumber(9,10)
}
return os.date("%d %B %Y", os.time(tbl))
end


_m.showline = function(frame)
_m.showline = function(frame)
Line 10: Line 19:
if not (data.is_local or data.is_minor) then
if not (data.is_local or data.is_minor) then
text = text .. "!"
text = text .. "!"
.. "rowspan=\"" .. tostring(#data.stops + (data.loop and 1 or 0)) .. "\""
.. "rowspan=\"" .. tostring(#data.stops + 1 + (data.loop and 1 or 0)) .. "\""
.. "style=\"background-color:#" .. data.color .. "\""
.. "style=\"background-color:#" .. data.color .. "\""
.. "|\n"
.. "|\n"
Line 16: Line 25:
text = text .. "!Stop\n!Code\n!Date opened\n!Notes\n"
text = text .. "!Stop\n!Code\n!Date opened\n!Notes\n"
for _, stop in ipairs(data.stops) do
for _, stop in ipairs(data.stops) do
local sdata = stop_data[stop]
local sdata = stop_data[stop] or {name=stop}
text = text .. "|-\n"
text = text .. "|-\n"
text = text .. "|" .. sdata.name .. ", " .. (sdata.country or "") .. "\n"
text = text .. "|" .. sdata.name .. (sdata.country and ", " .. sdata.country or "") .. "\n"
text = text .. "|" .. stop .. "\n"
text = text .. "|" .. stop .. "\n"
text = text .. "|" .. (sdata.date_opened or "") .. "\n"
text = text .. "|" .. (sdata.date_opened and formatDate(sdata.date_opened) or "") .. "\n"
text = text .. "|" .. (sdata.notes or "") .. "\n"
text = text .. "|" .. (sdata.notes or "") .. "\n"
end
end

Latest revision as of 15:25, 23 February 2025

Documentation for this module may be created at Module:Cenrail/doc

local _m = {}

local line_data = require( 'Module:Data/Cenrail/Lines' )
local stop_data = require( 'Module:Data/Cenrail/Stops' )

local function formatDate (d)
	tbl = {
		year = tonumber(d:sub(1,4)),
		month = tonumber(d:sub(6,7)),
		day = tonumber(9,10)
	}
	return os.date("%d %B %Y", os.time(tbl))
end

_m.showline = function(frame)
	local line = frame.args[1] or "central"
	local data = line_data[line]
	local text = "{| class=\"wikitable\"\n"
	if not (data.is_local or data.is_minor) then
		text = text .. "!"
			.. "rowspan=\"" .. tostring(#data.stops + 1 + (data.loop and 1 or 0)) .. "\""
			.. "style=\"background-color:#" .. data.color .. "\""
			.. "|\n"
	end
	text = text .. "!Stop\n!Code\n!Date opened\n!Notes\n"
	for _, stop in ipairs(data.stops) do
		local sdata = stop_data[stop] or {name=stop}
		text = text .. "|-\n"
		text = text .. "|" .. sdata.name .. (sdata.country and ", " .. sdata.country or "") .. "\n"
		text = text .. "|" .. stop .. "\n"
		text = text .. "|" .. (sdata.date_opened and formatDate(sdata.date_opened) or "") .. "\n"
		text = text .. "|" .. (sdata.notes or "") .. "\n"
	end
	if data.loop then
		text = text .. "|-\n! colspan=\"4\"| ''Line loops back to first stop''\n"
	end
	text = text .. "|}\n"
	return text
end

return _m