add dust template engine to support .dust files
This commit is contained in:
parent
282ed40264
commit
00dd6e81f3
@ -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'
|
||||
|
30
lib/jasmine/headless/dust_cache.rb
Normal file
30
lib/jasmine/headless/dust_cache.rb
Normal file
@ -0,0 +1,30 @@
|
||||
require 'execjs'
|
||||
require 'digest/sha1'
|
||||
require 'fileutils'
|
||||
|
||||
module Jasmine
|
||||
module Headless
|
||||
|
||||
class DustCache < CacheableAction
|
||||
|
||||
class << self
|
||||
def cache_type
|
||||
"dust"
|
||||
end
|
||||
end
|
||||
|
||||
def action
|
||||
@path ||= File.expand_path('../../../../vendor/assets/javascripts/dust-full-for-compile.js', __FILE__)
|
||||
@contents ||= File.read(@path)
|
||||
@context ||= ExecJS.compile(@contents)
|
||||
|
||||
template_root = DustTemplate.template_root
|
||||
template_root = template_root + '/' if template_root[ template_root.length - 1 ].chr != '/'
|
||||
template_name = file.split(template_root).last.split('.',2).first
|
||||
@context.call("dust.compile", File.read(file), template_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
41
lib/jasmine/headless/dust_template.rb
Normal file
41
lib/jasmine/headless/dust_template.rb
Normal file
@ -0,0 +1,41 @@
|
||||
require 'tilt/template'
|
||||
require 'execjs'
|
||||
|
||||
module Jasmine::Headless
|
||||
class DustTemplate < Tilt::Template
|
||||
include Jasmine::Headless::FileChecker
|
||||
|
||||
class << self
|
||||
def template_root=(root)
|
||||
@template_root = root
|
||||
end
|
||||
def template_root
|
||||
@template_root || "app/assets/javascripts/templates/"
|
||||
end
|
||||
end
|
||||
|
||||
self.default_mime_type = 'application/javascript'
|
||||
|
||||
def prepare; end
|
||||
|
||||
def evaluate(scope, locals, &block)
|
||||
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
|
@ -66,6 +66,7 @@ module Jasmine::Headless
|
||||
register_engine '.js', Jasmine::Headless::JSTemplate
|
||||
register_engine '.css', Jasmine::Headless::CSSTemplate
|
||||
register_engine '.jst', Jasmine::Headless::JSTTemplate
|
||||
register_engine '.dust', Jasmine::Headless::DustTemplate
|
||||
end
|
||||
end
|
||||
|
||||
@ -224,6 +225,9 @@ module Jasmine::Headless
|
||||
add_files(@searches[type] = data.flatten, type, send(SEARCH_ROOTS[type]))
|
||||
end
|
||||
end
|
||||
|
||||
# config dust template
|
||||
Jasmine::Headless::DustTemplate.template_root = @config['template_dir']
|
||||
end
|
||||
|
||||
def add_files(patterns, type, dirs)
|
||||
|
3209
vendor/assets/javascripts/dust-full-for-compile.js
vendored
Normal file
3209
vendor/assets/javascripts/dust-full-for-compile.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user