Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 521: | Строка 521: | ||
return "false" | return "false" | ||
end | |||
function p.GeneratorId(frame) | |||
local args = frame.args or {} | |||
local generatorId = args[1] or "" | |||
local pagePath = args[2] or "" | |||
if generatorId == "" or pagePath == "" then | |||
return "" | |||
end | |||
local moduleName = get_module_name(pagePath .. ".json") | |||
local data = load_cached_data(moduleName) | |||
if not data or type(data) ~= "table" then | |||
return "" | |||
end | |||
local entry = data[generatorId] | |||
if entry == nil then | |||
return "" | |||
end | |||
if type(entry) ~= "table" then | |||
local okSingle, jsonSingle = pcall(mw.text.jsonEncode, { tostring(entry) }) | |||
if okSingle then | |||
return jsonSingle | |||
end | |||
return "" | |||
end | |||
local ok, json = pcall(mw.text.jsonEncode, entry) | |||
if ok then | |||
return json | |||
end | |||
return "" | |||
end | |||
function p.GeneratorTplId(frame) | |||
local args = frame.args or {} | |||
local generatorId = args[1] or "" | |||
local pagePath = args[2] or "" | |||
local tplPath = args[3] or "" | |||
if generatorId == "" or pagePath == "" or tplPath == "" then | |||
return "" | |||
end | |||
local moduleName = get_module_name(pagePath .. ".json") | |||
local data = load_cached_data(moduleName) | |||
if not data or type(data) ~= "table" then | |||
return "" | |||
end | |||
local entry = data[generatorId] | |||
if type(entry) ~= "table" then | |||
return "" | |||
end | |||
local tplPagePath = pagePath .. "/" .. generatorId .. ".json" | |||
local out = {} | |||
for _, id in ipairs(entry) do | |||
local tpl = p.getTpl({ args = { id, tplPagePath, tplPath } }) | |||
if tpl ~= "" then | |||
out[#out + 1] = tpl | |||
end | |||
end | |||
if #out == 0 then | |||
return "" | |||
end | |||
local result = table.concat(out, " ") | |||
return preprocess_or_return(frame, result) | |||
end | end | ||
return p | return p | ||