ok, use coffee-script and external compiler, the html thing doesn't work

This commit is contained in:
John Bintz 2011-05-06 17:07:44 -04:00
parent 928decefd7
commit 234f49e583
4 changed files with 14 additions and 13 deletions

View File

@ -44,9 +44,8 @@ These options can also be placed into a `.jasmine-headless-webkit` file in your
### CoffeeScript Support
`jasmine-headless-webkit` brings in the `coffee-script-source` gem and allows you to run CoffeeScript
files without needing compilation. It uses [the `<script type="text/coffeescript">` method](http://jashkenas.github.com/coffee-script/#scripts) of loading
CoffeeScript. All you need to do is configure your `jasmine.yml` file to look for .coffee files:
`jasmine-headless-webkit` brings in the `coffee-script` gem and compiles & injects all CoffeeScript into the
generated HTML page. All you need to do is configure your `jasmine.yml` file to look for .coffee files:
src_files:
- app/assets/javascripts/**/*.coffee

View File

@ -10,13 +10,12 @@ require 'getoptlong'
require 'rubygems'
gem 'jasmine'
gem 'coffee-script-source'
gem 'coffee-script'
require 'jasmine'
require 'coffee_script/source'
require 'coffee-script'
require 'jasmine/cli'
include Jasmine::CLI
opts = GetoptLong.new(
@ -53,8 +52,7 @@ puts "Running Jasmine specs..."
files = [
'file://' + File.join(Jasmine.root, 'lib/jasmine.js'),
'file://' + File.join(Jasmine.root, 'lib/jasmine-html.js'),
'file://' + CoffeeScript::Source.bundled_path,
'file://' + File.join(Jasmine.root, 'lib/jasmine-html.js')
]
files += [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].collect do |searches, root|
@ -75,7 +73,7 @@ files = files.flatten.compact.collect { |file|
when '.js'
%{<script type="text/javascript" src="#{file}"></script>}
when '.coffee'
%{<script type="text/coffeescript" src="#{file}"></script>}
%{<script type="text/javascript">#{CoffeeScript.compile File.read(file)}</script>}
when '.css'
%{<link rel="stylesheet" href="#{file}" type="text/css" />}
end

View File

@ -21,5 +21,5 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.add_dependency 'jasmine'
s.add_dependency 'coffee-script-source'
s.add_dependency 'coffee-script'
end

View File

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