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

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

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


local function addRow(builder, label, data)
function p.youtubeChannel(frame)
     local trimmedData = (data or ''):gsub("^%s*(.-)%s*$", "%1")
     local function mainLogic(frame)
        local parent = frame:getParent()
        local args = {}
        if parent then
            args = parent.args
        end


    if trimmedData ~= '' then
        local currentTitle = mw.title.getCurrentTitle()
        builder:tag('tr')
        local titleText = 'Инфобокс'
            :addClass('infobox-row')
        if currentTitle then
            :tag('th')
             titleText = currentTitle.text
                :addClass('infobox-label')
        end
                :wikitext(label)
                :done()
             :tag('td')
                :addClass('infobox-data')
                :wikitext(trimmedData)
                :done()
    end
end


function p.youtubeChannel(frame)
        local function addRow(builder, label, data)
    local parent = frame:getParent()
            local trimmedData = (data or ''):gsub("^%s*(.-)%s*$", "%1")
    local args = {}
            if trimmedData ~= '' then
    if parent then
                builder:tag('tr')
        args = parent.args
                    :addClass('infobox-row')
    end
                    :tag('th')
 
                        :addClass('infobox-label')
    local currentTitle = mw.title.getCurrentTitle()
                        :wikitext(label)
    local titleText = 'Инфобокс'
                        :done()
    if currentTitle then
                    :tag('td')
         titleText = currentTitle.text
                        :addClass('infobox-data')
    end
                        :wikitext(trimmedData)
                        :done()
            end
         end


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


    local title = args['название'] or titleText
        local title = args['название'] or titleText
    root:tag('caption')
        root:tag('caption')
        :addClass('infobox-title')
            :addClass('infobox-title')
        :wikitext(title)
            :wikitext(title)


    local image = (args['изображение'] or ''):gsub("^%s*(.-)%s*$", "%1")
        local image = (args['изображение'] or ''):gsub("^%s*(.-)%s*$", "%1")
    if image ~= '' then
        if image ~= '' then
        root:tag('tr')
            root:tag('tr')
            :addClass('infobox-image-row')
                :addClass('infobox-image-row')
            :tag('td')
                :tag('td')
                :attr('colspan', 2)
                    :attr('colspan', 2)
                :addClass('infobox-image')
                    :addClass('infobox-image')
                :wikitext('[[Файл:' .. image .. '|frameless|280px|' .. (args['подпись'] or '') .. ']]')
                    :wikitext('[[Файл:' .. image .. '|frameless|280px|' .. (args['подпись'] or '') .. ']]')
                  
                  
        if args['подпись'] and args['подпись']:match('%S') then
            if args['подпись'] and args['подпись']:match('%S') then
            root:wikitext('<div class="infobox-caption">' .. args['подпись'] .. '</div>')
                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


     addRow(root, 'Имя', args['имя'])
     local success, result = pcall(mainLogic, frame)
    addRow(root, 'Дата создания', args['дата создания'])
    addRow(root, 'Подписчики', args['подписчики'])
    addRow(root, 'Просмотры', args['просмотры'])
    addRow(root, 'Ссылка', args['ссылка'])
    addRow(root, 'Ссылки', args['ссылки'])


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