Class Erubis::Engine
In: erubis/engine.rb
Parent: Object

(abstract) abstract engine class. subclass must include evaluator and converter module.

Methods

convert!   load_file   new   process   process_proc  

Public Class methods

load file and create engine object

[Source]

# File erubis/engine.rb, line 40
    def self.load_file(filename, properties={})
      input = File.open(filename, 'rb') { |f| f.read }
      input.untaint   # is it ok?
      properties[:filename] = filename
      engine = self.new(input, properties)
      return engine
    end

[Source]

# File erubis/engine.rb, line 31
    def initialize(input=nil, properties={})
      #@input = input
      init_generator(properties)
      init_converter(properties)
      init_evaluator(properties)
      @src    = convert(input) if input
    end

Public Instance methods

convert input string and set it to @src

[Source]

# File erubis/engine.rb, line 27
    def convert!(input)
      @src = convert(input)
    end

helper method to convert and evaluate input text with context object. context may be Binding, Hash, or Object.

[Source]

# File erubis/engine.rb, line 53
    def process(input, context=nil, filename=nil)
      code = convert(input)
      filename ||= '(erubis)'
      if context.is_a?(Binding)
        return eval(code, context, filename)
      else
        context = Context.new(context) if context.is_a?(Hash)
        return context.instance_eval(code, filename)
      end
    end

helper method evaluate Proc object iwth contect object. context may be Binding, Hash, or Object.

[Source]

# File erubis/engine.rb, line 69
    def process_proc(proc_obj, context=nil, filename=nil)
      if context.is_a?(Binding)
        filename ||= '(erubis)'
        return eval(proc_obj, context, filename)
      else
        context = Context.new(context) if context.is_a?(Hash)
        return context.instance_eval(&proc_obj)
      end
    end

[Validate]