Jump to content

Module:Sandbox/CAS222222221

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 風中的刀劍 (talk | contribs) at 03:40, 6 January 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

require('Module:No globals')

local getArgs = require('Module:Arguments').getArgs
local p = {}

local function won (frame, args, i)
	local cont = args['won' .. i] or 0
	return frame:expandTemplate{ title = 'won', args = { cont } }
end

local function nom(frame, args, i)
	local cont = args['nom' .. i] or 0
	return frame:expandTemplate{ title = 'nom', args = { cont } }
end

local function core(frame, args, i)
	if args['award' .. i] == nil then return end
	
	local ret

	ret =
		'|- style="background-color: #ddddff;"' .. '\n' ..
		'| style="text-align: center; font-weight: bold;" | ' .. args['award' .. i] .. '\n' ..
		'|' .. won(frame, args, i) .. '\n' ..
		'|' .. nom(frame, args, i) .. '\n'
		
	return ret
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	-- Main module code goes here.
	
	local ret, temp = '', ''
	local winTotal, nomTotal = 0, 0

	ret =
		'{| class="infobox" style="width: 20em; text-align: left; font-size: 90%; vertical-align: middle;"\n' ..
		'|+ style="font-size: 9pt; font-weight: bold;" | List of accolades received by <i>' .. (args[title] or '<span class="error">The parameter <code>title</code> is needed</span>') .. '</i>\n'
		
	if args.image then
		ret = ret .. '|-\n'
		ret = ret .. '|' .. require('Module:InfoboxImage').InfoboxImage{ args = { 	image = args.image, sizedefault = 'frameless', upright = '1.15', } }
		ret = ret .. args.capiton and ('<br />' .. args.caption) or ''
		ret = ret .. '\n'
	end
	
	for i = 1, 99 do
		local t = core(frame, args, i)
		if t then
			temp = temp .. t
			winTotal = winTotal + tonumber(args['won' .. i])
			nomTotal = nomTotal + tonumber(args['nom' .. i])
		end
	end
	
	if temp ~= '' then
		ret = ret .. '|-\n' ..
			'{| colspan="3"\n' ..
			'{| class="collapsible collapsed" style="width: 100%;"\n' ..
			'! colspan=3 style="background-color: #D9E8FF; text-align: center;" | Accolades\n' ..
			temp ..
			'|}\n'
	end
	
	if totals ~= 'no' then
		ret = ret ..
			'|-style="background:#d9e8ff;"\n' ..
			'| style="text-align:center;" colspan="3"| <b>Total number of awards and nominations</b>\n' ..
			'|-\n' ..
			'|' .. frame:expandTemplate{ title = 'won', args = { '<b>Totals</b>' } } .. '\n' ..
			'|' .. frame:expandTemplate{ title = 'won', args = { '<b>' .. (args.totalwin or winTotal) .. '</b>' } } .. '\n' ..
			'|' .. frame:expandTemplate{ title = 'nom', args = { '<b>' .. (args.totalnom or totalnom) .. '</b>' } } .. '\n'
	end
		
	if refsect ~= 'no' then
		ret = ret ..
			'|- style="background:#d9e8ff;"\n' ..
			'| colspan="3" style="font-size: smaller; text-align:center;"| [[#References|Footnotes]]'
	end
	
	return ret
	
end

return p