2012-01-11 18:23:39 +00:00
|
|
|
require 'tilt/template'
|
|
|
|
require 'execjs'
|
|
|
|
|
|
|
|
module Jasmine::Headless
|
|
|
|
class DustTemplate < Tilt::Template
|
|
|
|
include Jasmine::Headless::FileChecker
|
|
|
|
|
2012-01-12 06:47:39 +00:00
|
|
|
class << self
|
|
|
|
def template_root=(root)
|
|
|
|
@template_root = root
|
|
|
|
end
|
|
|
|
def template_root
|
|
|
|
@template_root || "app/assets/javascripts/templates/"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-11 20:36:43 +00:00
|
|
|
self.default_mime_type = 'application/javascript'
|
2012-01-11 18:23:39 +00:00
|
|
|
|
2012-01-11 20:36:43 +00:00
|
|
|
def prepare; end
|
2012-01-11 18:23:39 +00:00
|
|
|
|
2012-01-11 20:36:43 +00:00
|
|
|
def evaluate(scope, locals, &block)
|
|
|
|
if bad_format?(file)
|
|
|
|
alert_bad_format(file)
|
|
|
|
return ''
|
2012-01-11 18:23:39 +00:00
|
|
|
end
|
2012-01-11 20:36:43 +00:00
|
|
|
begin
|
|
|
|
cache = Jasmine::Headless::DustCache.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 StandardError => e
|
|
|
|
puts "[%s] Error in compiling file: %s" % [ 'coffeescript'.color(:red), file.color(:yellow) ]
|
|
|
|
raise e
|
2012-01-11 18:23:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|