Module:Schedule: Difference between revisions

From Coral Island Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 19: Line 19:
while lib.isNotEmpty(args[Y .. '_group']) do
while lib.isNotEmpty(args[Y .. '_group']) do
-- initialize table
-- initialize table
local _table = mw.html.create('table'):addClass('fandom-table article-table tdc1 tdbg1')
local _table = mw.html.create('table'):addClass('fandom-table article-table schedule-table tdc1 tdbg1')
local tr = _table:tag('tr')
local tr = _table:tag('tr')
tr:tag('th'):wikitext('Time')
tr:tag('th'):wikitext('Time')
Line 28: Line 28:
if lib.isNotEmpty(args[i .. '_time']) and lib.isNotEmpty(args[i .. '_info']) then
if lib.isNotEmpty(args[i .. '_time']) and lib.isNotEmpty(args[i .. '_info']) then
local tr = _table:tag('tr')
local tr = _table:tag('tr')
local _time = lib.split(args[i .. '_' .. y .. '_time'], ':')
if args[i .. '_time']:find('[^:\d]') then
tr:tag('td'):wikitext(
tr:tag('td'):wikitext(args[i .. '_time'])
string.format('%02d',tostring(math.mod(tonumber(_time[1]),12))),
else
':',
local _time = lib.split(args[i .. '_time'], ':')
string.format('%02d', (_time[2] or '00')),
tr:tag('td'):wikitext(
' ',
string.format('%02d',tostring(math.mod(tonumber(_time[1]),12))),
lib.ternary(tonumber(_time[1])>=12, 'PM', 'AM')
':',
)
string.format('%02d', (_time[2] or '00')),
tr:tag('td'):wikitext(args[i .. '_' .. y .. '_info'])
' ',
lib.ternary(tonumber(_time[1])>=12, 'PM', 'AM')
)
end
tr:tag('td'):wikitext(args[i .. '_info'])
elseif lib.isNotEmpty(args[i .. '_cond']) then
elseif lib.isNotEmpty(args[i .. '_cond']) then
local tr = _table:tag('tr'):tag('th'):attr('colspan', '2'):wikitext(args[i .. '_cond'])
local tr = _table:tag('tr'):tag('th'):addClass('days-header'):attr('colspan', '2'):wikitext(args[i .. '_cond'])
else
else
break
break
end
end
i = Y .. '_' ..tostring(tonumber(i:gsub('^%d+_', ''))+1)
i = Y .. '_' ..tostring(tonumber((i:gsub('^%d+_', '')))+1)
end
end
tabs['label' .. Y] = args[Y .. '_group']
tabs['label' .. Y] = args[Y .. '_group']

Latest revision as of 20:07, 13 January 2024

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

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

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

	args.character = args.character or mw.title.getCurrentTitle().rootText
	
	return p._main(args)
end

function p._main(args)
	local out = mw.html.create()
	local tabs = {alwaystabs=true}
	local Y = '1'
	while lib.isNotEmpty(args[Y .. '_group']) do
		-- initialize table
		local _table = mw.html.create('table'):addClass('fandom-table article-table schedule-table tdc1 tdbg1')
		local tr = _table:tag('tr')
		tr:tag('th'):wikitext('Time')
		tr:tag('th'):wikitext('Activity')
		
		local i = Y .. '_1'
		while true do
			if lib.isNotEmpty(args[i .. '_time']) and lib.isNotEmpty(args[i .. '_info']) then
				local tr = _table:tag('tr')
				if args[i .. '_time']:find('[^:\d]') then
					tr:tag('td'):wikitext(args[i .. '_time'])
				else
					local _time = lib.split(args[i .. '_time'], ':')
					tr:tag('td'):wikitext(
						string.format('%02d',tostring(math.mod(tonumber(_time[1]),12))),
						':',
						string.format('%02d', (_time[2] or '00')),
						' ',
						lib.ternary(tonumber(_time[1])>=12, 'PM', 'AM')
					)
				end
				tr:tag('td'):wikitext(args[i .. '_info'])
			elseif lib.isNotEmpty(args[i .. '_cond']) then
				local tr = _table:tag('tr'):tag('th'):addClass('days-header'):attr('colspan', '2'):wikitext(args[i .. '_cond'])
			else
				break
			end
			i = Y .. '_' ..tostring(tonumber((i:gsub('^%d+_', '')))+1)
		end
		tabs['label' .. Y] = args[Y .. '_group']
		tabs['content' .. Y] = _table
		Y = tostring(tonumber(Y)+1)
	end
	
	if not tabs['content1'] and not args.alwaystabs then
		return 'No information about ' .. args.character .. '\'s schedule.'
	else
		return Tabber(tabs)
	end
end

return p