Dantes (обсуждение | вклад) Нет описания правки |
Dantes (обсуждение | вклад) Нет описания правки |
||
| Строка 10: | Строка 10: | ||
} | } | ||
local function renderIngredients(ingredients) | -- Добавляем аргумент frame для обработки вики-разметки | ||
local function renderIngredients(ingredients, frame) | |||
local list = mw.html.create("ul"):addClass("alchemy-ingredient-list") | local list = mw.html.create("ul"):addClass("alchemy-ingredient-list") | ||
for _, item in ipairs(ingredients) do | for _, item in ipairs(ingredients) do | ||
list:tag("li"):wikitext(item) | -- Обрабатываем каждый ингредиент через frame:preprocess() | ||
list:tag("li"):wikitext(frame:preprocess(item)) | |||
end | end | ||
return tostring(list) | return tostring(list) | ||
| Строка 23: | Строка 25: | ||
args = frame:getParent().args | args = frame:getParent().args | ||
end | end | ||
local ingredients = {} | local ingredients = {} | ||
| Строка 48: | Строка 49: | ||
["display"] = "flex", | ["display"] = "flex", | ||
["flex-direction"] = "column", | ["flex-direction"] = "column", | ||
["gap"] = "10px" | ["gap"] = "10px", | ||
["word-wrap"] = "break-word" -- Добавляем перенос длинных слов | |||
}) | }) | ||
-- Результат (без изменений) | |||
card:tag("div") | card:tag("div") | ||
:addClass("alchemy-result-name") | :addClass("alchemy-result-name") | ||
| Строка 58: | Строка 61: | ||
:wikitext(result) | :wikitext(result) | ||
-- Ингредиенты с обработкой вики-разметки | |||
card:tag("div") | card:tag("div") | ||
:addClass("alchemy-ingredients") | :addClass("alchemy-ingredients") | ||
:wikitext(renderIngredients(ingredients)) | :wikitext(renderIngredients(ingredients, frame)) -- Передаем frame | ||
if recipe ~= "" then | if recipe ~= "" then | ||
| Строка 66: | Строка 70: | ||
:addClass("alchemy-recipe") | :addClass("alchemy-recipe") | ||
:css("color", darkColors.border2) | :css("color", darkColors.border2) | ||
:css("font-weight", "bold") -- Делаем текст заметнее | |||
:wikitext("Способ: " .. recipe) | :wikitext("Способ: " .. recipe) | ||
end | end | ||
if effect ~= "" then | if effect ~= "" then | ||
-- Обрабатываем эффект через frame:preprocess() | |||
local processedEffect = frame:preprocess(effect) | |||
card:tag("div") | card:tag("div") | ||
:addClass("alchemy-effect") | :addClass("alchemy-effect") | ||
:css("color", "#ccc") | :css("color", "#ccc") | ||
:wikitext( | :css("font-size", "14px") -- Опционально: регулируем размер | ||
:wikitext(processedEffect) -- Выводим обработанный текст | |||
end | end | ||
Версия от 00:02, 7 июня 2025
Для документации этого модуля может быть создана страница Модуль:AlchemyRecipe/doc
local p = {}
local darkColors = {
border = "#338833",
bg = "#101910",
border2 = "#cc7744",
bg2 = "#1a110a",
border3 = "#2277cc",
bg3 = "#0d1117"
}
-- Добавляем аргумент frame для обработки вики-разметки
local function renderIngredients(ingredients, frame)
local list = mw.html.create("ul"):addClass("alchemy-ingredient-list")
for _, item in ipairs(ingredients) do
-- Обрабатываем каждый ингредиент через frame:preprocess()
list:tag("li"):wikitext(frame:preprocess(item))
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*$") 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" -- Добавляем перенос длинных слов
})
-- Результат (без изменений)
card:tag("div")
:addClass("alchemy-result-name")
:css("color", darkColors.border)
:css("font-size", "18px")
:css("font-weight", "bold")
:wikitext(result)
-- Ингредиенты с обработкой вики-разметки
card:tag("div")
:addClass("alchemy-ingredients")
:wikitext(renderIngredients(ingredients, frame)) -- Передаем frame
if recipe ~= "" then
card:tag("div")
:addClass("alchemy-recipe")
:css("color", darkColors.border2)
:css("font-weight", "bold") -- Делаем текст заметнее
:wikitext("Способ: " .. recipe)
end
if effect ~= "" then
-- Обрабатываем эффект через frame:preprocess()
local processedEffect = frame:preprocess(effect)
card:tag("div")
:addClass("alchemy-effect")
:css("color", "#ccc")
:css("font-size", "14px") -- Опционально: регулируем размер
:wikitext(processedEffect) -- Выводим обработанный текст
end
return tostring(card)
end
return p