Hopp til innhold

Modul:Episode list

Fra Wikipedia, den frie encyklopedi
Sideversjon per 7. jul. 2014 kl. 17:41 av The Mol Man (diskusjon | bidrag) (Created page with 'local p = {} local getArgs local yesno = require('Module:Yesno') local _mod = require('Module:Math').mod() function p.sublist(frame) if not getArgs then get...')
(diff) ← Eldre sideversjon | Nåværende sideversjon (diff) | Nyere sideversjon → (diff)
Moduldokumentasjon

Usage

Creates a standard Episode list with

{{#invoke:Episode list|list}}

or a sublist (which removes summaries on the main list when specified) with

{{#invoke:Episode list|sublist}}

Tracking/maintenance category

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 = mw.title.getCurrentTitle()
	local mainlist = args.MainList or args[1] or page_title
	
	on_same_page = page_title:anchorencode() == mainlist:anchorencode()
	
	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 = mw.html.create('td')
					:wikitext(args[v])
			table_row:node(v)
		end
	end
	if args.ProdCode then
		ProdCode:attr('id','pc'..args.ProdCode)
	end
	
	if 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)
		table_row:node(ShortSummary)
	end
				
	return tostring(table_row)
end

return p