From 57a8c2661a7d8631c471d5f7068335b798232fd5 Mon Sep 17 00:00:00 2001 From: hysios Date: Thu, 9 Feb 2012 10:41:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0jst=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/jasmine/headless.rb | 1 + lib/jasmine/headless/jst_template.rb | 16 ++++++++++++- lib/jasmine/headless/jst_template_cache.rb | 26 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 lib/jasmine/headless/jst_template_cache.rb 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 +