Module Webgen::Output
In: lib/webgen/output.rb
lib/webgen/output/filesystem.rb
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

Namespace for all classes that know how to write out node content.

Implementing an output class

Output classes know how to write rendered node data to an output location.

An output class must respond to three methods

exists?(path)
Return true if the output path exists.
delete(path)
Delete the given output path.
write(path, data, type)
Write the data to the given output path. The parameter data is either a String with the content or a Webgen::Path::SourceIO object. The parameter type specifies the type of the to be written path: :file or :directory.
read(path, mode = ‘rb’)
Return the content of the given path if it exists or raise an error otherwise. The parameter mode specifies the mode in which the path should be opened and defaults to reading in binary mode.

It seems a bit odd that an output instance has to implement reading functionality. However, consider the case where you want webgen to render a website programmatically and use the output. In this case you need a way to get to content of the written files! This functionality is used, for example, in the webgui.

Sample Output Class

Following is a simple but actually used (by the webgui) output class which stores the written nodes in a hash in memory:

  class MemoryOutput
    include Webgen::WebsiteAccess

    attr_reader :data

    def initialize
      @data = {}
    end

    def exists?(path)
      @data.has_key?(path)
    end

    def delete(path)
      @data.delete(path)
    end

    def write(path, io, type = :file)
      @data[path] = [(io.kind_of?(String) ? io : io.data), type]
    end

    def read(path, mode = 'rb')
      path = File.join('/', path)
      raise "No such file #{path}" unless @data[path] && @data[path].last == :file
      @data[path].first
    end
  end

  WebsiteAccess.website.config.output(['MemoryOutput'])

The last line is used to tell webgen to use this new output class instead of the default one.

Methods

instance  

Classes and Modules

Class Webgen::Output::FileSystem

Public Class methods

Returns an instance of the configured output class.

[Source]

    # File lib/webgen/output.rb, line 75
75:     def self.instance
76:       classes = (WebsiteAccess.website.cache.volatile[:classes] ||= {})
77:       unless classes.has_key?(:output_instance)
78:         klass, *args = WebsiteAccess.website.config['output']
79:         classes[:output_instance] = Common.const_for_name(klass).new(*args)
80:       end
81:       classes[:output_instance]
82:     end

[Validate]