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



28
29
30
31
32
# File 'lib/jekyll-admin/file_helper.rb', line 28

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

#requested_fileObject

The file the user requested in the URL



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

def requested_file
  find_by_path(path)
end

#write_file(path, content) ⇒ Object

Write a file to disk with the given content



17
18
19
20
21
22
23
24
25
# File 'lib/jekyll-admin/file_helper.rb', line 17

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
  site.process
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



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

def written_file
  find_by_path(write_path)
end