Modulis:Basketbola izlases rezultāti

Vikipēdijas lapa
Dokumentācijas ikona Moduļa dokumentācija[izveidot]
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')

local p = {}

local floor = math.floor

----------------------------------------------------------------------------
-- Helper functions
----------------------------------------------------------------------------

function p.isInteger(v)
	if type(v) == 'number' and floor(v) == v then
		return true
	else
		return false
	end
end

function p.getArgNums(args)
	local isInteger = p.isInteger
	local nums = {}
	for k, v in pairs(args) do
		if isInteger(k) then
			nums[#nums + 1] = k
		end
	end
	table.sort(nums)
	return nums
end			

----------------------------------------------------------------------------
-- Main functions
----------------------------------------------------------------------------

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

function p._main(args)
	--[=[
	{| width=60% class="collapsible collapsed vevent" cellpadding="2" cellspacing="0" style="background:#f9f9f9; border: 1px #aaa solid; border-collapse: collapse; font-size: 90%;"
|-
!bgcolor=#75AADB colspan=6|<big>[[Basketbols Olimpiskajās spēlēs|<span style="color:white;">Olimpiskās spēles</span>]]</big>
|-
]=]
	
	local years = p.getArgNums(args)
	local gender = args.dzimums
	local dateRows = p.renderDateRows(args, years)
	local dateRowLength = #years + 1
	local root
		--[=[
	local count = 0
	
	for i, year in ipairs(years) do
		if args[year] then
			count = count+1
		end
	end

	if count>1 then
		colspan=count/10
		colspan = math.floor(colspan)
	end
	
	rowsincolumn = math.floor(count/colspan)
	]=]
	
		root = mw.html.create('table')
		root
			:css('width', '60%')
			:addClass( 'collapsible' )--:addClass( 'collapsible collapsed vevent' )
			:attr('cellpadding', '2')
			:attr('cellspacing', '0')
			:css('background', '#f9f9f9')
			:css('border', '1px #aaa solid')
			:css('border-collapse', 'collapse')
			:css('font-size', '90%')
		root:tag('th')
			:tag('td')
			:attr('colspan', '6')--neaizmirst šo salabot
			--tekstu ielikt <big>
			:wikitext('[[Basketbols Olimpiskajās spēlēs]]')
			--:wikitext('[[Basketbols Olimpiskajās spēlēs|<span style="color:white;">Olimpiskās spēles</span>]]')
			
	root:wikitext(dateRows)
	return tostring(root)
end

function p.renderDateRows(args, years, border, padding)
	local root = mw.html.create()
	for i, year in ipairs(years) do
		if args[year] then
			local drow = root:tag('tr')
				drow
					:tag('td')
						:attr('scope', 'row')
						:css('border', border)
						:css('padding', padding)
						:wikitext(year)
					:tag('td')
						:css('border', border)
						:css('padding', padding)
						:css('text-align', 'center')
						:wikitext(args[year])
		end
	end
	return tostring(root)
end

return p