Module: JekyllAdmin::PathHelper

Included in:
DataFile, DataFile, Server
Defined in:
lib/jekyll-admin/path_helper.rb

Instance Method Summary collapse

Instance Method Details

#absolute_pathObject Also known as: path

Returns the sanitized absolute path to the requested object



22
23
24
# File 'lib/jekyll-admin/path_helper.rb', line 22

def absolute_path
  sanitized_path File.join(directory_path, filename)
end

#filenameObject

Returns the basename + extension for the requested file



11
12
13
14
# File 'lib/jekyll-admin/path_helper.rb', line 11

def filename
  params["ext"] ||= "yml" if namespace == "data"
  "#{params["path"]}.#{params["ext"]}"
end

#new?Boolean

Is this request creating a new file?

Returns:

  • (Boolean)


55
56
57
# File 'lib/jekyll-admin/path_helper.rb', line 55

def new?
  !request_payload["path"]
end

#relative_pathObject

Returns the sanitized relative path to the requested object



28
29
30
# File 'lib/jekyll-admin/path_helper.rb', line 28

def relative_path
  sanitized_relative_path absolute_path
end

#relative_write_pathObject

Returns the sanitized relative path to write the requested object



43
44
45
# File 'lib/jekyll-admin/path_helper.rb', line 43

def relative_write_path
  sanitized_relative_path write_path
end

#renamed?Boolean

Is this request renaming a file?

Returns:

  • (Boolean)


48
49
50
51
52
# 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

#sanitized_path(path) ⇒ Object



5
6
7
8
# 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) ⇒ Object

Returns the sanitized path relative to the site source



17
18
19
# File 'lib/jekyll-admin/path_helper.rb', line 17

def sanitized_relative_path(path)
  path_without_site_source sanitized_path(path)
end

#write_pathObject Also known as: request_path

Returns the sanitized absolute path to write the requested object



33
34
35
36
37
38
39
# File 'lib/jekyll-admin/path_helper.rb', line 33

def write_path
  if renamed?
    sanitized_path request_payload["path"]
  else
    path
  end
end