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

Нет описания правки
Нет описания правки
 
Строка 39: Строка 39:
end
end


function p.project(frame)
local function isFrameLike(value)
     local args = getArgs(frame)
     return type(value) == "table" and type(value.getParent) == "function"
    local path = resolvePath(args.path or args[1])
    return resolvePath(path)
end
end


function p.prefix(frame)
local function getPathFromCall(call)
     local args = getArgs(frame)
    if type(call) == "string" then
     local path = resolvePath(args.path or args[1])
        return resolvePath(call)
     end
 
    if isFrameLike(call) then
        local args = getArgs(call)
        return resolvePath(args.path or args[1])
     end
 
    if type(call) == "table" then
        return resolvePath(call.path or call[1])
    end
 
    return resolvePath("")
end
 
function p.project(call)
    return getPathFromCall(call)
end
 
function p.prefix(call)
    local path = getPathFromCall(call)


     if path ~= "" then
     if path ~= "" then
Строка 102: Строка 120:


function p.has(id, path)
function p.has(id, path)
    if isFrameLike(id) then
        local args = getArgs(id)
        id = args[1] or args.id
        path = args.path or args[2]
    end
     id = trim(id)
     id = trim(id)
     if id == "" then
     if id == "" then
Строка 121: Строка 145:


function p.get(rel, path)
function p.get(rel, path)
    if isFrameLike(rel) then
        local args = getArgs(rel)
        rel = args[1] or args.rel
        path = args.path or args[2]
    end
     rel = trim(rel)
     rel = trim(rel)
     if rel == "" then
     if rel == "" then
Строка 136: Строка 166:
end
end


function p.git(frame)
function p.git(call)
    local args = getArgs(frame)
     local path = getPathFromCall(call)
     local path = resolvePath(args.path or args[1])


     if path == "Goob" then
     if path == "Goob" then