Class: Stitch::CoffeeScriptTemplate

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/stitch/coffee_script_template.rb

Constant Summary collapse

@@default_bare =
false
@@excludes =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_bareObject



9
10
11
# File 'lib/stitch/coffee_script_template.rb', line 9

def self.default_bare
  @@default_bare
end

.default_bare=(value) ⇒ Object



13
14
15
# File 'lib/stitch/coffee_script_template.rb', line 13

def self.default_bare=(value)
  @@default_bare = value
end

.engine_initialized?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/stitch/coffee_script_template.rb', line 19

def self.engine_initialized?
  defined? ::CoffeeScript
end

.excludes=(excludes) ⇒ Object



23
24
25
# File 'lib/stitch/coffee_script_template.rb', line 23

def self.excludes=(excludes)
  @@excludes = excludes
end

.javascripts_pathObject



27
28
29
# File 'lib/stitch/coffee_script_template.rb', line 27

def self.javascripts_path
  File.expand_path('../../assets/javascripts', __FILE__)
end

Instance Method Details

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/stitch/coffee_script_template.rb', line 41

def evaluate(scope, locals, &block)
  name = module_name(scope)
  if (name == 'stitch_rails') || excluded?(name)
    @output ||= CoffeeScript.compile(data, options)
  else
    @output ||= <<JS
require.define({
  #{name.inspect}: function(exports, require, module) {
#{indent_lines(CoffeeScript.compile(data, options.merge(:bare => true)), 4)}
  }
});
JS
  end
end

#initialize_engineObject



31
32
33
# File 'lib/stitch/coffee_script_template.rb', line 31

def initialize_engine
  require_template_library 'coffee_script'
end

#prepareObject



35
36
37
38
39
# File 'lib/stitch/coffee_script_template.rb', line 35

def prepare
  if !options.key?(:bare)
    options[:bare] = self.class.default_bare
  end
end