Dust template #108

Open
ssowonny wants to merge 1 commits from ssowonny/dust into master
5 changed files with 3286 additions and 0 deletions
Showing only changes of commit 00dd6e81f3 - Show all commits

View File

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

View 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

View 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

View File

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

File diff suppressed because it is too large Load Diff