add ember-script support #179

Open
heartsentwined wants to merge 1 commits from heartsentwined/ember-script into master
9 changed files with 74 additions and 5 deletions

View File

@ -6,6 +6,7 @@ $: << File.expand_path('../../lib', __FILE__)
require 'jasmine-headless-webkit' require 'jasmine-headless-webkit'
require 'coffee-script' require 'coffee-script'
require 'ember_script'
Jasmine::Headless::CommandLine.run! Jasmine::Headless::CommandLine.run!

View File

@ -22,6 +22,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'jasmine-core' s.add_runtime_dependency 'jasmine-core'
s.add_runtime_dependency 'coffee-script' s.add_runtime_dependency 'coffee-script'
s.add_runtime_dependency 'ember_script'
s.add_runtime_dependency 'rainbow' s.add_runtime_dependency 'rainbow'
s.add_runtime_dependency 'multi_json', '>= 1.2.0' s.add_runtime_dependency 'multi_json', '>= 1.2.0'
s.add_runtime_dependency 'sprockets' s.add_runtime_dependency 'sprockets'

View File

@ -1,7 +1,7 @@
module JasmineMixin module JasmineMixin
JASMINE_PROGRAM = File.expand_path('../../../bin/jasmine-headless-webkit', __FILE__) JASMINE_PROGRAM = File.expand_path('../../../bin/jasmine-headless-webkit', __FILE__)
JAVASCRIPT_EXTENSIONS = %w{js coffee} JAVASCRIPT_EXTENSIONS = %w{js coffee em}
def self.included(klass) def self.included(klass)
klass::ALL_HOOKS << [ :run_jasmine, :ran_jasmine ] klass::ALL_HOOKS << [ :run_jasmine, :ran_jasmine ]
@ -92,7 +92,7 @@ module JasmineMixin
end end
def setup_jasmine_project_mappings def setup_jasmine_project_mappings
add_mapping(%r{spec/javascripts/.*_spec\.(js|coffee)}) { |filename, _| add_mapping(%r{spec/javascripts/.*_spec\.(js|coffee|em)}) { |filename, _|
filename filename
} }
@ -103,6 +103,10 @@ module JasmineMixin
add_mapping(%r{app/coffeescripts/(.*)\.coffee}) { |_, m| add_mapping(%r{app/coffeescripts/(.*)\.coffee}) { |_, m|
files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$}) files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$})
} }
add_mapping(%r{app/emberscripts/(.*)\.em}) { |_, m|
files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$})
}
end end
def add_javascript_extensions(*extensions) def add_javascript_extensions(*extensions)

View File

@ -2,12 +2,13 @@ require 'pathname'
module Jasmine module Jasmine
module Headless module Headless
EXCLUDED_FORMATS = %w{less sass scss erb str} EXCLUDED_FORMATS = %w{less sass scss erb str}
autoload :CommandLine, 'jasmine/headless/command_line' autoload :CommandLine, 'jasmine/headless/command_line'
autoload :CoffeeScriptCache, 'jasmine/headless/coffee_script_cache' autoload :CoffeeScriptCache, 'jasmine/headless/coffee_script_cache'
autoload :EmberScriptCache, 'jasmine/headless/ember_script_cache'
autoload :SpecFileAnalyzer, 'jasmine/headless/spec_file_analyzer' autoload :SpecFileAnalyzer, 'jasmine/headless/spec_file_analyzer'
autoload :CacheableAction, 'jasmine/headless/cacheable_action' autoload :CacheableAction, 'jasmine/headless/cacheable_action'
autoload :VERSION, 'jasmine/headless/version' autoload :VERSION, 'jasmine/headless/version'
@ -19,10 +20,11 @@ module Jasmine
autoload :UniqueAssetList, 'jasmine/headless/unique_asset_list' autoload :UniqueAssetList, 'jasmine/headless/unique_asset_list'
autoload :TemplateWriter, 'jasmine/headless/template_writer' autoload :TemplateWriter, 'jasmine/headless/template_writer'
autoload :FileChecker, 'jasmine/headless/file_checker' autoload :FileChecker, 'jasmine/headless/file_checker'
autoload :CoffeeTemplate, 'jasmine/headless/coffee_template' autoload :CoffeeTemplate, 'jasmine/headless/coffee_template'
autoload :EmberScriptTemplate, 'jasmine/headless/ember_script_template'
autoload :JSTemplate, 'jasmine/headless/js_template' autoload :JSTemplate, 'jasmine/headless/js_template'
autoload :JSTTemplate, 'jasmine/headless/jst_template' autoload :JSTTemplate, 'jasmine/headless/jst_template'
autoload :CSSTemplate, 'jasmine/headless/css_template' autoload :CSSTemplate, 'jasmine/headless/css_template'

View File

@ -3,6 +3,7 @@ module Jasmine::Headless
class << self class << self
def run! def run!
require 'coffee-script' require 'coffee-script'
require 'ember_script'
require 'rainbow' require 'rainbow'
begin begin
@ -19,6 +20,8 @@ module Jasmine::Headless
end end
rescue CoffeeScript::CompilationError rescue CoffeeScript::CompilationError
exit 1 exit 1
rescue ExecJS::ProgramError
exit 1
rescue StandardError => e rescue StandardError => e
$stderr.puts "[%s] %s (%s)" % [ "jasmine-headless-webkit".color(:red), e.message.color(:white), e.class.name.color(:yellow) ] $stderr.puts "[%s] %s (%s)" % [ "jasmine-headless-webkit".color(:red), e.message.color(:white), e.class.name.color(:yellow) ]
$stderr.puts e.backtrace.collect { |line| " #{line}" }.join("\n") $stderr.puts e.backtrace.collect { |line| " #{line}" }.join("\n")

View File

@ -0,0 +1,20 @@
require 'ember_script'
require 'digest/sha1'
require 'fileutils'
module Jasmine
module Headless
class EmberScriptCache < CacheableAction
class << self
def cache_type
"ember_script"
end
end
def action
EmberScript.compile(File.read(file))
end
end
end
end

View File

@ -0,0 +1,36 @@
require 'tilt/template'
require 'rainbow'
module Jasmine::Headless
class EmberScriptTemplate < Tilt::Template
include Jasmine::Headless::FileChecker
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::EmberScriptCache.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 ExecJS::ProgramError => ne
puts "[%s] %s: %s" % [ 'emberscript'.color(:red), file.color(:yellow), "#{ne.message}".color(:white) ]
raise ne
rescue StandardError => e
puts "[%s] Error in compiling file: %s" % [ 'emberscript'.color(:red), file.color(:yellow) ]
raise e
end
end
end
end

View File

@ -150,6 +150,7 @@ module Jasmine::Headless
end end
register_engine '.coffee', Jasmine::Headless::CoffeeTemplate register_engine '.coffee', Jasmine::Headless::CoffeeTemplate
register_engine '.em', Jasmine::Headless::EmberScriptTemplate
register_engine '.js', Jasmine::Headless::JSTemplate register_engine '.js', Jasmine::Headless::JSTemplate
register_engine '.css', Jasmine::Headless::CSSTemplate register_engine '.css', Jasmine::Headless::CSSTemplate
register_engine '.jst', Jasmine::Headless::JSTTemplate register_engine '.jst', Jasmine::Headless::JSTTemplate

View File

@ -1,6 +1,7 @@
require 'fileutils' require 'fileutils'
require 'coffee-script' require 'coffee-script'
require 'ember_script'
require 'rainbow' require 'rainbow'
require 'yaml' require 'yaml'