Модуль:Infobox: различия между версиями
Материал из YastreWiki
Дополнительные действия
мНет описания правки |
мНет описания правки |
||
| Строка 11: | Строка 11: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local title = clean(args['название']) or mw.title.getCurrentTitle().text | local title = clean(args['название']) or mw.title.getCurrentTitle().text | ||
local imageParam = clean(args['изображение']) | local imageParam = clean(args['изображение']) | ||
local | local captionParam = clean(args['подпись']) | ||
local root = mw.html.create('table') | local root = mw.html.create('table') | ||
| Строка 27: | Строка 27: | ||
:addClass('infobox-image') | :addClass('infobox-image') | ||
local images = mw.text.split(imageParam, '%s*,%s*') | 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 | for i, imgName in ipairs(images) do | ||
local trimmedImg = mw.text.trim(imgName) | local trimmedImg = mw.text.trim(imgName) | ||
if trimmedImg ~= '' then | if trimmedImg ~= '' then | ||
imageCell:tag('div') | local wrapper = imageCell:tag('div') | ||
:addClass('infobox-image-wrapper') | :addClass('infobox-image-wrapper') | ||
:wikitext(string.format('[[Файл:%s | :css('margin-bottom', '10px') | ||
wrapper:tag('div') | |||
:wikitext(string.format('[[Файл:%s|280px]]', trimmedImg)) | |||
local currentCaption = clean(captions[i]) | |||
if currentCaption then | |||
wrapper:tag('div') | |||
:addClass('infobox-caption') | |||
:css('color', '#b0b0b0') | |||
:css('font-size', '90%') | |||
:css('margin-top', '2px') | |||
:wikitext(currentCaption) | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
Версия от 23:55, 12 апреля 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')
:css('margin-bottom', '10px')
wrapper:tag('div')
:wikitext(string.format('[[Файл:%s|280px]]', trimmedImg))
local currentCaption = clean(captions[i])
if currentCaption then
wrapper:tag('div')
:addClass('infobox-caption')
:css('color', '#b0b0b0')
:css('font-size', '90%')
:css('margin-top', '2px')
: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['ссылки'])
return styles .. tostring(root)
end
return p