2011-11-22 17:14:00 +00:00
|
|
|
require 'sprockets/jst_processor'
|
|
|
|
|
|
|
|
module Jasmine::Headless
|
|
|
|
class JSTTemplate < Sprockets::JstProcessor
|
2011-12-05 23:49:52 +00:00
|
|
|
include Jasmine::Headless::FileChecker
|
2011-11-22 17:14:00 +00:00
|
|
|
def evaluate(*args)
|
2011-12-05 23:49:52 +00:00
|
|
|
if bad_format?(file)
|
|
|
|
alert_bad_format(file)
|
|
|
|
return ''
|
|
|
|
end
|
2012-02-08 13:54:34 +00:00
|
|
|
begin
|
|
|
|
data = super
|
|
|
|
cache = Jasmine::Headless::JSTTemplateCache.new(file, data)
|
|
|
|
|
|
|
|
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" % [ 'jst'.color(:red), file.color(:yellow) ]
|
|
|
|
raise e
|
|
|
|
end
|
2011-11-22 17:14:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|