Sha256: 5e82af9cd03faefa47e74bce6f6e90298e5a8028ba23c3e471921f2b535e5251

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

module Webgen::ContentProcessor

  # Processes embedded Ruby statements with the +erubis+ library.
  class Erubis

    include Webgen::WebsiteAccess

    # Process the Ruby statements embedded in the content of +context+.
    def call(context)
      require 'erubis'
      # including Erubis because of problem with resolving Erubis::XmlHelper et al
      self.class.class_eval "include ::Erubis"

      node = context.content_node
      ref_node = context.ref_node
      dest_node = context.dest_node

      options = website.config['contentprocessor.erubis.options']
      if context[:block]
        use_pi = context[:block].options['erubis_use_pi']
        context[:block].options.select {|k,v| k =~ /^erubis_/}.
          each {|k,v| options[k.sub(/^erubis_/, '').to_sym] = v }
      end
      erubis = if (!use_pi.nil? && use_pi) || (use_pi.nil? && website.config['contentprocessor.erubis.use_pi'])
                    ::Erubis::PI::Eruby.new(context.content, options)
                  else
                    ::Erubis::Eruby.new(context.content, options)
                  end
      erubis.filename = context.ref_node.absolute_lcn
      context.content = erubis.result(binding)
      context
    rescue Exception => e
      raise RuntimeError, "Erubis processing failed in <#{context.ref_node.absolute_lcn}>: #{e.message}", e.backtrace
    end

  end

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.5.20081010 lib/webgen/contentprocessor/erubis.rb
gettalong-webgen-0.5.5.20081012 lib/webgen/contentprocessor/erubis.rb
gettalong-webgen-0.5.6.20081020 lib/webgen/contentprocessor/erubis.rb
webgen-0.5.6 lib/webgen/contentprocessor/erubis.rb