Module:Cenrail

From Nguhcraft Wiki
Revision as of 14:47, 23 February 2025 by Annwan (talk | contribs) (first draft of table generator)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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' )

_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 + (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]
		text = text .. "|-\n"
		text = text .. "|" .. sdata.name .. ", " .. (sdata.country or "") .. "\n"
		text = text .. "|" .. stop .. "\n"
		text = text .. "|" .. (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