module JekyllAdmin::FileHelper
Public Instance Methods
delete_file(path)
click to toggle source
Delete the file at the given path
# File lib/jekyll-admin/file_helper.rb, line 26 def delete_file(path) Jekyll.logger.debug "DELETING:", path FileUtils.rm_f sanitized_path(path) site.process end
requested_file()
click to toggle source
The file the user requested in the URL
# File lib/jekyll-admin/file_helper.rb, line 5 def requested_file find_by_path(path) end
write_file(path, content)
click to toggle source
Write a file to disk with the given content
# 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.write(path, content) site.process end
written_file()
click to toggle source
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
# File lib/jekyll-admin/file_helper.rb, line 12 def written_file find_by_path(write_path) end
Private Instance Methods
ensure_directory()
click to toggle source
# File lib/jekyll-admin/file_helper.rb, line 60 def ensure_directory render_404 unless Dir.exist?(directory_path) end
ensure_file(file)
click to toggle source
# File lib/jekyll-admin/file_helper.rb, line 56 def ensure_file(file) render_404 if file.nil? end
ensure_requested_file()
click to toggle source
# File lib/jekyll-admin/file_helper.rb, line 34 def ensure_requested_file ensure_file(requested_file) end
ensure_written_file()
click to toggle source
# File lib/jekyll-admin/file_helper.rb, line 38 def ensure_written_file ensure_file(written_file) end
find_by_path(path)
click to toggle source
# File lib/jekyll-admin/file_helper.rb, line 42 def find_by_path(path) files = case namespace when "collections" collection.docs when "data" DataFile.all when "pages", "static_files" site.public_send(namespace.to_sym) else [] end files.find { |f| sanitized_path(f.path) == path } end