Модуль: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 jsonStr = args[1] or "" | ||
if jsonStr == "" then return "" end | |||
if | local ok, data = pcall(mw.text.jsonDecode, jsonStr) | ||
if not ok or type(data) ~= "table" then | |||
return "" | return "" | ||
end | end | ||
local | local ids = {} | ||
if type(data.id) == "table" then | |||
if | for k in pairs(data.id) do | ||
ids[#ids + 1] = k | |||
end | |||
end | end | ||
table.sort(ids) | |||
local okOut, outJson = pcall(mw.text.jsonEncode, ids) | |||
if okOut and outJson then | |||
return outJson | |||
local | |||
if | |||
return | |||
end | end | ||
return "" | return "" | ||
end | end | ||
function p.GeneratorTplId(frame) | function p.GeneratorTplId(frame) | ||
local args = frame.args or {} | local args = frame.args or {} | ||
local | local jsonStr = args[1] or "" | ||
local | local tplPath = args[2] or "" | ||
if | if jsonStr == "" or tplPath == "" or pagePath == "" then | ||
return "" | return "" | ||
end | end | ||
local | local ok, data = pcall(mw.text.jsonDecode, jsonStr) | ||
if not ok or type(data) ~= "table" then | |||
if not | |||
return "" | return "" | ||
end | end | ||
local | local idsTable = data.id | ||
if type( | if type(idsTable) ~= "table" then | ||
return "" | return "" | ||
end | end | ||
local | local out = {} | ||
for idKey in pairs(idsTable) do | |||
for | local tpl = p.getTpl({ args = { idKey, jsonStr, tplPath } }) | ||
local tpl = p.getTpl({ args = { | |||
if tpl ~= "" then | if tpl ~= "" then | ||
out[#out + 1] = tpl | out[#out + 1] = tpl | ||
| Строка 591: | Строка 578: | ||
end | end | ||
table.sort(out) | |||
local result = table.concat(out, " ") | local result = table.concat(out, " ") | ||