module JekyllAdmin::PathHelper

Public Instance Methods

absolute_path() click to toggle source

Returns the sanitized absolute path to the requested object

# File lib/jekyll-admin/path_helper.rb, line 22
def absolute_path
  sanitized_path File.join(directory_path, filename)
end
Also aliased as: path
filename() click to toggle source

Returns the basename + extension for the requested file

# File lib/jekyll-admin/path_helper.rb, line 11
def filename
  params["ext"] ||= "yml" if namespace == "data"
  "#{params["path"]}.#{params["ext"]}"
end
new?() click to toggle source

Is this request creating a new file?

# File lib/jekyll-admin/path_helper.rb, line 55
def new?
  !request_payload["path"]
end
path()
Alias for: absolute_path
relative_path() click to toggle source

Returns the sanitized relative path to the requested object

# File lib/jekyll-admin/path_helper.rb, line 28
def relative_path
  sanitized_relative_path absolute_path
end
relative_write_path() click to toggle source

Returns the sanitized relative path to write the requested object

# File lib/jekyll-admin/path_helper.rb, line 43
def relative_write_path
  sanitized_relative_path write_path
end
renamed?() click to toggle source

Is this request renaming a file?

# File lib/jekyll-admin/path_helper.rb, line 48
def renamed?
  return false unless request_payload["path"]

  ensure_leading_slash(request_payload["path"]) != relative_path
end
request_path()
Alias for: write_path
sanitized_path(path) click to toggle source
# File lib/jekyll-admin/path_helper.rb, line 5
def sanitized_path(path)
  path = path_without_site_source(path)
  Jekyll.sanitized_path JekyllAdmin.site.source, path
end
sanitized_relative_path(path) click to toggle source

Returns the sanitized path relative to the site source

# File lib/jekyll-admin/path_helper.rb, line 17
def sanitized_relative_path(path)
  path_without_site_source sanitized_path(path)
end
write_path() click to toggle source

Returns the sanitized absolute path to write the requested object

# File lib/jekyll-admin/path_helper.rb, line 33
def write_path
  if renamed?
    sanitized_path request_payload["path"]
  else
    path
  end
end
Also aliased as: request_path

Private Instance Methods

directory_path() click to toggle source

Returns the path to the requested file's containing directory

# File lib/jekyll-admin/path_helper.rb, line 62
def directory_path
  sanitized_path(
    case namespace
    when "collections"
      File.join(collection.directory, params["splat"].first)
    when "data"
      File.join(DataFile.data_dir, params["splat"].first)
    when "drafts"
      File.join("_drafts", params["splat"].first)
    else
      params["splat"].first
    end
  )
end
ensure_leading_slash(input) click to toggle source
# File lib/jekyll-admin/path_helper.rb, line 77
def ensure_leading_slash(input)
  return input if input.nil? || input.empty? || input.start_with?("/")

  "/#{input}"
end
path_without_site_source(path) click to toggle source
# File lib/jekyll-admin/path_helper.rb, line 83
def path_without_site_source(path)
  path.to_s.gsub(%r!\A#{Regexp.escape(JekyllAdmin.site.source)}!, "")
end