fix bug of dust_template, add dust_cache
This commit is contained in:
parent
72b0c80b48
commit
aa40010fbd
@ -8,6 +8,7 @@ module Jasmine
|
||||
autoload :CommandLine, 'jasmine/headless/command_line'
|
||||
|
||||
autoload :CoffeeScriptCache, 'jasmine/headless/coffee_script_cache'
|
||||
autoload :DustCache, 'jasmine/headless/dust_cache'
|
||||
autoload :SpecFileAnalyzer, 'jasmine/headless/spec_file_analyzer'
|
||||
autoload :CacheableAction, 'jasmine/headless/cacheable_action'
|
||||
autoload :VERSION, 'jasmine/headless/version'
|
||||
@ -23,6 +24,7 @@ module Jasmine
|
||||
autoload :FileChecker, 'jasmine/headless/file_checker'
|
||||
|
||||
autoload :CoffeeTemplate, 'jasmine/headless/coffee_template'
|
||||
autoload :DustTemplate, 'jasmine/headless/dust_template'
|
||||
autoload :JSTemplate, 'jasmine/headless/js_template'
|
||||
autoload :JSTTemplate, 'jasmine/headless/jst_template'
|
||||
autoload :CSSTemplate, 'jasmine/headless/css_template'
|
||||
|
36
lib/jasmine/headless/dust_cache.rb
Normal file
36
lib/jasmine/headless/dust_cache.rb
Normal file
@ -0,0 +1,36 @@
|
||||
require 'execjs'
|
||||
require 'digest/sha1'
|
||||
require 'fileutils'
|
||||
|
||||
module Jasmine
|
||||
module Headless
|
||||
class DustCache < CacheableAction
|
||||
class << self
|
||||
def cache_type
|
||||
"dust"
|
||||
end
|
||||
end
|
||||
|
||||
module Source
|
||||
def self.path
|
||||
@path ||= File.expand_path('../../../../vendor/assets/javascripts/dust-full-for-compile.js', __FILE__)
|
||||
end
|
||||
|
||||
def self.contents
|
||||
@contents ||= File.read(path)
|
||||
end
|
||||
|
||||
def self.context
|
||||
@context ||= ExecJS.compile(contents)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def action
|
||||
template_root = "app/assets/javascripts/templates/"
|
||||
template_name = file.split(template_root).last.split('.',2).first
|
||||
Source.context.call("dust.compile", File.read(file), template_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -5,37 +5,28 @@ module Jasmine::Headless
|
||||
class DustTemplate < Tilt::Template
|
||||
include Jasmine::Headless::FileChecker
|
||||
|
||||
module Source
|
||||
def self.path
|
||||
@path ||= File.expand_path('../../../vendor/assets/javascripts/dust-full-for-compile.js', __FILE__)
|
||||
end
|
||||
self.default_mime_type = 'application/javascript'
|
||||
|
||||
def self.contents
|
||||
@contents ||= File.read(path)
|
||||
end
|
||||
|
||||
def self.context
|
||||
@context ||= ExecJS.compile(contents)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class DustTemplate < ::Tilt::Template
|
||||
|
||||
def self.default_mime_type
|
||||
'application/javascript'
|
||||
end
|
||||
|
||||
def prepare
|
||||
end
|
||||
def prepare; end
|
||||
|
||||
def evaluate(scope, locals, &block)
|
||||
template_root = Dust.config.template_root
|
||||
template_name = file.split(template_root).last.split('.',2).first
|
||||
Source.context.call("dust.compile", data, template_name)
|
||||
if bad_format?(file)
|
||||
alert_bad_format(file)
|
||||
return ''
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user