Class: Jade::Template

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/jade/template.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/jade/template.rb', line 6

def self.engine_initialized?
  defined? ::Jade
end

Instance Method Details

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

Compile template data using Jade compiler.

This returns a String containing a JS function, which is intended to be used with the Sprockets JST engine. Name your file so that it is processed by both of these engines, and then the template will be available on the JST global on the front end.

For example, ‘my_template.jst.jade` will be available on the front end as JST, which is a function that takes a single argument containing the locals to use in rendering the template:

# => function template(locals) { ... }


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jade/template.rb', line 30

def evaluate(context, locals, &block)
  options = { }
  options[:filename] = eval_file

  # For Rails 4.0.x and 4.1.x, the app-level config is on context.environment.
  # For Rails 4.2.x, it's on context.assets instead.
  app_level_config = context.environment.context_class.jade_config
  if app_level_config.nil?
    app_level_config = context.assets.context_class.jade_config
  end
  jade_config = app_level_config.merge(options)

  # Manually camelize the one option key that needs to be camelized.
  jade_config[:compileDebug] = jade_config.delete(:compile_debug) { false }

  Jade.compile(data, jade_config)
end

#initialize_engineObject



10
11
12
# File 'lib/jade/template.rb', line 10

def initialize_engine
  require_template_library 'jade'
end

#prepareObject



14
15
# File 'lib/jade/template.rb', line 14

def prepare
end