Для документации этого модуля может быть создана страница Модуль:AlchemyRecipe/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
-- Обработка параметров
local name = mw.text.killMarkers(args.name or "Без названия")
local recipe = args.recipe or ""
local effects = frame:preprocess(args.effects or "Нет описания.")
local method = (recipe ~= "" and "Смешайте") or "Неизвестно"
-- Функция для форматирования реагентов с чекбоксами
local function formatReagents(input)
if input == "" then return "" end
local result = {}
local count = 0
-- Обрабатываем каждый элемент рецепта
for item in mw.text.gsplit(input, ",") do
local trimmed = mw.text.trim(item)
if trimmed ~= "" then
count = count + 1
local stepHtml = string.format(
'<div class="recipe-step">'..
'<input type="checkbox" id="step%d" disabled>'..
'<label for="step%d">%s</label></div>',
count, count, mw.text.nowiki(trimmed)
)
table.insert(result, stepHtml)
end
end
-- Добавляем шаг смешивания
if count > 0 then
local mixHtml = string.format(
'<div class="recipe-step">'..
'<input type="checkbox" id="step-mix" disabled checked>'..
'<label for="step-mix">%s</label></div>',
method
)
table.insert(result, mixHtml)
end
return table.concat(result)
end
-- Генерация HTML
local html = {
'<div class="alchemy-card dark-theme">',
'<h1 class="alchemy-title">' .. name .. '</h1>',
'<div class="alchemy-section">',
'<div class="section-header" onclick="toggleAlchemySection(this)">',
'<span class="section-title">Рецепты</span>',
'<span class="collapse-toggle">[свернуть]</span>',
'</div>',
'<div class="section-content">',
formatReagents(recipe),
'</div>',
'</div>',
'<hr class="alchemy-divider">',
'<div class="alchemy-section">',
'<div class="section-header" onclick="toggleAlchemySection(this)">',
'<span class="section-title">Эффекты</span>',
'<span class="collapse-toggle">[свернуть]</span>',
'</div>',
'<div class="section-content">',
effects,
'</div>',
'</div>',
'</div>' -- закрываем alchemy-card
}
return table.concat(html)
end
return p