Module Webgen::ContentProcessor
In: lib/webgen/contentprocessor.rb
lib/webgen/contentprocessor/blocks.rb
lib/webgen/contentprocessor/redcloth.rb
lib/webgen/contentprocessor/haml.rb
lib/webgen/contentprocessor/scss.rb
lib/webgen/contentprocessor/head.rb
lib/webgen/contentprocessor/tags.rb
lib/webgen/contentprocessor/less.rb
lib/webgen/contentprocessor/maruku.rb
lib/webgen/contentprocessor/sass.rb
lib/webgen/contentprocessor/kramdown.rb
lib/webgen/contentprocessor/erb.rb
lib/webgen/contentprocessor/fragments.rb
lib/webgen/contentprocessor/rdiscount.rb
lib/webgen/contentprocessor/rdoc.rb
lib/webgen/contentprocessor/tidy.rb
lib/webgen/contentprocessor/erubis.rb
lib/webgen/contentprocessor/builder.rb
lib/webgen/contentprocessor/xmllint.rb
lib/webgen/contentprocessor/kramdown/html.rb
Error RenderError CommandNotFoundError LoadError NodeCreationError ::Rake::TaskLib WebgenTask Helpers Configuration 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 Copy Feed Virtual Sitemap Directory Page Fragment Template Metainfo Memory Coderay Sitemap IncludeFile BreadcrumbTrail Langbar TikZ Menu Tags Fragments Resource Website Tidy Head Kramdown Less Xmllint Blocks Comparable Language Path StandardError CmdParse::CommandParser CommandParser CmdParse::Command RunCommand WebguiCommand CreateCommand 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/context/render.rb lib/webgen/website.rb lib/webgen/blackboard.rb lib/webgen/tree.rb lib/webgen/websitemanager.rb lib/webgen/logger.rb lib/webgen/configuration.rb lib/webgen/path.rb lib/webgen/webgentask.rb lib/webgen/page.rb lib/webgen/node.rb ClassMethods WebsiteAccess 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 LanguageManager lib/webgen/output/filesystem.rb Output lib/webgen/common/sitemap.rb Common lib/webgen/sourcehandler/memory.rb lib/webgen/sourcehandler/metainfo.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/includefile.rb lib/webgen/tag/link.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_82_0.png

Namespace for all content processors.

Implementing a content processor

Content processors are used to process the content of files, normally of files in Webgen Page Format. A content processor only needs to respond to one method called call and must not take any parameters in the initialize method. This method is invoked with a Webgen::Context object that provides the whole context (especially the content and the node chain) and the method needs to return this object. During processing a content processor normally changes the content of the context but it does not need to.

A self-written content processor does not need to be in the Webgen::ContentProcessor namespace but all shipped ones do.

After writing the content processor class, one needs to add it to the contentprocessor.map hash so that it is used by webgen. The key for the entry needs to be a short name without special characters or spaces and the value can be:

  • the class name, not as constant but as a string - then this content processor is assumed to work with textual data -, or
  • an array with the class name like before and the type, which needs to be :binary or :text.

Sample Content Processor

The following sample content processor checks for a meta information replace_key and replaces strings of the form replace_key:path/to/node with a link to the specified node if it is found.

Note how the content node, the reference node and the destination node are used sothat the correct meta information is used, the node is correctly resolved and the correct relative link is calculated respectively!

  class SampleProcessor

    def call(context)
      if !context.content_node['replace_key'].to_s.empty?
        context.content.gsub!(/#{context.content_node['replace_key']}:([\w\/.]+)/ ) do |match|
          link_node = context.ref_node.resolve($1, context.content_node.lang)
          if link_node
            context.dest_node.link_to(link_node, :lang => context.content_node.lang)
          else
            match
          end
        end
      end
      context
    rescue Exception => e
      raise "Error while replacing special key: #{e.message}"
    end

  end

  Webgen::WebsiteAccess.website.config['contentprocessor.map']['replacer'] = 'SampleProcessor'
  # Or one could equally write
  # Webgen::WebsiteAccess.website.config['contentprocessor.map']['replacer'] = ['SampleProcessor', :text]

Methods

for_name   is_binary?   list  

Classes and Modules

Class Webgen::ContentProcessor::AccessHash
Class Webgen::ContentProcessor::Blocks
Class Webgen::ContentProcessor::Builder
Class Webgen::ContentProcessor::Erb
Class Webgen::ContentProcessor::Erubis
Class Webgen::ContentProcessor::Fragments
Class Webgen::ContentProcessor::Haml
Class Webgen::ContentProcessor::Head
Class Webgen::ContentProcessor::Kramdown
Class Webgen::ContentProcessor::KramdownHtmlConverter
Class Webgen::ContentProcessor::Less
Class Webgen::ContentProcessor::Maruku
Class Webgen::ContentProcessor::RDiscount
Class Webgen::ContentProcessor::RDoc
Class Webgen::ContentProcessor::RedCloth
Class Webgen::ContentProcessor::Sass
Class Webgen::ContentProcessor::Scss
Class Webgen::ContentProcessor::Tags
Class Webgen::ContentProcessor::Tidy
Class Webgen::ContentProcessor::Xmllint

Public Class methods

Return the content processor object identified by name.

[Source]

    # File lib/webgen/contentprocessor.rb, line 90
90:     def self.for_name(name)
91:       klass, cp_type = WebsiteAccess.website.config['contentprocessor.map'][name]
92:       klass.nil? ? nil : WebsiteAccess.website.cache.instance(klass)
93:     end

Return whether the content processor identified by name is processing binary data.

[Source]

    # File lib/webgen/contentprocessor.rb, line 96
96:     def self.is_binary?(name)
97:       WebsiteAccess.website.config['contentprocessor.map'][name].kind_of?(Array) &&
98:         WebsiteAccess.website.config['contentprocessor.map'][name].last == :binary
99:     end

Return the list of all available content processors.

[Source]

    # File lib/webgen/contentprocessor.rb, line 85
85:     def self.list
86:       WebsiteAccess.website.config['contentprocessor.map'].keys
87:     end

[Validate]