Module:Schedule

From Sun Haven Wiki
Jump to navigation Jump to search

Used in the {{Schedule}} template.

Subpages

local p = {}
local lib = require('Module:Feature')

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = { 'Template:Schedule' }
	})

	args.character = args.character or mw.title.getCurrentTitle().rootText
	
	local result = p._main(args)
	if result == nil then
		return 'No information about ' .. args.character .. '\'s schedule.'
	end
	
	return frame:extensionTag('tabber', result)
end

function p._main(args)
	local out = mw.html.create()
	local tabs = {}
	local i = '1'

	while lib.isNotEmpty(args[i .. '_name']) and lib.isNotEmpty(args[i .. '_1_time']) and lib.isNotEmpty(args[i .. '_1_info']) do
		local _table = mw.html.create('table'):addClass('article-table tablemedium')
		if i == '1' and lib.isEmpty(args['2_name']) then _table:tag('caption'):wikitext(args[i .. '_name']) end
		--header
		local tr = _table:tag('tr')
		tr:tag('th'):wikitext('Time'):addClass('thsmall')
		tr:tag('th'):wikitext('Activity')
		
		
		local y = '1'
		while lib.isNotEmpty(args[i .. '_' .. y .. '_time']) and lib.isNotEmpty(args[i .. '_' .. y .. '_info']) do
			local tr = _table:tag('tr')
			local _time = lib.split(args[i .. '_' .. y .. '_time'], ':')
			tr:tag('td'):wikitext(string.format('%02d', _time[1]),':', string.format('%02d', (_time[2] or '00')))
			tr:tag('td'):wikitext(args[i .. '_' .. y .. '_info'])
			y = tostring(tonumber(y)+1)
		end
		
		-- Add to the tabber
		out:newline()
		out:wikitext(args[i.. '_name'] .. '=')
		out:newline()
		out:wikitext(tostring(_table))
		out:newline()
		out:wikitext('|-|')
		
		-- Store the names so we know if any content exists
		tabs['label' .. i] = args[i .. '_name']
		
		i = tostring(tonumber(i)+1)
	end
	
	if not tabs['label1'] then
		return nil
	end
	
	return tostring(out)
end

return p