Dantes (обсуждение | вклад) Нет описания правки |
Dantes (обсуждение | вклад) Нет описания правки |
||
| Строка 36: | Строка 36: | ||
local effectsDesc = recipe["ОписаниеЭффектов"] or "" | local effectsDesc = recipe["ОписаниеЭффектов"] or "" | ||
local borderColor = recipe["ЦветРамки"] or "#444" | local borderColor = recipe["ЦветРамки"] or "#444" | ||
local backgroundColor = recipe["ЦветФона"] or "# | local backgroundColor = recipe["ЦветФона"] or "#1a1a1a" | ||
local html = {} | local html = {} | ||
table.insert(html, '<div class="alchemy-card" style="border: 2px solid ' .. borderColor .. '; padding: 0.5em 1em; border-radius: 8px; background: ' .. backgroundColor .. '; box-sizing: border-box; width: 23%; margin: 0.5% | table.insert(html, '<div class="alchemy-card" style="border: 2px solid ' .. borderColor .. '; padding: 0.5em 1em; border-radius: 8px; background: ' .. backgroundColor .. '; box-sizing: border-box; width: 23%; margin: 0.5%;">') | ||
table.insert(html, '<h3 style="margin-top:0; text-align:center; font-size:1.1em; color:# | table.insert(html, '<h3 style="margin-top:0; text-align:center; font-size:1.1em; color:#ddd;">' .. mw.text.encode(title) .. '</h3>') | ||
-- Блок рецепта | -- Блок рецепта | ||
table.insert(html, '<div class="mw-collapsible mw-collapsed" style="margin-bottom:0.5em;">') | table.insert(html, '<div class="mw-collapsible mw-collapsed" style="margin-bottom:0.5em;">') | ||
table.insert(html, '<div class="mw-collapsible-toggle" style=" | table.insert(html, '<div class="mw-collapsible-toggle" style="color:#bbb;">Рецепт (нажмите для раскрытия)</div>') | ||
table.insert(html, '<div class="mw-collapsible-content">') | table.insert(html, '<div class="mw-collapsible-content">') | ||
table.insert(html, '<div style="display: flex; text-align: center; align-items: stretch; font-size:0.9em;">') | table.insert(html, '<div style="display: flex; text-align: center; align-items: stretch; font-size:0.9em;">') | ||
table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid # | table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid #555; padding-right: 0.5em; color:#ccc;">') | ||
table.insert(html, listBlock(ingredients)) | table.insert(html, listBlock(ingredients)) | ||
table.insert(html, '</div>') | table.insert(html, '</div>') | ||
table.insert(html, '<div style="flex: 0 0 80px; display: flex; align-items: center; justify-content: center; font-weight:bold; font-size: 0.95em; color:# | table.insert(html, '<div style="flex: 0 0 80px; display: flex; align-items: center; justify-content: center; font-weight:bold; font-size: 0.95em; color:#aaa;">СМЕШАТЬ</div>') | ||
table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-left: 1px solid # | table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-left: 1px solid #555; padding-left: 0.5em; color:#ccc;">') | ||
table.insert(html, listBlock(result)) | table.insert(html, listBlock(result)) | ||
table.insert(html, '</div>') | table.insert(html, '</div>') | ||
| Строка 63: | Строка 63: | ||
table.insert(html, '</div>') -- block | table.insert(html, '</div>') -- block | ||
-- Блок эффектов | -- Блок эффектов | ||
if effects ~= "" then | if effects ~= "" then | ||
table.insert(html, '<div class="mw-collapsible mw-collapsed" style="margin-top:0.5em;">') | table.insert(html, '<div class="mw-collapsible mw-collapsed" style="margin-top:0.5em;">') | ||
table.insert(html, '<div class="mw-collapsible-toggle" style=" | table.insert(html, '<div class="mw-collapsible-toggle" style="color:#bbb;">Эффекты (нажмите для раскрытия)</div>') | ||
table.insert(html, '<div class="mw-collapsible-content">') | table.insert(html, '<div class="mw-collapsible-content">') | ||
table.insert(html, '<ul style="margin: 0.3em 0 0.5em 1.2em; padding: 0;">') | table.insert(html, '<ul style="margin: 0.3em 0 0.5em 1.2em; padding: 0; color:#ccc;">') | ||
table.insert(html, listUL(effects)) | table.insert(html, listUL(effects)) | ||
table.insert(html, '</ul>') | table.insert(html, '</ul>') | ||
if effectsDesc ~= "" then | if effectsDesc ~= "" then | ||
table.insert(html, '<div style="margin-top: 0.3em; font-style: italic; color: # | table.insert(html, '<div style="margin-top: 0.3em; font-style: italic; color: #888; font-size: 0.85em;">' .. mw.text.encode(effectsDesc) .. '</div>') | ||
end | end | ||
table.insert(html, '</div>') -- content | table.insert(html, '</div>') -- content | ||
Версия от 17:44, 16 мая 2025
Для документации этого модуля может быть создана страница Модуль:AlchemyRecipesGrid/doc
local p = {}
local function chunk(tbl, n)
local chunks = {}
for i = 1, #tbl, n do
local chunk = {}
for j = i, math.min(i + n - 1, #tbl) do
table.insert(chunk, tbl[j])
end
table.insert(chunks, chunk)
end
return chunks
end
local function listBlock(text)
local items = {}
for item in mw.text.gsplit(text, ";") do
table.insert(items, "<div>" .. mw.text.trim(item) .. "</div>")
end
return table.concat(items, "\n")
end
local function listUL(text)
local items = {}
for item in mw.text.gsplit(text, ";") do
table.insert(items, "<li>" .. mw.text.trim(item) .. "</li>")
end
return table.concat(items, "\n")
end
local function makeCard(recipe)
local title = recipe["Название"] or "Без названия"
local ingredients = recipe["Ингредиенты"] or ""
local result = recipe["Результат"] or ""
local effects = recipe["Эффекты"] or ""
local effectsDesc = recipe["ОписаниеЭффектов"] or ""
local borderColor = recipe["ЦветРамки"] or "#444"
local backgroundColor = recipe["ЦветФона"] or "#1a1a1a"
local html = {}
table.insert(html, '<div class="alchemy-card" style="border: 2px solid ' .. borderColor .. '; padding: 0.5em 1em; border-radius: 8px; background: ' .. backgroundColor .. '; box-sizing: border-box; width: 23%; margin: 0.5%;">')
table.insert(html, '<h3 style="margin-top:0; text-align:center; font-size:1.1em; color:#ddd;">' .. mw.text.encode(title) .. '</h3>')
-- Блок рецепта
table.insert(html, '<div class="mw-collapsible mw-collapsed" style="margin-bottom:0.5em;">')
table.insert(html, '<div class="mw-collapsible-toggle" style="color:#bbb;">Рецепт (нажмите для раскрытия)</div>')
table.insert(html, '<div class="mw-collapsible-content">')
table.insert(html, '<div style="display: flex; text-align: center; align-items: stretch; font-size:0.9em;">')
table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid #555; padding-right: 0.5em; color:#ccc;">')
table.insert(html, listBlock(ingredients))
table.insert(html, '</div>')
table.insert(html, '<div style="flex: 0 0 80px; display: flex; align-items: center; justify-content: center; font-weight:bold; font-size: 0.95em; color:#aaa;">СМЕШАТЬ</div>')
table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-left: 1px solid #555; padding-left: 0.5em; color:#ccc;">')
table.insert(html, listBlock(result))
table.insert(html, '</div>')
table.insert(html, '</div>') -- flex
table.insert(html, '</div>') -- content
table.insert(html, '</div>') -- block
-- Блок эффектов
if effects ~= "" then
table.insert(html, '<div class="mw-collapsible mw-collapsed" style="margin-top:0.5em;">')
table.insert(html, '<div class="mw-collapsible-toggle" style="color:#bbb;">Эффекты (нажмите для раскрытия)</div>')
table.insert(html, '<div class="mw-collapsible-content">')
table.insert(html, '<ul style="margin: 0.3em 0 0.5em 1.2em; padding: 0; color:#ccc;">')
table.insert(html, listUL(effects))
table.insert(html, '</ul>')
if effectsDesc ~= "" then
table.insert(html, '<div style="margin-top: 0.3em; font-style: italic; color: #888; font-size: 0.85em;">' .. mw.text.encode(effectsDesc) .. '</div>')
end
table.insert(html, '</div>') -- content
table.insert(html, '</div>') -- block
end
table.insert(html, '</div>') -- карточка
return table.concat(html, "\n")
end
function p.fromTable(frame)
local data = mw.text.jsonDecode(frame.args.data or "[]")
if not data or type(data) ~= "table" then return "Ошибка данных таблицы." end
local html = {}
html[#html + 1] = '<div class="alchemy-grid" style="display: flex; flex-wrap: wrap; justify-content: space-between;">'
for _, recipe in ipairs(data) do
html[#html + 1] = makeCard(recipe)
end
html[#html + 1] = '</div>'
return table.concat(html, "\n")
end
return p