Class: LessAssets::LessTemplate

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/less_assets/less_template.rb

Overview

Less template implementation for Tilt.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.name_filterObject

A proc that is called to modify the template name used as the JST key. The proc is passed the name as an argument and should return the modified name (or unmodified) name.



15
16
17
# File 'lib/less_assets/less_template.rb', line 15

def name_filter
  @name_filter
end

.namespaceObject

The JavaScript Style template namespace



18
19
20
# File 'lib/less_assets/less_template.rb', line 18

def namespace
  @namespace
end

Class Method Details

.engine_initialized?Boolean

Test if the compiler is initialized.

Returns:

  • (Boolean)

    the initialization status



34
35
36
# File 'lib/less_assets/less_template.rb', line 34

def self.engine_initialized?
  true
end

Instance Method Details

#evaluate(scope, locals = { }, &block) ⇒ String

Generates the Less template wrapped in a JavaScript template

Parameters:

  • name (String)

    the template name

Returns:

  • (String)

    the less JavaScript template



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/less_assets/less_template.rb', line 53

def evaluate(scope, locals = { }, &block)
  name = scope.logical_path
  name = self.class.name_filter.call(name) if self.class.name_filter

  <<-JST
(function() {
  #{ self.class.namespace } || (#{ self.class.namespace } = {});
  #{ self.class.namespace }['#{ name }'] = function(v, e) { return LessAssets.render('#{ name }', \"#{ data.gsub(/\n/, "\\n") }\", v, e); };
}).call(this);
  JST
end

#initialize_engineObject

Initialize the template engine.



40
41
# File 'lib/less_assets/less_template.rb', line 40

def initialize_engine
end

#prepareObject

Prepare the template



45
46
# File 'lib/less_assets/less_template.rb', line 45

def prepare
end