Модуль:Infobox: различия между версиями
Материал из YastreWiki
Дополнительные действия
Новая страница: «local p = {} local function addRow(builder, label, data) local trimmedData = (data or ''):gsub("^%s*(.-)%s*$", "%1") function p.youtubeChannel(frame) local args = frame:getParent().args if trimmedData ~= '' then builder:tag('tr') :addClass('infobox-row') :tag('th') :addClass('infobox-label') :wikitext(label) :done() :tag('td') :addClass...» |
Нет описания правки |
||
| (не показано 11 промежуточных версий этого же участника) | |||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
local function | local function clean(val) | ||
local | if val == '' or val == nil then return nil end | ||
return mw.text.trim(val) | |||
end | |||
function p.render(frame) | |||
local styles = frame:extensionTag('templatestyles', '', { src = 'Шаблон:Инфобокс/styles.css' }) | |||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local title = clean(args['название']) or mw.title.getCurrentTitle().text | |||
local imageParam = clean(args['изображение']) | |||
local captionParam = clean(args['подпись']) | |||
local root = mw.html.create('table') | local root = mw.html.create('table') | ||
root:addClass('infobox | root:addClass('infobox') | ||
root:tag('caption') | root:tag('caption') | ||
:addClass('infobox-title') | :addClass('infobox-title') | ||
:wikitext(title) | :wikitext(title) | ||
if imageParam then | |||
if | local imageRow = root:tag('tr'):addClass('infobox-image-row') | ||
root:tag('tr') | local imageCell = imageRow:tag('td') | ||
:attr('colspan', '2') | |||
:addClass('infobox-image') | |||
local images = mw.text.split(imageParam, '%s*;%s*') | |||
local captions = {} | |||
if captionParam then | |||
captions = mw.text.split(captionParam, '%s*;%s*') | |||
end | |||
for i, imgName in ipairs(images) do | |||
local trimmedImg = mw.text.trim(imgName) | |||
if trimmedImg ~= '' then | |||
local wrapper = imageCell:tag('div') | |||
:addClass('infobox-image-wrapper') | |||
wrapper:tag('div') | |||
root: | :wikitext(string.format('[[Файл:%s|150px]]', trimmedImg)) | ||
local currentCaption = clean(captions[i]) | |||
if currentCaption then | |||
wrapper:tag('div') | |||
:addClass('infobox-caption') | |||
:wikitext(currentCaption) | |||
end | |||
end | |||
end | |||
end | |||
local function addRow(label, data) | |||
local val = clean(data) | |||
if val then | |||
local row = root:tag('tr'):addClass('infobox-row') | |||
row:tag('th') | |||
:addClass('infobox-label') | |||
:wikitext(label) | |||
row:tag('td') | |||
:addClass('infobox-data') | |||
:wikitext(val) | |||
end | end | ||
end | end | ||
addRow( | addRow('Настоящее имя', args['имя']) | ||
addRow( | addRow('Описание', args['описание']) | ||
addRow( | addRow('Статус', args['статус']) | ||
addRow( | |||
addRow( | addRow('Дата создания', args['дата создания']) | ||
addRow( | addRow('Подписчики', args['подписчики']) | ||
addRow('Просмотры', args['просмотры']) | |||
addRow('Ссылки', args['ссылки']) | |||
return tostring(root) | return styles .. tostring(root) | ||
end | end | ||
return p | return p | ||
Текущая версия от 00:29, 13 апреля 2026
Для документации этого модуля может быть создана страница Модуль:Infobox/doc
local p = {}
local function clean(val)
if val == '' or val == nil then return nil end
return mw.text.trim(val)
end
function p.render(frame)
local styles = frame:extensionTag('templatestyles', '', { src = 'Шаблон:Инфобокс/styles.css' })
local args = frame:getParent().args
local title = clean(args['название']) or mw.title.getCurrentTitle().text
local imageParam = clean(args['изображение'])
local captionParam = clean(args['подпись'])
local root = mw.html.create('table')
root:addClass('infobox')
root:tag('caption')
:addClass('infobox-title')
:wikitext(title)
if imageParam then
local imageRow = root:tag('tr'):addClass('infobox-image-row')
local imageCell = imageRow:tag('td')
:attr('colspan', '2')
:addClass('infobox-image')
local images = mw.text.split(imageParam, '%s*;%s*')
local captions = {}
if captionParam then
captions = mw.text.split(captionParam, '%s*;%s*')
end
for i, imgName in ipairs(images) do
local trimmedImg = mw.text.trim(imgName)
if trimmedImg ~= '' then
local wrapper = imageCell:tag('div')
:addClass('infobox-image-wrapper')
wrapper:tag('div')
:wikitext(string.format('[[Файл:%s|150px]]', trimmedImg))
local currentCaption = clean(captions[i])
if currentCaption then
wrapper:tag('div')
:addClass('infobox-caption')
:wikitext(currentCaption)
end
end
end
end
local function addRow(label, data)
local val = clean(data)
if val then
local row = root:tag('tr'):addClass('infobox-row')
row:tag('th')
:addClass('infobox-label')
:wikitext(label)
row:tag('td')
:addClass('infobox-data')
:wikitext(val)
end
end
addRow('Настоящее имя', args['имя'])
addRow('Описание', args['описание'])
addRow('Статус', args['статус'])
addRow('Дата создания', args['дата создания'])
addRow('Подписчики', args['подписчики'])
addRow('Просмотры', args['просмотры'])
addRow('Ссылки', args['ссылки'])
return styles .. tostring(root)
end
return p