Модуль:Football box (Bk;rl,&Football box)
Перейти к навигации
Перейти к поиску
![]() | Этот шаблон реализован на основе Lua:
|
![]() | Этот модуль использует TemplateStyles и загружает следующие таблицы CSS-стилей:
|
Реализация Шаблон:Footballbox
--Реализация [[Шаблон:Footballbox]]
local fbxb = require("Модуль:Football box/base")
local p = {}
local lang = nil
local delink = require('Модуль:Delink')._delink
local templatestyles = 'Football box/styles.css'
local tracking, preview
local function checkarg(k, v, tracking, preview)
fbxb.checkarg(k, v, 'Страницы, использующие шаблон footballbox с неизвестными параметрами', tracking, preview)
end
local function timestamp(d, t)
if not d then
return nil
end
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
local function getid(s)
s = fbxb.trim(s or '')
if fbxb.isnotempty(s) then
return s
end
return nil
end
function p.main(frame)
-- Exit early if we are using section transclusion for a different section
local tsection = frame:getParent().args['transcludesection'] or frame:getParent().args['section'] or ''
local bsection = frame.args['section'] or ''
if ( tsection ~= '' and bsection ~= '') then
if ( tsection ~= bsection) then
return ''
end
end
local args = require('Модуль: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, tracking, preview)
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 .. ')'
elseif args['asdet'] then
score = score .. ' (' .. fbxb.labels.asdet .. ')'
elseif args['agget'] then
score = score .. ' (' .. fbxb.labels.agget .. ')'
elseif args['asget'] then
score = score .. ' (' .. fbxb.labels.asget .. ')'
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('fleft')
local timetag = block:tag('time')
:attr('itemprop', d and 'startDate' or nil)
:attr('datetime', d)
timetag:tag('div')
:addClass('fdate')
:wikitext(args['date'])
if args['time'] then
timetag:tag('div')
:addClass('ftime')
:wikitext(args['time'])
end
if args['round'] then
block:tag('div')
: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'):attr('scope', 'col')
:addClass('fhome')
:tag('span')
:wikitext(args['team1'])
row:tag('th'):attr('scope', 'col')
:addClass('fscore')
:wikitext(score)
row:tag('th'):attr('scope', 'col')
: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('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