增加jst缓存支持

This commit is contained in:
hysios 2012-02-09 10:41:02 +08:00
parent 4e64480c69
commit 57a8c2661a
3 changed files with 42 additions and 1 deletions

View File

@ -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'

View File

@ -8,7 +8,21 @@ module Jasmine::Headless
alert_bad_format(file)
return ''
end
%{<script type="text/javascript">#{super}</script>}
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
end
end
end

View File

@ -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