Class Webgen::Output::FileSystem
In: lib/webgen/output/filesystem.rb
Parent: Object
Error RenderError CommandNotFoundError LoadError NodeCreationError ::Rake::TaskLib WebgenTask Node Context\n[lib/webgen/context.rb\nlib/webgen/context/nodes.rb\nlib/webgen/context/render.rb\nlib/webgen/context/tags.rb] Tree FileSystem Sitemap Feed Copy Virtual Sitemap Directory Page Fragment Template Memory Metainfo Coderay Sitemap IncludeFile BreadcrumbTrail Langbar TikZ Menu Tags Fragments Resource Website Tidy Head Less Kramdown Xmllint Blocks Helpers Configuration Comparable Language Path StandardError CmdParse::CommandParser CommandParser CmdParse::Command RunCommand CreateCommand WebguiCommand ApplyCommand WebsiteAccess Main Loggable OutputPathHelpers ExecuteCommand Link Date Relocatable Metainfo ::Kramdown::Converter::Html KramdownHtmlConverter Cache Blackboard WebsiteManager Logger Page ProxyNode Utils Scss RDoc Sass Erb RDiscount Erubis Haml Maruku Builder RedCloth AccessHash TarArchive Stacked FileSystem lib/webgen/cache.rb lib/webgen/error.rb lib/webgen/languages.rb lib/webgen/website.rb lib/webgen/blackboard.rb lib/webgen/tree.rb lib/webgen/websitemanager.rb lib/webgen/logger.rb lib/webgen/context/tags.rb lib/webgen/configuration.rb lib/webgen/path.rb lib/webgen/webgentask.rb lib/webgen/page.rb lib/webgen/node.rb lib/webgen/cli/run_command.rb lib/webgen/cli/utils.rb lib/webgen/cli/apply_command.rb lib/webgen/cli/webgui_command.rb lib/webgen/cli.rb lib/webgen/cli/create_command.rb Color CLI ClassMethods WebsiteAccess LanguageManager lib/webgen/output/filesystem.rb Output lib/webgen/common/sitemap.rb Common lib/webgen/sourcehandler/metainfo.rb lib/webgen/sourcehandler/memory.rb lib/webgen/sourcehandler/copy.rb lib/webgen/sourcehandler/directory.rb lib/webgen/sourcehandler.rb lib/webgen/sourcehandler/page.rb lib/webgen/sourcehandler/template.rb lib/webgen/sourcehandler/fragment.rb lib/webgen/sourcehandler/sitemap.rb lib/webgen/sourcehandler/virtual.rb lib/webgen/sourcehandler/feed.rb OutputPathHelpers Base SourceHandler lib/webgen/tag/coderay.rb lib/webgen/tag/relocatable.rb lib/webgen/tag/menu.rb lib/webgen/tag/langbar.rb lib/webgen/tag/executecommand.rb lib/webgen/tag/breadcrumbtrail.rb lib/webgen/tag/metainfo.rb lib/webgen/tag/link.rb lib/webgen/tag/includefile.rb lib/webgen/tag/date.rb lib/webgen/tag/tikz.rb lib/webgen/tag/sitemap.rb Base Tag lib/webgen/contentprocessor/less.rb lib/webgen/contentprocessor/scss.rb lib/webgen/contentprocessor/blocks.rb lib/webgen/contentprocessor/rdoc.rb lib/webgen/contentprocessor/sass.rb lib/webgen/contentprocessor/erb.rb lib/webgen/contentprocessor/rdiscount.rb lib/webgen/contentprocessor/tags.rb lib/webgen/contentprocessor/erubis.rb lib/webgen/contentprocessor/kramdown/html.rb lib/webgen/contentprocessor/haml.rb lib/webgen/contentprocessor/maruku.rb lib/webgen/contentprocessor/xmllint.rb lib/webgen/contentprocessor/kramdown.rb lib/webgen/contentprocessor/head.rb lib/webgen/contentprocessor/builder.rb lib/webgen/contentprocessor/tidy.rb lib/webgen/contentprocessor/redcloth.rb lib/webgen/contentprocessor/fragments.rb lib/webgen/contentprocessor.rb ContentProcessor lib/webgen/source/tararchive.rb lib/webgen/source/stacked.rb lib/webgen/source/resource.rb lib/webgen/source/filesystem.rb Source Loggable Webgen dot/m_81_0.png

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.

Methods

delete   exists?   new   read   write  

Included Modules

Webgen::WebsiteAccess

Attributes

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

Public Class methods

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

[Source]

    # 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

Public Instance methods

Delete the given path

[Source]

    # 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.

[Source]

    # 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.

[Source]

    # 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.

[Source]

    # 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

[Validate]