Parent

Included Modules

Class/Module Index [+]

Quicksearch

Webgen::Output::FileSystem

This class uses the file systems as output device. On initialization a root path is set and all other operations are taken relative to this root path.

Attributes

root[R]

The root path, ie. the path to which the root node gets rendered.

Public Class Methods

new(root) click to toggle source

Create a new object with the given root path. If root is not absolute, it is taken relative to the website directory.

# File lib/webgen/output/filesystem.rb, line 17
def initialize(root)
  #TODO: copied from source/filesystem.rb
  if root =~ /^([a-zA-Z]:|\/)/
    @root = root
  else
    @root = File.join(website.directory, root)
  end
end

Public Instance Methods

delete(path) click to toggle source

Delete the given path

# File lib/webgen/output/filesystem.rb, line 32
def delete(path)
  dest = File.join(@root, path)
  if File.directory?(dest)
    FileUtils.rm_rf(dest)
  else
    FileUtils.rm(dest)
  end
end
exists?(path) click to toggle source

Return true if the given path exists.

# File lib/webgen/output/filesystem.rb, line 27
def exists?(path)
  File.exists?(File.join(@root, path))
end
read(path, mode = 'rb') click to toggle source

Return the content of the given path which is opened in mode.

# File lib/webgen/output/filesystem.rb, line 62
def read(path, mode = 'rb')
  File.open(File.join(@root, path), mode) {|f| f.read}
end
write(path, data, type = :file) click to toggle source

Write the data to the given path. The type parameter specifies the type of the path to be created which can either be :file or :directory.

# File lib/webgen/output/filesystem.rb, line 43
def write(path, data, type = :file)
  dest = File.join(@root, path)
  FileUtils.makedirs(File.dirname(dest))
  if type == :directory
    FileUtils.makedirs(dest)
  elsif type == :file
    if data.kind_of?(String)
      File.open(dest, 'wb') {|f| f.write(data) }
    else
      data.stream('rb') do |source|
        File.open(dest, 'wb') {|f| FileUtils.copy_stream(source, f) }
      end
    end
  else
    raise "Unsupported path type '#{type}' for #{path}"
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.