Sha256: 0fafc0866d363a1e1c3030e6c109eb79a5aedba1bd8e9cddc68551e3ba996036
Contents?: true
Size: 1.61 KB
Versions: 2
Compression:
Stored size: 1.61 KB
Contents
require 'fileutils' module Webgen::Output # This class is used to write rendered nodes out to the file system. class FileSystem include Webgen::WebsiteAccess # The root path, ie. the path to which the root node gets rendered. attr_reader :root # Create a new object with the given +root+ path. If +root+ is not absolute, it is taken # relative to the website directory. 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 # Return +true+ if the given path exists. def exists?(path) File.exists?(File.join(@root, path)) end # Delete the given +path+ def delete(path) dest = File.join(@root, path) if File.directory?(dest) FileUtils.rm_rf(dest) else FileUtils.rm(dest) end end # Write the +data+ to the given +path+. The +type+ parameter specifies the type of the path to # be created which can either be <tt>:file</tt> or <tt>:directory</tt>. 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 do |source| File.open(dest, 'wb') {|f| FileUtils.copy_stream(source, f) } end end else raise "Unsupported path type '#{type}' for #{path}" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
webgen-0.5.0 | lib/webgen/output/filesystem.rb |
webgen-0.5.1 | lib/webgen/output/filesystem.rb |