Class: StylusAssets::StylusTemplate

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/stylus_assets/stylus_template.rb

Overview

Stylus 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/stylus_assets/stylus_template.rb', line 15

def name_filter
  @name_filter
end

.namespaceObject

The JavaScript Style template namespace



18
19
20
# File 'lib/stylus_assets/stylus_template.rb', line 18

def namespace
  @namespace
end

.variable_prefixObject

The variable prefix



21
22
23
# File 'lib/stylus_assets/stylus_template.rb', line 21

def variable_prefix
  @variable_prefix
end

Class Method Details

.engine_initialized?Boolean

Test if the compiler is initialized.

Returns:

  • (Boolean)

    the initialization status



40
41
42
# File 'lib/stylus_assets/stylus_template.rb', line 40

def self.engine_initialized?
  true
end

Instance Method Details

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

Generates the Stylus template wrapped in a JavaScript template

Parameters:

  • name (String)

    the template name

Returns:

  • (String)

    the less JavaScript template



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/stylus_assets/stylus_template.rb', line 59

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, i) { return StylusAssets.render('#{ name }', \"#{ data.gsub(/\n/, "\\n") }\", v, e, i); };
}).call(this);
  JST
end

#initialize_engineObject

Initialize the template engine.



46
47
# File 'lib/stylus_assets/stylus_template.rb', line 46

def initialize_engine
end

#prepareObject

Prepare the template



51
52
# File 'lib/stylus_assets/stylus_template.rb', line 51

def prepare
end