Module: JekyllAdmin::FileHelper

Included in:
Server
Defined in:
lib/jekyll-admin/file_helper.rb

Instance Method Summary collapse

Instance Method Details

#delete_file(path) ⇒ Object

Delete the file at the given path



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

def delete_file(path)
  Jekyll.logger.debug "DELETING:", path
  FileUtils.rm_f sanitized_path(path)
  site.process
end

#delete_file_without_process(path) ⇒ Object



40
41
42
43
# File 'lib/jekyll-admin/file_helper.rb', line 40

def delete_file_without_process(path)
  Jekyll.logger.debug "DELETING:", path
  FileUtils.rm_f sanitized_path(path)
end

#requested_fileObject

The file the user requested in the URL



6
7
8
# File 'lib/jekyll-admin/file_helper.rb', line 6

def requested_file
  find_by_path(path)
end

#write_file(path, content) ⇒ Object

Write a file to disk with the given content



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jekyll-admin/file_helper.rb', line 18

def write_file(path, content)
  Jekyll.logger.debug "WRITING:", path
  path = sanitized_path(path)
  FileUtils.mkdir_p File.dirname(path)
  File.open(path, "wb") do |file|
    file.write(content)
  end
  # we should fully process in dev mode for tests to pass
  if ENV["RACK_ENV"] == "production"
    site.read
  else
    site.process
  end
end

#written_fileObject

The file ultimately written to disk This may be the requested file, or in the case of a rename will be read from the new path that was actually written to disk



13
14
15
# File 'lib/jekyll-admin/file_helper.rb', line 13

def written_file
  find_by_path(write_path)
end