Модуль:Infobox: различия между версиями
Материал из YastreWiki
Дополнительные действия
Нет описания правки |
мНет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
function p.youtubeChannel(frame) | |||
local | local function mainLogic(frame) | ||
local parent = frame:getParent() | |||
local args = {} | |||
if parent then | |||
args = parent.args | |||
end | |||
local currentTitle = mw.title.getCurrentTitle() | |||
local titleText = 'Инфобокс' | |||
if currentTitle then | |||
titleText = currentTitle.text | |||
end | |||
end | |||
function | 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 | end | ||
addRow(root, 'Имя', args['имя']) | |||
addRow(root, 'Дата создания', args['дата создания']) | |||
addRow(root, 'Подписчики', args['подписчики']) | |||
addRow(root, 'Просмотры', args['просмотры']) | |||
addRow(root, 'Ссылка', args['ссылка']) | |||
addRow(root, 'Ссылки', args['ссылки']) | |||
return tostring(root) | |||
end | end | ||
local success, result = pcall(mainLogic, frame) | |||
return tostring( | 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 | end | ||
return p | return p | ||
Версия от 16:47, 26 сентября 2025
Для документации этого модуля может быть создана страница Модуль:Infobox/doc
local p = {}
function p.youtubeChannel(frame)
local function mainLogic(frame)
local parent = frame:getParent()
local args = {}
if parent then
args = parent.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