Модуль:Infobox: различия между версиями
Материал из YastreWiki
Дополнительные действия
Нет описания правки |
Нет описания правки |
||
| (не показано 8 промежуточных версий этого же участника) | |||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
function | 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) | |||
local | 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 | 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 | 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