Module:Episode list

This is an old revision of this page, as edited by The Mol Man (talk | contribs) at 15:55, 7 July 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

local getArgs
local yesno = require('Module:Yesno')
local _mod = require('Module:Math').mod()

function p.sublist(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	local args = getArgs(frame, {wrappers = 'Template:Episode list/sublist'})
	
	local on_same_page
	local page_title = tostring(mw.title.getCurrentTitle())
	local mainlist = args.MainList or args[1] or page_title
	
	on_same_page = mw.uri.anchorEncode(page_title) == mw.uri.anchorEncode(mainlist)
	
	local EpisodeNumber,EpisodeNumber2,Title,Aux1,DirectedBy,WrittenBy,DirectedBy,Aux2,Aux3,OriginalAirDate,AltDate,ProdCode,Viewers,Aux4
	
	local line_color = args.LineColor or 'CCCCFF'
	local cell_names = {
		'EpisodeNumber2',
		'Title',
		'Aux1',
		'DirectedBy',
		'WrittenBy',
		'DirectedBy',
		'Aux2',
		'Aux3',
		'OriginalAirDate',
		'AltDate',
		'ProdCode',
		'Viewers',
		'Aux4'
	}
	
	local td_tags = {
		['EpisodeNumber2'] = EpisodeNumber2,
		['Title'] = Title,
		['Aux1'] = Aux1,
		['DirectedBy'] = DirectedBy,
		['WrittenBy'] = WrittenBy,
		['DirectedBy'] = DirectedBy,
		['Aux2'] = Aux2,
		['Aux3'] = Aux3,
		['OriginalAirDate'] = OriginalAirDate,
		['AltDate'] = AltDate,
		['ProdCode'] = ProdCode,
		['Viewers'] = Viewers,
		['Aux4'] = Aux4,
	}
	
	local nonnil_params = 0
	
	local table_row = mw.html.create('tr')
				:addClass('vevent')
				:css('text-align','center')
	
	local row_color = yesno(args.RowColor, false)
	local top_color
	local epn = args.EpisodeNumber or 1
	if args.TopColor then
		top_color = '#'..args.TopColor
	elseif row_color and on_same_page and _mod(epn) == 0 then
		top_color = '#E9E9E9'
	elseif args.ShortSummary then
		top_color = '#F2F2F2'
	else
		top_color = 'inherit'
	end
		
	table_row:css('background',top_color)
	
	if args.EpisodeNumber then
		EpisodeNumber = mw.html.create('th')
				:attr('scope','row')
				:attr('id','ep'..args.EpisodeNumber)
				:css('text-align','center')
		table_row:css('background',top_color)
		table_row:node(EpisodeNumber)
	end
	
	for _,v in ipairs(cell_names) do
		if args[v] then
			nonnil_params = nonnil_params + 1
			td_tags[v] = mw.html.create('td')
					:wikitext(args[v])
			table_row:node(td_tags[v])
		end
	end
	if ProdCode and args.ProdCode then
		ProdCode:attr('id','pc'..args.ProdCode)
	end
	
	if Title and args.Title then
		local title_string = '"'..args.Title..'"'
		if args.RTitle then
			title_string = title_string..RTitle
		end
		
		if args.AltTitle then
			title_string = title_string..'"'..AltTitle..'"'
		end
		
		if args.RAltTitle then
			title_string = title_string..RAltTitle
		end
		Title:wikitext(title_string)
	end
	
	if args.ShortSummary then
		local bottom_wrapper = mw.html.create('tr')
		local ShortSummary = mw.html.create('td')
					:addClass('description')
					:css('border-bottom','solid 3px #'..line_color)
					:attr('colspan',nonnil_params)
					:wikitext(args.ShortSummary)
		bottom_wrapper:node(ShortSummary)
		return tostring(table_row)..tostring(bottom_wrapper)
	else
		return tostring(table_row)
	end
end

return p