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

Материал из Space Stories Wiki
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
local p = {}
local p = {}
local mw_text = mw.text
-- Функция для безопасного экранирования HTML
local function escape_html(text)
    return mw_text.encode(text or '', true)
end


function p.render(frame)
function p.render(frame)
local args = frame:getParent().args
    -- Безопасное получение аргументов
 
    local parent = frame:getParent()
local title = args['название'] or 'Без названия'
    local args
local recipe = {}
    if parent then
local i = 1
        args = parent.args
 
    else
while args['ингредиент' .. i] do
        args = frame.args
table.insert(recipe, args['ингредиент' .. i])
    end
i = i + 1
   
end
    -- Обработка данных с экранированием
 
    local title = args['название'] and escape_html(args['название']) or 'Без названия'
local result = args['результат'] or 'Неизвестно'
    local result = args['результат'] and escape_html(args['результат']) or 'Неизвестно'
local effects = {}
    local description = args['описание'] or 'Нет описания.' -- HTML разрешён
i = 1


while args['эффект' .. i] do
    -- Сбор ингредиентов
table.insert(effects, args['эффект' .. i])
    local recipe = {}
i = i + 1
    local i = 1
end
    while args['ингредиент' .. i] do
        table.insert(recipe, escape_html(args['ингредиент' .. i]))
        i = i + 1
    end


local description = args['описание'] or 'Нет описания.'
    -- Сбор эффектов
    local effects = {}
    i = 1
    while args['эффект' .. i] do
        table.insert(effects, escape_html(args['эффект' .. i]))
        i = i + 1
    end


local out = {}
    -- Генерация HTML
table.insert(out, '<div class="alchemy-recipe-card" style="border:1px solid #555;padding:1em;margin:1em 0;background:#1a1a1a;color:#eee;border-radius:12px;">')
    local out = {
table.insert(out, '<div style="font-size:1.5em;font-weight:bold;margin-bottom:0.5em;">' .. title .. '</div>')
        '<div class="alchemy-recipe-card" style="border:1px solid #555;padding:1em;margin:1em 0;background:#1a1a1a;color:#eee;border-radius:12px;">',
        '<div style="font-size:1.5em;font-weight:bold;margin-bottom:0.5em;">' .. title .. '</div>'
    }


-- Рецепт
    -- Секция рецепта
table.insert(out, '<div style="margin-bottom:0.5em;"><b>Рецепт</b><ul>')
    if #recipe > 0 then
for _, r in ipairs(recipe) do
        table.insert(out, '<div style="margin-bottom:0.5em;"><b>Рецепт</b><ul>')
table.insert(out, '<li>' .. r .. '</li>')
        for _, r in ipairs(recipe) do
end
            table.insert(out, '<li>' .. r .. '</li>')
table.insert(out, '<li><i>Смешайте</i></li>')
        end
table.insert(out, '<li><b>' .. result .. '</b></li>')
        table.insert(out, '<li><i>Смешайте</i></li>')
table.insert(out, '</ul></div>')
        table.insert(out, '<li><b>' .. result .. '</b></li></ul></div>')
    end


-- Эффекты
    -- Секция эффектов
if #effects > 0 then
    if #effects > 0 then
table.insert(out, '<div style="margin-bottom:0.5em;"><b>Эффекты</b><ul>')
        table.insert(out, '<div style="margin-bottom:0.5em;"><b>Эффекты</b><ul>')
for _, e in ipairs(effects) do
        for _, e in ipairs(effects) do
table.insert(out, '<li>' .. e .. '</li>')
            table.insert(out, '<li>' .. e .. '</li>')
end
        end
table.insert(out, '</ul></div>')
        table.insert(out, '</ul></div>')
end
    end


-- Описание
    -- Секция описания
table.insert(out, '<div><b>Описание</b><br>' .. description .. '</div>')
    table.insert(out, '<div><b>Описание</b><br>' .. description .. '</div>')
table.insert(out, '</div>')
    table.insert(out, '</div>')


return table.concat(out, '\n')
    return table.concat(out, '\n')
end
end


return p
return p

Версия от 17:20, 20 июня 2025

Для документации этого модуля может быть создана страница Модуль:AlchemyRecipe/doc

local p = {}
local mw_text = mw.text

-- Функция для безопасного экранирования HTML
local function escape_html(text)
    return mw_text.encode(text or '', true)
end

function p.render(frame)
    -- Безопасное получение аргументов
    local parent = frame:getParent()
    local args
    if parent then
        args = parent.args
    else
        args = frame.args
    end
    
    -- Обработка данных с экранированием
    local title = args['название'] and escape_html(args['название']) or 'Без названия'
    local result = args['результат'] and escape_html(args['результат']) or 'Неизвестно'
    local description = args['описание'] or 'Нет описания.'  -- HTML разрешён

    -- Сбор ингредиентов
    local recipe = {}
    local i = 1
    while args['ингредиент' .. i] do
        table.insert(recipe, escape_html(args['ингредиент' .. i]))
        i = i + 1
    end

    -- Сбор эффектов
    local effects = {}
    i = 1
    while args['эффект' .. i] do
        table.insert(effects, escape_html(args['эффект' .. i]))
        i = i + 1
    end

    -- Генерация HTML
    local out = {
        '<div class="alchemy-recipe-card" style="border:1px solid #555;padding:1em;margin:1em 0;background:#1a1a1a;color:#eee;border-radius:12px;">',
        '<div style="font-size:1.5em;font-weight:bold;margin-bottom:0.5em;">' .. title .. '</div>'
    }

    -- Секция рецепта
    if #recipe > 0 then
        table.insert(out, '<div style="margin-bottom:0.5em;"><b>Рецепт</b><ul>')
        for _, r in ipairs(recipe) do
            table.insert(out, '<li>' .. r .. '</li>')
        end
        table.insert(out, '<li><i>Смешайте</i></li>')
        table.insert(out, '<li><b>' .. result .. '</b></li></ul></div>')
    end

    -- Секция эффектов
    if #effects > 0 then
        table.insert(out, '<div style="margin-bottom:0.5em;"><b>Эффекты</b><ul>')
        for _, e in ipairs(effects) do
            table.insert(out, '<li>' .. e .. '</li>')
        end
        table.insert(out, '</ul></div>')
    end

    -- Секция описания
    table.insert(out, '<div><b>Описание</b><br>' .. description .. '</div>')
    table.insert(out, '</div>')

    return table.concat(out, '\n')
end

return p