Модуль:AlchemyRecipe: различия между версиями

Материал из Space Stories Wiki
Нет описания правки
Нет описания правки
Строка 7: Строка 7:
local result = args["Результат"] or ""
local result = args["Результат"] or ""
local effects = args["Эффекты"] or ""
local effects = args["Эффекты"] or ""
local effectsDesc = args["ОписаниеЭффектов"] or ""


local borderColor = args["ЦветРамки"] or "#ccc"
local borderColor = args["ЦветРамки"] or "#ccc"
Строка 15: Строка 16:
for item in mw.text.gsplit(text, ";") do
for item in mw.text.gsplit(text, ";") do
table.insert(items, "<div>" .. mw.text.trim(item) .. "</div>")
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
end
return table.concat(items, "\n")
return table.concat(items, "\n")
Строка 23: Строка 32:
table.insert(html, '<h3 style="margin-top:0; text-align:center;">' .. title .. '</h3>')
table.insert(html, '<h3 style="margin-top:0; text-align:center;">' .. title .. '</h3>')


-- Flex с выравниванием по центру и равной высотой
-- Рецепт (флекс, три колонки)
table.insert(html, '<div style="display: flex; text-align: center; align-items: stretch;">')
table.insert(html, '<div style="display: flex; text-align: center; align-items: stretch;">')
-- Ингредиенты
table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid #aaa; padding-right: 0.5em;">')
table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid #aaa; padding-right: 0.5em;">')
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 100px; display: flex; align-items: center; justify-content: center; font-weight:bold;">СМЕШАТЬ</div>')
table.insert(html, '<div style="flex: 0 0 100px; display: flex; align-items: center; justify-content: center; font-weight:bold;">СМЕШАТЬ</div>')
-- Результат
table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-left: 1px solid #aaa; padding-left: 0.5em;">')
table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-left: 1px solid #aaa; padding-left: 0.5em;">')
table.insert(html, listBlock(result))
table.insert(html, listBlock(result))
table.insert(html, '</div>')
table.insert(html, '</div>')
table.insert(html, '</div>')
table.insert(html, '</div>')


-- Эффекты (опционально)
-- Эффекты (список)
if effects ~= "" then
if effects ~= "" then
table.insert(html, '<hr><b>Эффекты:</b><ul>')
table.insert(html, '<hr><b>Эффекты:</b><ul>')
for item in mw.text.gsplit(effects, ";") do
table.insert(html, listUL(effects))
table.insert(html, "<li>" .. mw.text.trim(item) .. "</li>")
table.insert(html, '</ul>')
end
end
table.insert(html, "</ul>")
 
-- Описание эффектов (текст под списком)
if effectsDesc ~= "" then
table.insert(html, '<div style="margin-top: 0.5em; font-style: italic; color: #555;">' .. mw.text.trim(effectsDesc) .. '</div>')
end
end


table.insert(html, "</div>")
table.insert(html, '</div>')
return table.concat(html, "\n")
return table.concat(html, "\n")
end
end


return p
return p

Версия от 10:53, 16 мая 2025

Для документации этого модуля может быть создана страница Модуль:AlchemyRecipe/doc

local p = {}

function p.card(frame)
	local args = frame:getParent().args
	local title = args["Название"] or "Без названия"
	local ingredients = args["Ингредиенты"] or ""
	local result = args["Результат"] or ""
	local effects = args["Эффекты"] or ""
	local effectsDesc = args["ОписаниеЭффектов"] or ""

	local borderColor = args["ЦветРамки"] or "#ccc"
	local backgroundColor = args["ЦветФона"] or "#f9f9f9"

	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 html = {}
	table.insert(html, '<div style="border: 2px solid ' .. borderColor .. '; padding: 1em; border-radius: 8px; background: ' .. backgroundColor .. '; max-width: 600px;">')
	table.insert(html, '<h3 style="margin-top:0; text-align:center;">' .. title .. '</h3>')

	-- Рецепт (флекс, три колонки)
	table.insert(html, '<div style="display: flex; text-align: center; align-items: stretch;">')
	table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid #aaa; padding-right: 0.5em;">')
	table.insert(html, listBlock(ingredients))
	table.insert(html, '</div>')
	table.insert(html, '<div style="flex: 0 0 100px; display: flex; align-items: center; justify-content: center; font-weight:bold;">СМЕШАТЬ</div>')
	table.insert(html, '<div style="flex: 1; display: flex; flex-direction: column; justify-content: center; border-left: 1px solid #aaa; padding-left: 0.5em;">')
	table.insert(html, listBlock(result))
	table.insert(html, '</div>')
	table.insert(html, '</div>')

	-- Эффекты (список)
	if effects ~= "" then
		table.insert(html, '<hr><b>Эффекты:</b><ul>')
		table.insert(html, listUL(effects))
		table.insert(html, '</ul>')
	end

	-- Описание эффектов (текст под списком)
	if effectsDesc ~= "" then
		table.insert(html, '<div style="margin-top: 0.5em; font-style: italic; color: #555;">' .. mw.text.trim(effectsDesc) .. '</div>')
	end

	table.insert(html, '</div>')
	return table.concat(html, "\n")
end

return p