|
Метки: очистка ручная отмена |
| (не показано 8 промежуточных версий этого же участника) |
| Строка 1: |
Строка 1: |
| local p = {}
| |
|
| |
|
| function p.main(frame)
| |
| local args = frame:getParent().args
| |
| local name = args.name or "Без названия"
| |
| local recipe = args.recipe or ""
| |
| local effects = args.effects or "Нет описания."
| |
| local method = recipe ~= "" and "Смешайте" or "Неизвестно"
| |
|
| |
| local function formatReagents(str)
| |
| local out = {}
| |
| for reagent in mw.text.gsplit(str, ",") do
| |
| local trimmed = mw.text.trim(reagent)
| |
| local name, qty = trimmed:match("^(.-)%s*%[(%d+)%]$")
| |
| if name and qty then
| |
| table.insert(out, string.format(
| |
| '<div class="reagent-item">🧪 <span class="reagent">%s</span> <span class="qty">[%s]</span></div>',
| |
| mw.text.nowiki(name),
| |
| mw.text.nowiki(qty)
| |
| ))
| |
| else
| |
| table.insert(out, '<div class="reagent-item">' .. mw.text.nowiki(trimmed) .. '</div>')
| |
| end
| |
| end
| |
| return table.concat(out)
| |
| end
| |
|
| |
| local function collapsible(title, content)
| |
| return string.format([[
| |
| <div class="collapsible-container">
| |
| <div class="collapsible-header" onclick="this.nextElementSibling.classList.toggle('collapsed')">%s</div>
| |
| <div class="collapsible-body collapsed">%s</div>
| |
| </div>]], title, content)
| |
| end
| |
|
| |
| local html = mw.html.create("div")
| |
| html:addClass("alchemy-card")
| |
|
| |
| html:tag("div")
| |
| :addClass("alchemy-title")
| |
| :wikitext(name)
| |
|
| |
| html:tag("div")
| |
| :addClass("alchemy-section")
| |
| :wikitext(collapsible("Рецепт", formatReagents(recipe) .. '<div class="method">🔄 ' .. method .. '</div>'))
| |
|
| |
| html:tag("div")
| |
| :addClass("alchemy-section")
| |
| :wikitext(collapsible("Эффекты", effects))
| |
|
| |
| return tostring(html)
| |
| end
| |
|
| |
| return p
| |