Для документации этого модуля может быть создана страница Модуль:AlchemyRecipe/doc
local p = {}
local darkColors = {
border = "#338833",
bg = "#101910",
border2 = "#cc7744",
bg2 = "#1a110a",
border3 = "#2277cc",
bg3 = "#0d1117"
}
-- Рендеринг списка ингредиентов с обработкой вики-разметки
local function renderIngredients(ingredients, frame)
local list = mw.html.create("ul"):addClass("alchemy-ingredient-list")
for _, item in ipairs(ingredients) do
if item and item ~= "" then
list:tag("li"):wikitext(frame:preprocess(item))
end
end
return tostring(list)
end
function p.main(frame)
local args = frame.args
if not next(args) then
args = frame:getParent().args
end
local ingredients = {}
for k, v in pairs(args) do
if k:match("^ingredient%d*$") and v and v ~= "" then
table.insert(ingredients, v)
end
end
local result = args.result or ""
local effect = args.effect or ""
local recipe = args.recipe or ""
local card = mw.html.create("div")
:addClass("alchemy-card")
:css({
["border"] = "1px solid " .. darkColors.border,
["background-color"] = darkColors.bg,
["padding"] = "12px",
["margin"] = "8px",
["border-radius"] = "10px",
["width"] = "280px",
["box-shadow"] = "0 0 6px rgba(0,0,0,0.6)",
["display"] = "flex",
["flex-direction"] = "column",
["gap"] = "10px",
["word-wrap"] = "break-word"
})
-- Название результата
if result ~= "" then
card:tag("div")
:addClass("alchemy-result-name")
:css("color", darkColors.border)
:css("font-size", "18px")
:css("font-weight", "bold")
:css("text-align", "center")
:wikitext(frame:preprocess(result))
end
-- Ингредиенты
if #ingredients > 0 then
card:tag("div")
:addClass("alchemy-ingredients")
:wikitext(renderIngredients(ingredients, frame))
end
-- Рецепт
if recipe ~= "" then
card:tag("div")
:addClass("alchemy-recipe")
:css("color", darkColors.border2)
:css("font-weight", "bold")
:wikitext("Способ: " .. frame:preprocess(recipe))
end
-- Эффекты
if effect ~= "" then
card:tag("div")
:addClass("alchemy-effect")
:css("color", "#ccc")
:css("font-size", "14px")
:wikitext(frame:preprocess(effect))
end
return tostring(card)
end
return p