Class: Jasmine::Headless::CoffeeTemplate

Inherits:
Tilt::Template
  • Object
show all
Includes:
FileChecker
Defined in:
lib/jasmine/headless/coffee_template.rb

Instance Method Summary collapse

Methods included from FileChecker

#alert_bad_format, #alert_if_bad_format?, #bad_format?

Instance Method Details

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jasmine/headless/coffee_template.rb', line 12

def evaluate(scope, locals, &block)
  if bad_format?(file)
    alert_bad_format(file)
    return ''
  end
  begin
    cache = Jasmine::Headless::CoffeeScriptCache.new(file)
    source = cache.handle
    if cache.cached?
      %{<script type="text/javascript" src="#{cache.cache_file}"></script>
        <script type="text/javascript">window.CSTF['#{File.split(cache.cache_file).last}'] = '#{file}';</script>}
    else
      %{<script type="text/javascript">#{source}</script>}
    end
  rescue CoffeeScript::CompilationError => ne
    puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), "#{ne.message}".color(:white) ]
    raise ne
  rescue StandardError => e
    puts "[%s] Error in compiling file: %s" % [ 'coffeescript'.color(:red), file.color(:yellow) ]
    raise e
  end
end

#prepareObject



10
# File 'lib/jasmine/headless/coffee_template.rb', line 10

def prepare ; end