Dantes (обсуждение | вклад) Нет описания правки |
Dantes (обсуждение | вклад) Нет описания правки |
||
| Строка 2: | Строка 2: | ||
function p.main(frame) | 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 = {} | |||
-- Регулярка для обработки элементов вида "Название [10]" | |||
for item, qty in mw.ustring.gmatch(input, "([^%[%],]-)%s*%[(%d+)%]%s*,?") do | |||
item = mw.text.trim(item) | |||
if item ~= "" then | |||
table.insert(result, string.format( | |||
'<div class="reagent-item">🧪 <span class="reagent">%s</span> <span class="qty">[%s]</span></div>', | |||
mw.text.nowiki(item), qty | |||
)) | |||
end | |||
end | |||
return table.concat(result) | |||
end | |||
-- Современное сворачивание без JavaScript | |||
local function makeCollapsible(title, body) | |||
return string.format([[ | |||
<details class="alchemy-collapsible"> | |||
<summary>%s</summary> | |||
<div class="alchemy-collapsible-content">%s</div> | |||
</details>]], title, body) | |||
end | |||
-- Сборка HTML-карточки | |||
local html = { | |||
<div class=" | '<div class="alchemy-card">', | ||
'<div class="alchemy-title">' .. name .. '</div>', | |||
'<div class="alchemy-section">', | |||
</div> | makeCollapsible("Рецепт", formatReagents(recipe) .. '<div class="method">🔄 ' .. method .. '</div>'), | ||
'</div>', | |||
'<div class="alchemy-section">', | |||
makeCollapsible("Эффекты", effects), | |||
'</div>', | |||
'</div>' | |||
} | |||
return table.concat(html) | |||
end | |||
return p | return p | ||
Версия от 10:55, 22 июня 2025
Для документации этого модуля может быть создана страница Модуль: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 = {}
-- Регулярка для обработки элементов вида "Название [10]"
for item, qty in mw.ustring.gmatch(input, "([^%[%],]-)%s*%[(%d+)%]%s*,?") do
item = mw.text.trim(item)
if item ~= "" then
table.insert(result, string.format(
'<div class="reagent-item">🧪 <span class="reagent">%s</span> <span class="qty">[%s]</span></div>',
mw.text.nowiki(item), qty
))
end
end
return table.concat(result)
end
-- Современное сворачивание без JavaScript
local function makeCollapsible(title, body)
return string.format([[
<details class="alchemy-collapsible">
<summary>%s</summary>
<div class="alchemy-collapsible-content">%s</div>
</details>]], title, body)
end
-- Сборка HTML-карточки
local html = {
'<div class="alchemy-card">',
'<div class="alchemy-title">' .. name .. '</div>',
'<div class="alchemy-section">',
makeCollapsible("Рецепт", formatReagents(recipe) .. '<div class="method">🔄 ' .. method .. '</div>'),
'</div>',
'<div class="alchemy-section">',
makeCollapsible("Эффекты", effects),
'</div>',
'</div>'
}
return table.concat(html)
end
return p