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

Нет описания правки
мНет описания правки
Строка 525: Строка 525:
function p.GeneratorId(frame)
function p.GeneratorId(frame)
     local args = frame.args or {}
     local args = frame.args or {}
     local jsonStr = args[1] or ""
     local pagePath = args[1] or ""
    if jsonStr == "" then return "" end


     local ok, data = pcall(mw.text.jsonDecode, jsonStr)
    if pagePath == "" then
     if not ok or type(data) ~= "table" then
        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 = {}
     if type(data.id) == "table" then
     for k in pairs(idsTable) do
        for k in pairs(data.id) do
        ids[#ids + 1] = k
            ids[#ids + 1] = k
        end
     end
     end


     table.sort(ids)
     table.sort(ids)


     local okOut, outJson = pcall(mw.text.jsonEncode, ids)
     local ok, json = pcall(mw.text.jsonEncode, ids)
     if okOut and outJson then
     if ok and json then
         return outJson
         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 jsonStr = args[1] or ""
     local pagePath = args[1] or ""
     local tplPath = args[2] or ""
     local tplPath = args[2] or ""


     if jsonStr == "" or tplPath == "" or pagePath == "" then
     if pagePath == "" or tplPath == "" then
         return ""
         return ""
     end
     end


     local ok, data = pcall(mw.text.jsonDecode, jsonStr)
     local moduleName = get_module_name(pagePath)
     if not ok or type(data) ~= "table" then
    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, jsonStr, tplPath } })
         local tpl = p.getTpl({ args = { idKey, pagePath, tplPath } })
         if tpl ~= "" then
         if tpl ~= "" then
             out[#out + 1] = tpl
             out[#out + 1] = tpl