Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш IP-адрес будет виден всем, если вы внесёте какие-либо изменения.

Модуль:Infobox: различия между версиями

Материал из YastreWiki
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
local p = {}
local p = {}


function p.youtubeChannel(frame)
local function clean(val)
     local function mainLogic(frame)
     if val == '' or val == nil then return nil end
local args = {}
    return mw.text.trim(val)
if parent then
end
    args = parent.args
else
    args = frame.args
end


        local currentTitle = mw.title.getCurrentTitle()
function p.render(frame)
        local titleText = 'Инфобокс'
    local args = frame:getParent().args
        if currentTitle then
    local title = clean(args['название']) or mw.title.getCurrentTitle().text
            titleText = currentTitle.text
    local image = clean(args['изображение'])
        end
    local caption = clean(args['подпись'])


        local function addRow(builder, label, data)
    local root = mw.html.create('table')
            local trimmedData = (data or ''):gsub("^%s*(.-)%s*$", "%1")
    root:addClass('infobox')
            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:tag('caption')
         root:addClass('infobox-youtube-channel')
         :addClass('infobox-title')
        :wikitext(title)


         local title = args['название'] or titleText
    if image then
         root:tag('caption')
         local imageRow = root:tag('tr'):addClass('infobox-image-row')
             :addClass('infobox-title')
         local imageCell = imageRow:tag('td')
             :wikitext(title)
            :attr('colspan', '2')
             :addClass('infobox-image')
              
        imageCell:wikitext(string.format('[[Файл:%s|frameless|280px]]', image))
       
        if caption then
            imageCell:tag('div')
                :addClass('infobox-caption')
                :wikitext(caption)
        end
    end


         local image = (args['изображение'] or ''):gsub("^%s*(.-)%s*$", "%1")
    local function addRow(label, data)
         if image ~= '' then
         local val = clean(data)
             root:tag('tr')
         if val then
                :addClass('infobox-image-row')
             local row = root:tag('tr'):addClass('infobox-row')
                :tag('td')
            row:tag('th')
                    :attr('colspan', 2)
                :addClass('infobox-label')
                    :addClass('infobox-image')
                :wikitext(label)
                    :wikitext('[[Файл:' .. image .. '|frameless|280px|' .. (args['подпись'] or '') .. ']]')
            row:tag('td')
                  
                 :addClass('infobox-data')
            if args['подпись'] and args['подпись']:match('%S') then
                 :wikitext(val)
                 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)
     addRow('Имя', args['имя'])
    addRow('Описание', args['описание'])
    addRow('Дата создания', args['дата создания'])
    addRow('Подписчики', args['подписчики'])
    addRow('Просмотры', args['просмотры'])
    addRow('Ссылки', args['ссылки'])


     if success then
     return tostring(root)
        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

Версия от 23:15, 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 args = frame:getParent().args
    local title = clean(args['название']) or mw.title.getCurrentTitle().text
    local image = clean(args['изображение'])
    local caption = clean(args['подпись'])

    local root = mw.html.create('table')
    root:addClass('infobox')

    root:tag('caption')
        :addClass('infobox-title')
        :wikitext(title)

    if image then
        local imageRow = root:tag('tr'):addClass('infobox-image-row')
        local imageCell = imageRow:tag('td')
            :attr('colspan', '2')
            :addClass('infobox-image')
            
        imageCell:wikitext(string.format('[[Файл:%s|frameless|280px]]', image))
        
        if caption then
            imageCell:tag('div')
                :addClass('infobox-caption')
                :wikitext(caption)
        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 tostring(root)
end

return p