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 20
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 9
def filename
  params["ext"] ||= "yml" if namespace == "data"
  "#{params["path"]}.#{params["ext"]}"
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 26
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 41
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 46
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 3
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 15
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 31
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 54
def directory_path
  case namespace
  when "collections"
    sanitized_path File.join(collection.relative_directory, params["splat"].first)
  when "data"
    sanitized_path File.join(DataFile.data_dir)
  else
    sanitized_path params["splat"].first
  end
end
ensure_leading_slash(input) click to toggle source
# File lib/jekyll-admin/path_helper.rb, line 65
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 70
def path_without_site_source(path)
  path.to_s.gsub(%r!\A#{Regexp.escape(JekyllAdmin.site.source)}!, "")
end