Class: Sprockets::EjsTemplate

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/sprockets/ejs_template.rb

Overview

Tilt engine class for the EJS compiler. Depends on the `ejs` gem.

For more infomation see:

https://github.com/sstephenson/ruby-ejs

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.engine_initialized?Boolean

Check to see if EJS is loaded


12
13
14
# File 'lib/sprockets/ejs_template.rb', line 12

def self.engine_initialized?
  defined? ::EJS
end

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object

Compile template data with EJS compiler.

Returns a JS function definition String. The result should be assigned to a JS variable.

# => "function(obj){...}"

33
34
35
# File 'lib/sprockets/ejs_template.rb', line 33

def evaluate(scope, locals, &block)
  EJS.compile(data)
end

#initialize_engineObject

Autoload ejs library. If the library isn't loaded, Tilt will produce a thread safetly warning. If you intend to use `.ejs` files, you should explicitly require it.


19
20
21
# File 'lib/sprockets/ejs_template.rb', line 19

def initialize_engine
  require_template_library 'ejs'
end

#prepareObject


23
24
# File 'lib/sprockets/ejs_template.rb', line 23

def prepare
end