Class: Sprockets::WalrusTemplate

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

Defined Under Namespace

Modules: JSHelper

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.namespaceObject

Returns the value of attribute namespace.



11
12
13
# File 'lib/sprockets/walrus_template.rb', line 11

def namespace
  @namespace
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



20
21
22
# File 'lib/sprockets/walrus_template.rb', line 20

def namespace
  @namespace
end

Class Method Details

.default_mime_typeObject



6
7
8
# File 'lib/sprockets/walrus_template.rb', line 6

def self.default_mime_type
  'application/javascript'
end

Instance Method Details

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



22
23
24
25
26
27
28
29
30
# File 'lib/sprockets/walrus_template.rb', line 22

def evaluate(scope, locals, &block)
  <<-JST
(function() {
#{namespace} || (#{namespace} = {});
var parsed = Walrus.Parser.parse('#{escaped_javascript(data)}');
#{namespace}[#{scope.logical_path.inspect}] = function(obj) { return parsed.compile(obj) };
}).call(this);
  JST
end

#prepareObject



16
17
18
# File 'lib/sprockets/walrus_template.rb', line 16

def prepare
  @namespace = self.class.namespace
end