Для документации этого модуля может быть создана страница Модуль:TableOfRecipes/doc
local p = {}
-- Загрузка данных о рецептах из JSON-файла
p.recipes = mw.text.jsonDecode(mw.title.new("User:CapybaraBot/mealrecipes_prototypes.json"):getContent())
-- Функция для генерации таблицы с рецептами
p.fillRecipeTable = function(frame)
local out = ""
for _, recipe in pairs(p.recipes) do
-- Формируем список ингредиентов (solids)
local solidsList = {}
for solidId, amount in pairs(recipe.solids) do
table.insert(solidsList, string.format("%s (%d)", solidId, amount))
end
-- Формируем список реагентов (reagents)
local reagentsList = {}
for reagentId, amount in pairs(recipe.reagents) do
table.insert(reagentsList, string.format("%s (%d)", reagentId, amount))
end
-- Формируем аргументы для шаблона
local templateArgs = {
id = recipe.id,
name = recipe.name,
type = recipe.type,
time = recipe.time,
solids = table.concat(solidsList, ", "),
reagents = table.concat(reagentsList, ", "),
result = recipe.result
}
-- Генерация строки таблицы с использованием шаблона
out = out .. frame:expandTemplate{ title = "RecipeRow", args = templateArgs }
end
return out
end
return p