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.
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 18 18: def initialize(root) 19: #TODO: copied from source/filesystem.rb 20: if root =~ /^([a-zA-Z]:|\/)/ 21: @root = root 22: else 23: @root = File.join(website.directory, root) 24: end 25: end
Delete the given path
# File lib/webgen/output/filesystem.rb, line 33 33: def delete(path) 34: dest = File.join(@root, path) 35: if File.directory?(dest) 36: FileUtils.rm_rf(dest) 37: else 38: FileUtils.rm(dest) 39: end 40: end
Return true if the given path exists.
# File lib/webgen/output/filesystem.rb, line 28 28: def exists?(path) 29: File.exists?(File.join(@root, path)) 30: end
Return the content of the given path which is opened in mode.
# File lib/webgen/output/filesystem.rb, line 63 63: def read(path, mode = 'rb') 64: File.open(File.join(@root, path), mode) {|f| f.read} 65: end
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 44 44: def write(path, data, type = :file) 45: dest = File.join(@root, path) 46: FileUtils.makedirs(File.dirname(dest)) 47: if type == :directory 48: FileUtils.makedirs(dest) 49: elsif type == :file 50: if data.kind_of?(String) 51: File.open(dest, 'wb') {|f| f.write(data) } 52: else 53: data.stream('rb') do |source| 54: File.open(dest, 'wb') {|f| FileUtils.copy_stream(source, f) } 55: end 56: end 57: else 58: raise "Unsupported path type '#{type}' for #{path}" 59: end 60: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.