Compare commits

..

1 Commits

Author SHA1 Message Date
heartsentwined
ec0aa8d320 add ember-script support 2013-04-22 15:14:46 +08:00
10 changed files with 75 additions and 6 deletions

View File

@ -1,4 +1,4 @@
_This project is dead. You should use [Karma](http://karma-runner.github.io/) instead. I do._
_I am looking for a new maintainer for this project. Please contact me via GitHub if you're interested._
# Jasmine Headless WebKit runner

View File

@ -6,6 +6,7 @@ $: << File.expand_path('../../lib', __FILE__)
require 'jasmine-headless-webkit'
require 'coffee-script'
require 'ember_script'
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 'coffee-script'
s.add_runtime_dependency 'ember_script'
s.add_runtime_dependency 'rainbow'
s.add_runtime_dependency 'multi_json', '>= 1.2.0'
s.add_runtime_dependency 'sprockets'

View File

@ -1,7 +1,7 @@
module JasmineMixin
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)
klass::ALL_HOOKS << [ :run_jasmine, :ran_jasmine ]
@ -92,7 +92,7 @@ module JasmineMixin
end
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
}
@ -103,6 +103,10 @@ module JasmineMixin
add_mapping(%r{app/coffeescripts/(.*)\.coffee}) { |_, m|
files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$})
}
add_mapping(%r{app/emberscripts/(.*)\.em}) { |_, m|
files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$})
}
end
def add_javascript_extensions(*extensions)

View File

@ -8,6 +8,7 @@ module Jasmine
autoload :CommandLine, 'jasmine/headless/command_line'
autoload :CoffeeScriptCache, 'jasmine/headless/coffee_script_cache'
autoload :EmberScriptCache, 'jasmine/headless/ember_script_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 :EmberScriptTemplate, 'jasmine/headless/ember_script_template'
autoload :JSTemplate, 'jasmine/headless/js_template'
autoload :JSTTemplate, 'jasmine/headless/jst_template'
autoload :CSSTemplate, 'jasmine/headless/css_template'

View File

@ -3,6 +3,7 @@ module Jasmine::Headless
class << self
def run!
require 'coffee-script'
require 'ember_script'
require 'rainbow'
begin
@ -19,6 +20,8 @@ module Jasmine::Headless
end
rescue CoffeeScript::CompilationError
exit 1
rescue ExecJS::ProgramError
exit 1
rescue StandardError => e
$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")

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
register_engine '.coffee', Jasmine::Headless::CoffeeTemplate
register_engine '.em', Jasmine::Headless::EmberScriptTemplate
register_engine '.js', Jasmine::Headless::JSTemplate
register_engine '.css', Jasmine::Headless::CSSTemplate
register_engine '.jst', Jasmine::Headless::JSTTemplate

View File

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