jasmine-headless-webkit/lib/jasmine/headless/dust_template.rb

42 lines
1.1 KiB
Ruby
Raw Normal View History

2012-01-11 18:23:39 +00:00
require 'tilt/template'
require 'execjs'
module Jasmine::Headless
class DustTemplate < Tilt::Template
include Jasmine::Headless::FileChecker
class << self
def template_root=(root)
@template_root = root
end
def template_root
@template_root || "app/assets/javascripts/templates/"
end
end
self.default_mime_type = 'application/javascript'
2012-01-11 18:23:39 +00:00
def prepare; end
2012-01-11 18:23:39 +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
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