diff --git a/lib/jasmine/headless.rb b/lib/jasmine/headless.rb index a1dae0b..33ee28c 100644 --- a/lib/jasmine/headless.rb +++ b/lib/jasmine/headless.rb @@ -24,6 +24,7 @@ module Jasmine autoload :CoffeeTemplate, 'jasmine/headless/coffee_template' autoload :JSTemplate, 'jasmine/headless/js_template' + autoload :JSTTemplateCache, 'jasmine/headless/jst_template_cache' autoload :JSTTemplate, 'jasmine/headless/jst_template' autoload :CSSTemplate, 'jasmine/headless/css_template' autoload :NilTemplate, 'jasmine/headless/nil_template' diff --git a/lib/jasmine/headless/jst_template.rb b/lib/jasmine/headless/jst_template.rb index b6d8f1c..9ef20b2 100644 --- a/lib/jasmine/headless/jst_template.rb +++ b/lib/jasmine/headless/jst_template.rb @@ -8,7 +8,21 @@ module Jasmine::Headless alert_bad_format(file) return '' end - %{} + begin + data = super + cache = Jasmine::Headless::JSTTemplateCache.new(file, data) + + source = cache.handle + if cache.cached? + %{ + } + else + %{} + end + rescue StandardError => e + puts "[%s] Error in compiling file: %s" % [ 'jst'.color(:red), file.color(:yellow) ] + raise e + end end end end diff --git a/lib/jasmine/headless/jst_template_cache.rb b/lib/jasmine/headless/jst_template_cache.rb new file mode 100644 index 0000000..ff7dcdc --- /dev/null +++ b/lib/jasmine/headless/jst_template_cache.rb @@ -0,0 +1,26 @@ +require 'sprockets/jst_processor' +require 'digest/sha1' +require 'fileutils' + +module Jasmine + module Headless + class JSTTemplateCache < CacheableAction + + def initialize(file, data) + @file = file + @data = data + end + + class << self + def cache_type + "jst_template" + end + end + + def action + @data + end + end + end +end +