Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 525: | Строка 525: | ||
function p.GeneratorId(frame) | function p.GeneratorId(frame) | ||
local args = frame.args or {} | local args = frame.args or {} | ||
local | local pagePath = args[1] or "" | ||
local | if pagePath == "" then | ||
if not | return "" | ||
end | |||
local moduleName = get_module_name(pagePath) | |||
local data = load_cached_data(moduleName) | |||
if not data then | |||
return "" | |||
end | |||
local idsTable = data.id | |||
if type(idsTable) ~= "table" then | |||
return "" | return "" | ||
end | end | ||
local ids = {} | local ids = {} | ||
for k in pairs(idsTable) do | |||
ids[#ids + 1] = k | |||
end | end | ||
table.sort(ids) | table.sort(ids) | ||
local | local ok, json = pcall(mw.text.jsonEncode, ids) | ||
if | if ok and json then | ||
return | return json | ||
end | end | ||
| Строка 552: | Строка 559: | ||
function p.GeneratorTplId(frame) | function p.GeneratorTplId(frame) | ||
local args = frame.args or {} | local args = frame.args or {} | ||
local | local pagePath = args[1] or "" | ||
local tplPath = args[2] or "" | local tplPath = args[2] or "" | ||
if | if pagePath == "" or tplPath == "" then | ||
return "" | return "" | ||
end | end | ||
local | local moduleName = get_module_name(pagePath) | ||
if not | local data = load_cached_data(moduleName) | ||
if not data then | |||
return "" | return "" | ||
end | end | ||
| Строка 572: | Строка 580: | ||
for idKey in pairs(idsTable) do | for idKey in pairs(idsTable) do | ||
local tpl = p.getTpl({ args = { idKey, | local tpl = p.getTpl({ args = { idKey, pagePath, tplPath } }) | ||
if tpl ~= "" then | if tpl ~= "" then | ||
out[#out + 1] = tpl | out[#out + 1] = tpl | ||