|
|
| (не показано 20 промежуточных версий этого же участника) |
| Строка 1: |
Строка 1: |
| local p = {} | | local p = {} |
|
| |
|
| local function chunk(tbl, n)
| | function p.recipe(frame) |
| local chunks = {}
| | local args = frame:getParent().args |
| for i = 1, #tbl, n do
| | local name = args.name or 'Неизвестно' |
| local chunk = {}
| | local color = args.color or '#cccccc' |
| for j = i, math.min(i + n - 1, #tbl) do
| | local product = args.product or '' |
| table.insert(chunk, tbl[j])
| | local description = args.description or '' |
| end
| | local effect = args.effect or '' |
| table.insert(chunks, chunk)
| | local recipe = args.recipe or '' |
| 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 "#338833"
| |
| local backgroundColor = recipe["ЦветФона"] or "#1a2a1a"
| |
| | |
| 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: #ccffcc;">' .. mw.text.encode(title) .. '</h3>') | |
| | |
| -- Рецепт (по умолчанию раскрыт)
| |
| table.insert(html, '<div class="mw-collapsible mw-made-collapsible" style="margin-bottom:0.5em;" data-expandtext="▼ Рецепт" data-collapsetext="▲ Рецепт">')
| |
| table.insert(html, '<div class="mw-collapsible-content" style="margin-top:0.5em;">')
| |
| | |
| 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;">')
| |
| 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;">СМЕШАТЬ</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;">')
| |
| table.insert(html, listBlock(result))
| |
| table.insert(html, '</div>')
| |
| | |
| table.insert(html, '</div>') -- Конец flex | |
| table.insert(html, '</div>') -- Конец mw-collapsible-content
| |
| table.insert(html, '</div>') -- Конец mw-collapsible
| |
| | |
| -- Эффекты (по умолчанию раскрыт)
| |
| if effects ~= "" then
| |
| table.insert(html, '<div class="mw-collapsible mw-made-collapsible" style="margin-top:0.5em;" data-expandtext="▼ Эффекты" data-collapsetext="▲ Эффекты">')
| |
| table.insert(html, '<div class="mw-collapsible-content" style="margin-top:0.5em;">')
| |
| table.insert(html, '<b>Эффекты:</b><ul style="margin: 0.3em 0 0.5em 1.2em; padding: 0; color: #ccffcc;">')
| |
| 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: #88cc88; font-size: 0.85em;">' .. mw.text.encode(effectsDesc) .. '</div>')
| |
| end
| |
| table.insert(html, '</div>') -- конец mw-collapsible-content
| |
| table.insert(html, '</div>') -- конец mw-collapsible
| |
| end
| |
| | |
| table.insert(html, '</div>') -- Конец карточки
| |
| return table.concat(html, "\n")
| |
| end
| |
| | |
| function p.grid(frame)
| |
| local count = tonumber(frame.args.count) or 0 | |
| if count == 0 then return "Ошибка: параметр count обязателен и должен быть числом." end
| |
| | |
| local allRecipes = {} | |
| for i = 1, count do
| |
| local r = {}
| |
| for _, key in ipairs({"Название", "Ингредиенты", "Результат", "Эффекты", "ОписаниеЭффектов", "ЦветРамки", "ЦветФона"}) do
| |
| local val = frame.args[key .. i]
| |
| if val then r[key] = val end
| |
| end
| |
| table.insert(allRecipes, r)
| |
| end
| |
| | |
| local html = {}
| |
| html[#html + 1] = '<div class="alchemy-grid" style="display: flex; flex-wrap: wrap; justify-content: space-between;">'
| |
|
| |
|
| for _, recipe in ipairs(allRecipes) do | | local function collapse(title, content) |
| html[#html + 1] = makeCard(recipe) | | return string.format( |
| | '<div class="alchemy-collapse">' .. |
| | '<div class="alchemy-toggle" onclick="this.classList.toggle(\'open\')">%s</div>' .. |
| | '<div class="alchemy-content">%s</div>' .. |
| | '</div>', |
| | title, content |
| | ) |
| end | | end |
|
| |
|
| html[#html + 1] = '</div>' | | local recipeBlock = collapse('Рецепт', recipe) |
| | local effectBlock = collapse('Эффекты', effect) |
|
| |
|
| return table.concat(html, "\n") | | return string.format([[ |
| | <div class="alchemy-block" style="border-color:%s"> |
| | <div class="alchemy-header" style="background:%s">%s</div> |
| | <div class="alchemy-body"> |
| | <div class="alchemy-product">%s</div> |
| | %s |
| | %s |
| | <div class="alchemy-description">%s</div> |
| | </div> |
| | </div> |
| | ]], color, color, name, product, recipeBlock, effectBlock, description) |
| end | | end |
|
| |
|
| return p | | return p |