2011-11-19 17:45:40 +00:00
|
|
|
require 'tilt/template'
|
2011-11-22 19:01:05 +00:00
|
|
|
require 'rainbow'
|
2011-11-19 17:45:40 +00:00
|
|
|
|
|
|
|
module Jasmine::Headless
|
|
|
|
class CoffeeTemplate < Tilt::Template
|
2011-12-05 23:49:52 +00:00
|
|
|
include Jasmine::Headless::FileChecker
|
|
|
|
|
2011-11-22 15:36:42 +00:00
|
|
|
self.default_mime_type = 'application/javascript'
|
|
|
|
|
2011-11-19 17:45:40 +00:00
|
|
|
def prepare ; end
|
|
|
|
|
|
|
|
def evaluate(scope, locals, &block)
|
2011-12-05 23:49:52 +00:00
|
|
|
if bad_format?(file)
|
|
|
|
alert_bad_format(file)
|
|
|
|
return ''
|
|
|
|
end
|
2011-11-19 17:45:40 +00:00
|
|
|
begin
|
|
|
|
cache = Jasmine::Headless::CoffeeScriptCache.new(file)
|
|
|
|
source = cache.handle
|
|
|
|
if cache.cached?
|
2011-11-29 15:56:02 +00:00
|
|
|
%{<script type="text/javascript" src="#{cache.cache_file}"></script>
|
2011-11-22 17:14:00 +00:00
|
|
|
<script type="text/javascript">window.CSTF['#{File.split(cache.cache_file).last}'] = '#{file}';</script>}
|
2011-11-19 17:45:40 +00:00
|
|
|
else
|
2011-11-29 15:56:02 +00:00
|
|
|
%{<script type="text/javascript">#{source}</script>}
|
2011-11-19 17:45:40 +00:00
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|