Модуль:Infobox: различия между версиями
Материал из YastreWiki
Дополнительные действия
мНет описания правки |
Нет описания правки |
||
| Строка 3: | Строка 3: | ||
function p.youtubeChannel(frame) | function p.youtubeChannel(frame) | ||
local function mainLogic(frame) | local function mainLogic(frame) | ||
local args = {} | |||
if parent then | |||
args = parent.args | |||
else | |||
args = frame.args | |||
end | |||
local currentTitle = mw.title.getCurrentTitle() | local currentTitle = mw.title.getCurrentTitle() | ||
Версия от 22:25, 12 апреля 2026
Для документации этого модуля может быть создана страница Модуль:Infobox/doc
local p = {}
function p.youtubeChannel(frame)
local function mainLogic(frame)
local args = {}
if parent then
args = parent.args
else
args = frame.args
end
local currentTitle = mw.title.getCurrentTitle()
local titleText = 'Инфобокс'
if currentTitle then
titleText = currentTitle.text
end
local function addRow(builder, label, data)
local trimmedData = (data or ''):gsub("^%s*(.-)%s*$", "%1")
if trimmedData ~= '' then
builder:tag('tr')
:addClass('infobox-row')
:tag('th')
:addClass('infobox-label')
:wikitext(label)
:done()
:tag('td')
:addClass('infobox-data')
:wikitext(trimmedData)
:done()
end
end
local root = mw.html.create('table')
root:addClass('infobox-youtube-channel')
local title = args['название'] or titleText
root:tag('caption')
:addClass('infobox-title')
:wikitext(title)
local image = (args['изображение'] or ''):gsub("^%s*(.-)%s*$", "%1")
if image ~= '' then
root:tag('tr')
:addClass('infobox-image-row')
:tag('td')
:attr('colspan', 2)
:addClass('infobox-image')
:wikitext('[[Файл:' .. image .. '|frameless|280px|' .. (args['подпись'] or '') .. ']]')
if args['подпись'] and args['подпись']:match('%S') then
root:wikitext('<div class="infobox-caption">' .. args['подпись'] .. '</div>')
end
end
addRow(root, 'Имя', args['имя'])
addRow(root, 'Дата создания', args['дата создания'])
addRow(root, 'Подписчики', args['подписчики'])
addRow(root, 'Просмотры', args['просмотры'])
addRow(root, 'Ссылка', args['ссылка'])
addRow(root, 'Ссылки', args['ссылки'])
return tostring(root)
end
local success, result = pcall(mainLogic, frame)
if success then
return result
else
return '<div class="scribunto-error" style="border: 2px solid red; padding: 1em; background-color: #fcc;"><strong>Ошибка в модуле Infobox:</strong><br><code>' .. tostring(result) .. '</code></div>'
end
end
return p