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

Нет описания правки
Нет описания правки
 
(не показаны 3 промежуточные версии этого же участника)
Строка 39: Строка 39:
end
end


function p.project(path)
local function isFrameLike(value)
     return resolvePath(path)
    return type(value) == "table" and type(value.getParent) == "function"
end
 
local function getPathFromCall(call)
    if type(call) == "string" then
        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
        return path .. ":"
    end
 
    return ""
end
end


Строка 89: Строка 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
Строка 108: Строка 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
Строка 123: Строка 166:
end
end


function p.git(path)
function p.git(call)
path = resolvePath(path)
    local path = getPathFromCall(call)
     if project == "Goob" then
 
     if path == "Goob" then
         return "https://github.com/space-syndicate/Goob-Station/tree/master"
         return "https://github.com/space-syndicate/Goob-Station/tree/master"
     elseif project == "CM" then
     elseif path == "CM" then
         return "???"
         return "???"
     elseif project == "Fallout" then
     elseif path == "Fallout" then
         return "https://github.com/Forge-Station/nuclear-14/tree/master"
         return "https://github.com/Forge-Station/nuclear-14/tree/master"
     elseif project == "Frontier" then
     elseif path == "Frontier" then
         return "https://github.com/Forge-Station/Frontier/tree/master"
         return "https://github.com/Forge-Station/Frontier/tree/master"
     elseif project == "SW" then
     elseif path == "SW" then
         return "???"
         return "???"
     elseif project == "Wega" then
     elseif path == "Wega" then
         return "https://github.com/wega-team/ss14-weg/tree/master"
         return "https://github.com/wega-team/ss14-weg/tree/master"
     elseif project == "WL" then
     elseif path == "WL" then
         return "https://github.com/corvax-team/ss14-wl/tree/master"
         return "https://github.com/corvax-team/ss14-wl/tree/master"
     end
     end