Class: StylusAssets::StylusTemplate
- Inherits:
-
Tilt::Template
- Object
- Tilt::Template
- StylusAssets::StylusTemplate
- Defined in:
- lib/stylus_assets/stylus_template.rb
Overview
Stylus template implementation for Tilt.
Class Attribute Summary collapse
-
.name_filter ⇒ Object
A proc that is called to modify the template name used as the JST key.
-
.namespace ⇒ Object
The JavaScript Style template namespace.
-
.variable_prefix ⇒ Object
The variable prefix.
Class Method Summary collapse
-
.engine_initialized? ⇒ Boolean
Test if the compiler is initialized.
Instance Method Summary collapse
-
#evaluate(scope, locals = { }, &block) ⇒ String
Generates the Stylus template wrapped in a JavaScript template.
-
#initialize_engine ⇒ Object
Initialize the template engine.
-
#prepare ⇒ Object
Prepare the template.
Class Attribute Details
.name_filter ⇒ Object
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 |
.namespace ⇒ Object
The JavaScript Style template namespace
18 19 20 |
# File 'lib/stylus_assets/stylus_template.rb', line 18 def namespace @namespace end |
.variable_prefix ⇒ Object
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.
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
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_engine ⇒ Object
Initialize the template engine.
46 47 |
# File 'lib/stylus_assets/stylus_template.rb', line 46 def initialize_engine end |
#prepare ⇒ Object
Prepare the template
51 52 |
# File 'lib/stylus_assets/stylus_template.rb', line 51 def prepare end |