Mô đun:Episode table/sandbox

-- This module implements  and .
--------------------------------------------------------------------------------
-- EpisodeTable class
-- The main class.
--------------------------------------------------------------------------------
local contrast_ratio = require('Module:Color contrast')._ratio
local EpisodeTable = {}
function EpisodeTable.cell(background, width, text, reference)
	local cell = mw.html.create('th')
	
	-- Cell
	cell:attr('scope','col')
		:css('background',background or '#CCCCFF')
		:css('width',width ~=  and width .. '%' or nil)
		:wikitext(text)
	
	-- Reference
	if reference and reference ~=  then
		cell:wikitext(" " .. EpisodeTable.reference(reference, background))
	end
	
	return cell
end
function EpisodeTable.reference(reference, background)
	local link1_cr = contrast_ratio{'#0645AD', background or '#CCCCFF', 'error' = 0}
	local link2_cr = contrast_ratio{'#0B0080', background or '#CCCCFF', 'error' = 0}
	
	local refspan = mw.html.create('span')
		:wikitext(reference)
	
	if link1_cr  white_cr and 'black' or 'white')
		:wikitext("" .. displaytext .. "" .. (args.r and " " .. EpisodeTable.reference(args.r, args.c) or ))
	
	return tostring(row)
end
function EpisodeTable.new(args)
	args = args or {}
	local categories = 
	local background = (args.background and args.background ~=  and args.background ~= '#') and args.background or nil
	
	-- Default widths noted by local consensus
	local defaultwidths = {};
	defaultwidths.overall = 5;
	defaultwidths.season = 5;
	defaultwidths.series = 5;
	defaultwidths.prodcode = 7;
	defaultwidths.viewers = 10;
	
	-- Create episode table
	local root = mw.html.create('table')
	
	root
		:addClass('wikitable')
		:addClass('plainrowheaders')
		:addClass('wikiepisodetable')
		:css('width', args.total_width and string.gsub(args.total_width,'%%',) .. '%' or '100%')
	
	-- Caption
	if args.caption then
		root:tag('caption'):wikitext(args.caption)
	end
	
	-- Colour contrast; add to category only if it's in the mainspace
	local title = mw.title.getCurrentTitle()
	local black_cr = contrast_ratio{background, 'black', 'error' = 0}
	local white_cr = contrast_ratio{'white', background, 'error' = 0}
	
	if title.namespace == 0 and (args.background and args.background ~=  and args.background ~= '#') and black_cr  white_cr and 'black' or 'white') or 'black')
		:css('text-align', 'center')
	
	-- Cells
	do
		local used_season = false
		local country = args.country ~=  and args.country ~= nil
		local viewers = 'Người xem' .. ' ' .. (country and args.country or )  ..
			((not args.viewers_type or args.viewers_type ~= ) and '(' .. (args.viewers_type or 'triệu') .. ')' or )
		
		local cellNames = {
			{'overall','EpisodeNumber',EpisodeTable.abbr('STT','tập') ..
				((args.season or args.series or args.EpisodeNumber2 or args.EpisodeNumber2Series or args.forceoverall) and 'chính' or )},
			{'season','EpisodeNumber2',EpisodeTable.abbr('STT.','tập') .. ' theo mùa'},
			{'series','EpisodeNumber2Series',EpisodeTable.abbr('STT.','tập') .. ' theoseries'},
			{'title','Title','Tên tập'},
			{'aux1','Aux1',},
			{'director','DirectedBy','Đạo diễn'},
			{'writer','WrittenBy','Kịch bản'},
			{'aux2','Aux2',},
			{'aux3','Aux3',},
			{'airdate','OriginalAirDate','Ngày ' .. (args.released and 'phát hành' or 'phát sóng') .. ' gốc'},
			{'altdate','AltDate',},
			{'guests','Guests','Khách mời'},
			{'prodcode','ProdCode',EpisodeTable.abbr('Mã','Production') .. 'sản xuất'},
			{'viewers','Viewers',viewers},
			{'aux4','Aux4',}
		}
	
		for k,v in pairs(cellNames) do
			local thisCell = argsv1 or argsv2
			if thisCell and (v1 ~= 'series' or (v1 == 'series' and used_season == false)) then
				if v1 == 'season' then used_season = true end
				if (k ", "") or tostring(root)) .. categories
end
--------------------------------------------------------------------------------
-- Exports
--------------------------------------------------------------------------------
local p = {}
function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		removeBlanks = false,
		wrappers = 'Template:Episode table'
	})
	return EpisodeTable.new(args)
end
function p.part(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		removeBlanks = false,
		wrappers = 'Template:Episode table/part'
	})
	return EpisodeTable.part(frame,args)
end
function p.ref(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		removeBlanks = false,
	})
	return EpisodeTable.reference(args.r,args.b)
end
return p