Модуль:Football box: различия между версиями

Материал из Тептар — свободной энциклопедии
Перейти к навигации Перейти к поиску
(Новая страница: «-- Модуль для шаблона Шаблон:Footballbox local fbxb = require("Module:Football box/base") local p = {} local lang = nil local delink = require('Module:Delink')._delink local templatestyles = 'Football box/styles.css' local tracking, preview local function checkarg(k,v) fbxb.checkarg(k, v, 'Страницы, использующие шаблон footballbox с неизвестными параметрами', tracking, preview)...»)
(нет различий)

Версия от 19:37, 17 февраля 2022

Реализация Шаблон:Football box


-- Модуль для шаблона [[Шаблон:Footballbox]]
local fbxb = require("Module:Football box/base")


local p = {}
local lang = nil
local delink = require('Module:Delink')._delink
local templatestyles = 'Football box/styles.css'

local tracking, preview

local function checkarg(k,v)
	fbxb.checkarg(k, v, 'Страницы, использующие шаблон footballbox с неизвестными параметрами', tracking, preview)
end

local function timestamp(d, t)
	if d then
		lang = lang or mw.language.getContentLanguage() -- lazy initialize
		local success, timestamp = pcall(lang.formatDate, lang, 'c', delink({d .. ' ' .. (t or '')}))
		if success then
			return timestamp
		else
			return nil
		end
	end
	return nil
end

local function getid(s)
	s = fbxb.trim(s or '')
	if fbxb.isnotempty(s) then
		return s
	end
	return nil
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local id = getid(args['id'])
	local d = timestamp(args['date'], args['time'])
	local block

	tracking, preview = {}, {}
	fbxb.process_rus_params(args)
	for k, v in pairs(args) do
		if v ~= '' then
			checkarg(k,v)
		end
	end

	local score = '–:–'
	if args['score1'] or args['score2'] then
		score = (args['score1'] or '0') .. ':' .. (args['score2'] or '0')
	elseif fbxb.isnotempty(args['score']) then
		score = args['score']
	end
	if args['aet'] then
		score = score .. ' (' .. fbxb.labels.aet .. ')'
	end
	if args['scorenote'] then
		score = score .. '<br>' .. args['scorenote']
	end

	-- Start box
	local root = 
		mw.html.create('div')
			:addClass('footballbox')
			:css('width', args['size'])
			:css('background-color', args['bg'])
			:attr('id', id)
	root:newline()
	
	if args['event'] then
		root:tag('div')
			:addClass('ftitle')
			:wikitext(args['event'])
	end

	-- Start left block
	block = root:tag('div')
		:addClass('mobile-float-reset')
		:addClass('fleft')
	
	local timetag = block:tag('time')
		:attr('itemprop', d and 'startDate' or nil)
		:attr('datetime', d)
		
	timetag:tag('div')
		:addClass('mobile-float-reset')
		:addClass('fdate')
		:wikitext(args['date'])
	
	if args['time'] then
		timetag:tag('div')
			:addClass('mobile-float-reset')
			:addClass('ftime')
			:wikitext(args['time'])
	end
	
	if args['round'] then
		block:tag('div')
			:addClass('mobile-float-reset')
			:addClass('frnd')
			:wikitext(args['round'])
	end
	-- End block

	-- Start table
	local rtable = root:tag('table')
		:addClass('fevent')
	local row = rtable:tag('tr')
	row:newline()
	row:tag('th')
		:addClass('fhome')
		:tag('span')
			:wikitext(args['team1'])
	row:tag('th')
		:addClass('fscore')
		:wikitext(score)
	row:tag('th')
		:addClass('faway')
		:tag('span')
			:wikitext(args['team2'])

	row = rtable:tag('tr')
		:addClass('fgoals')
		:newline()
	row:tag('td')
		:addClass('fhgoal')
		:wikitext(fbxb.fmtlist(args['goals1']))
	row:newline()
	row:tag('td')
		:wikitext(fbxb.makelink(args['report'] or '', '(отчёт)'))
	row:newline()
	row:tag('td')
		:addClass('fagoal')
		:wikitext(fbxb.fmtlist(args['goals2']))
	row:newline()

	if args['penaltyscore'] then
		rtable
			:tag('tr')
				:tag('th')
					:attr('colspan', 3)
					:wikitext(fbxb.labels.penalties)
		row = rtable:tag('tr')
			:addClass('fgoals')
		row:newline()
		row:tag('td')
			:addClass('fhgoal')
			:wikitext(fbxb.fmtlist(args['penalties1']))
		row:newline()
		row:tag('th')
			:wikitext(args['penaltyscore'])
		row:newline()
		row:tag('td')
			:addClass('fagoal')
			:wikitext(fbxb.fmtlist(args['penalties2']))
		row:newline()
	end
	-- End table

	-- Start right block
	block = root:tag('div')
		:addClass('mobile-float-reset')
		:addClass('fright')

	if args['stadium'] then
		local sdiv = block:tag('div')
		if args['location'] then
			sdiv:tag('span')
				:wikitext(args['stadium'])
			sdiv:wikitext(', ')
			sdiv:tag('span')
				:wikitext(args['location'])
		else
			sdiv:tag('span')
				:wikitext(args['stadium'])
		end
	end

	if args['attendance'] then
		block:tag('div'):wikitext(fbxb.labels.attendance ..' ' .. args['attendance'])
	end
	if args['referee'] then
		block:tag('div'):wikitext(fbxb.labels.referee .. ' ' .. args['referee'])
	end

	local squads = {}

	if fbxb.isnotempty(args['squad1']) then
		table.insert(squads, fbxb.bold(fbxb.check_team_pattern(args['team1'])) .. ": " .. args['squad1'])
	end
	if fbxb.isnotempty(args['squad2']) then
		table.insert(squads, fbxb.bold(fbxb.check_team_pattern(args['team2'])) .. ": " .. args['squad2'])
	end

	if #squads > 0 then
		local squad_table = root:tag('table')
			:css('float', 'left') 
			:css('width', '100%') 
			:css('table-layout', 'fixed') 
			:css('text-align', 'left')
			:css('vertical-align', 'bottom')
			:css('font-size', '85%')
		squad_table:tag('tr'):tag('td')
			:wikitext(table.concat(squads, '<br>'))
	end

	local trackstr = (#tracking > 0) and table.concat(tracking, '') or ''
	if #preview > 0 and frame:preprocess( "{{REVISIONID}}" ) == "" then
		trackstr = tostring(mw.html.create('div')
			:addClass('hatnote')
			:css('color','red')
			:tag('strong'):wikitext('Внимание:'):done()
			:wikitext('Неизвестные параметры: ' .. table.concat(preview, '; ')))
	end
	
	return frame:extensionTag{ name = 'templatestyles', args = { src = templatestyles} } .. tostring(root) .. trackstr
end

return p