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

мНет описания правки
мНет описания правки
 
(не показана 1 промежуточная версия этого же участника)
Строка 197: Строка 197:
     end
     end
     return text
     return text
end
local function get_field_loose(entry, fieldId)
    local value = entry[fieldId]
    if value ~= nil then return value end
    if fieldId == "" then return nil end
    local first = string.sub(fieldId, 1, 1)
    local tail = string.sub(fieldId, 2)
    value = entry[string.lower(first) .. tail]
    if value ~= nil then return value end
    return entry[string.upper(first) .. tail]
end
end


Строка 224: Строка 237:
     end
     end


     local value = entry[fieldId]
     local value = get_field_loose(entry, fieldId)
     if value == nil then
     if value == nil then
         return ""
         return ""
Строка 447: Строка 460:
     local result = table.concat(out, " ")
     local result = table.concat(out, " ")
     return preprocess_or_return(frame, result)
     return preprocess_or_return(frame, result)
end
function p.getGenerator(frame)
    local args = frame.args or {}
    local searchId = args[1] or ""
    local kind = (args[2] or ""):lower()
    local generatorId = args[3] or ""
    if searchId == "" or generatorId == "" then
        return ""
    end
    if kind ~= "prototype" and kind ~= "component" then
        return ""
    end
    local idsJson = p.findInGenerator({ args = { searchId, kind, generatorId } })
    local ok, ids = pcall(mw.text.jsonDecode, idsJson or "")
    if not ok or type(ids) ~= "table" or #ids == 0 then
        return ""
    end
    local okOut, outJson = pcall(mw.text.jsonEncode, ids)
    if okOut and outJson then
        return outJson
    end
    return ""
end
end