class Yarrow::Output::Web::IndexedFile

Constants

WRITE_MODE

Public Instance Methods

docroot() click to toggle source

@return [String] Docroot of the output target

# File lib/yarrow/output/web/indexed_file.rb, line 13
def docroot
  @docroot ||= config.output_dir || 'public'
end
ensure_dir_exists!(target) click to toggle source
# File lib/yarrow/output/web/indexed_file.rb, line 37
def ensure_dir_exists!(target)
  unless File.directory?(target)
    FileUtils.mkdir_p(target)
  end
end
index_name() click to toggle source

@return [String] Basename reflecting the server convention (usually: index.html)

# File lib/yarrow/output/web/indexed_file.rb, line 8
def index_name
  @index_name ||= config.index_name || 'index.html'
end
write(path, content) click to toggle source

Write an output file to the specified path under the docroot.

@param path [String] @param content [String]

# File lib/yarrow/output/web/indexed_file.rb, line 21
def write(path, content)
  # If the target path is a directory,
  # generate a default index filename.
  if path[path.length-1] == '/'
    path = "#{path}#{index_name}"
  end

  target_path = Pathname.new("#{docroot}#{path}")

  ensure_dir_exists!(target_path.dirname)

  File.open(target_path.to_s, WRITE_MODE) do |file|
    file.puts(content)
  end
end