Class: Erubis::Engine

### Home Classes Methods

### In Files

- lib/erubis/engine.rb

### Parent

Object

### Methods

- ::load_file
- ::new
- #convert!
- #process
- #process_proc

### Class/Module Index

Quicksearch

- Erubis
- Erubis::ArrayBufferEnhancer
- Erubis::ArrayBufferEruby
- Erubis::ArrayEnhancer
- Erubis::ArrayEruby
- Erubis::Basic
- Erubis::Basic::Converter
- Erubis::Basic::Engine
- Erubis::BiPatternEnhancer
- Erubis::BiPatternEruby
- Erubis::CGenerator
- Erubis::CommandOptionError
- Erubis::Context
- Erubis::Converter
- Erubis::CppGenerator
- Erubis::DeleteIndentEnhancer
- Erubis::DeleteIndentEruby
- Erubis::Ec
- Erubis::Ecpp
- Erubis::Ejava
- Erubis::Ejavascript
- Erubis::Ejs
- Erubis::Engine
- Erubis::Eperl
- Erubis::Ephp
- Erubis::ErboutEnhancer
- Erubis::ErboutEruby
- Erubis::ErubisError
- Erubis::Eruby
- Erubis::EscapeEnhancer
- Erubis::EscapedEc
- Erubis::EscapedEcpp
- Erubis::EscapedEjava
- Erubis::EscapedEjavascript
- Erubis::EscapedEjs
- Erubis::EscapedEperl
- Erubis::EscapedEphp
- Erubis::EscapedEruby
- Erubis::EscapedEscheme
- Erubis::Escheme
- Erubis::Evaluator
- Erubis::FastEruby
- Erubis::Generator
- Erubis::HeaderFooterEnhancer
- Erubis::HeaderFooterEruby
- Erubis::Helpers
- Erubis::Helpers::RailsFormHelper
- Erubis::Helpers::RailsHelper
- Erubis::Helpers::RailsHelper::TemplateConverter
- Erubis::InterpolationEnhancer
- Erubis::InterpolationEruby
- Erubis::JavaGenerator
- Erubis::JavascriptGenerator
- Erubis::Main
- Erubis::NoCodeEnhancer
- Erubis::NoCodeEruby
- Erubis::NoTextEnhancer
- Erubis::NoTextEruby
- Erubis::NotSupportedError
- Erubis::OptimizedEruby
- Erubis::OptimizedGenerator
- Erubis::OptimizedXmlEruby
- Erubis::PI
- Erubis::PI::Converter
- Erubis::PI::Ec
- Erubis::PI::Ecpp
- Erubis::PI::Ejava
- Erubis::PI::Ejavascript
- Erubis::PI::Engine
- Erubis::PI::Eperl
- Erubis::PI::Ephp
- Erubis::PI::Eruby
- Erubis::PI::Escheme
- Erubis::PI::TinyEruby
- Erubis::PercentLineEnhancer
- Erubis::PercentLineEruby
- Erubis::PerlGenerator
- Erubis::PhpGenerator
- Erubis::PrefixedLineEnhancer
- Erubis::PrefixedLineEruby
- Erubis::PreprocessingEruby
- Erubis::PreprocessingHelper
- Erubis::PrintEnabledEnhancer
- Erubis::PrintEnabledEruby
- Erubis::PrintOutEnhancer
- Erubis::PrintOutEruby
- Erubis::PrintOutSimplifiedEruby
- Erubis::RubyEvaluator
- Erubis::RubyGenerator
- Erubis::SchemeGenerator
- Erubis::SimplifiedEruby
- Erubis::SimplifyEnhancer
- Erubis::StdoutEnhancer
- Erubis::StdoutEruby
- Erubis::StdoutSimplifiedEruby
- Erubis::StringBufferEnhancer
- Erubis::StringBufferEruby
- Erubis::StringIOEruby
- Erubis::TinyEruby
- Erubis::XmlEruby
- Erubis::XmlHelper
- ActionView
- ActionView::TemplateHandlers
- ActionView::TemplateHandlers::ErubisHandler
- ERB
- Kernel

No matching classes.

# Erubis::Engine

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

### Public Class Methods

load_file(filename, properties={}) click to toggle source

load file, write cache file, and return engine object. this method create code cache file automatically. cachefile name can be specified with properties, or filname + 'cache' is used as default.

    # File lib/erubis/engine.rb, line 48
    def self.load_file(filename, properties={})
      cachename = properties[:cachename] || (filename + '.cache')
      properties[:filename] = filename
      timestamp = File.mtime(filename)
      if test(ff, cachename) && timestamp == File.mtime(cachename)
        engine = self.new(nil, properties)
        engine.src = File.read(cachename)
      else
        input = File.open(filename, 'rb') {|f| f.read }
        engine = self.new(input, properties)
        tmpname = cachename + rand().to_s[1,8]
        File.open(tmpname, 'wb') {|f| f.write(engine.src) }
        File.rename(tmpname, cachename)
        File.utime(timestamp, timestamp, cachename)
      end
      engine.src.untaint   # ok?
      return engine
    end

new(input=nil, properties={}) click to toggle source

include Evaluator include Converter include Generator

    # File lib/erubis/engine.rb, line 25
    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) click to toggle source

convert input string and set it to @src

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

process(input, context=nil, filename=nil) click to toggle source

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

    # File lib/erubis/engine.rb, line 72
    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

process_proc(proc_obj, context=nil, filename=nil) click to toggle source

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

    # File lib/erubis/engine.rb, line 88
    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]

Generated with the Darkfish Rdoc Generator 2.