Sha256: 2ee78ed9434e9bfbbbbaed949b3ccb1d4b87f69e984dc18a1f6c34566b5232a4

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

# -*- encoding: utf-8 -*-

module Webgen::ContentProcessor

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

    include Deprecated

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

      website = deprecate('website', 'context.website', context.website)
      node = deprecate('node', 'context.node', context.content_node)
      ref_node = deprecate('ref_node', 'context.ref_node', context.ref_node)
      dest_node = deprecate('dest_node', 'context.dest_node', context.dest_node)

      options = context.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? && context.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.alcn
      context.content = erubis.result(binding)
      context
    rescue LoadError
      raise Webgen::LoadError.new('erubis', self.class.name, context.dest_node.alcn, 'erubis')
    rescue Exception => e
      line = (e.is_a?(::SyntaxError) ? e.message : e.backtrace[0]).scan(/:(\d+)/).first.first.to_i rescue nil
      raise Webgen::RenderError.new(e, self.class.name, context.dest_node.alcn, context.ref_node.alcn, line)
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webgen-0.5.10 lib/webgen/contentprocessor/erubis.rb
webgen-0.5.9 lib/webgen/contentprocessor/erubis.rb