Permalink
Browse files

merge sprockets code into mainline, please report bugs

  • Loading branch information...
2 parents a18100b + edf5a49 commit 3911041866cf441b8086064e327a1569957b03d1 @johnbintz committed Nov 23, 2011
Showing with 986 additions and 490 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 Gemfile
  3. +19 −0 Rakefile
  4. +2 −22 bin/jasmine-headless-webkit
  5. +5 −4 jasmine-headless-webkit.gemspec
  6. +20 −0 lib/digest/jasmine_test.rb
  7. +4 −4 lib/jasmine-headless-webkit.rb
  8. +0 −176 lib/jasmine/files_list.rb
  9. +8 −0 lib/jasmine/headless.rb
  10. +30 −0 lib/jasmine/headless/coffee_template.rb
  11. +31 −0 lib/jasmine/headless/command_line.rb
  12. +14 −0 lib/jasmine/headless/css_template.rb
  13. +275 −0 lib/jasmine/headless/files_list.rb
  14. +18 −0 lib/jasmine/headless/js_template.rb
  15. +10 −0 lib/jasmine/headless/jst_template.rb
  16. +9 −4 lib/jasmine/headless/runner.rb
  17. +2 −21 lib/jasmine/headless/task.rb
  18. +9 −1 skel/template.html.erb
  19. +18 −0 spec/bin/jasmine-headless-webkit_spec.rb
  20. +2 −0 spec/jasmine/with_sprockets_includes/assets/application.js
  21. +6 −0 spec/jasmine/with_sprockets_includes/assets/things/code.js
  22. +2 −0 spec/jasmine/with_sprockets_includes/assets/things/required.js
  23. +2 −0 spec/jasmine/with_sprockets_includes/assets/things/subcode/more_code.js
  24. +1 −0 spec/jasmine/with_sprockets_includes/assets/things/templates/that.jst.ejs
  25. +2 −0 spec/jasmine/with_sprockets_includes/assets/things/templates/this.jst
  26. +1 −0 spec/jasmine/with_sprockets_includes/spec/spec_helper.js
  27. +9 −0 spec/jasmine/with_sprockets_includes/spec/things/code_spec.js
  28. +12 −0 spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml
  29. +0 −248 spec/lib/jasmine/files_list_spec.rb
  30. +55 −0 spec/lib/jasmine/headless/coffee_template_spec.rb
  31. +25 −0 spec/lib/jasmine/headless/css_template_spec.rb
  32. +179 −0 spec/lib/jasmine/headless/files_list_spec.rb
  33. +31 −0 spec/lib/jasmine/headless/js_template_spec.rb
  34. +21 −0 spec/lib/jasmine/headless/jst_template_spec.rb
  35. +8 −4 spec/lib/jasmine/headless/template_writer_spec.rb
  36. +36 −0 spec/spec_helper.rb
  37. +1 −1 vendor/assets/coffeescripts/headless_reporter_result.coffee
  38. +1 −0 vendor/assets/coffeescripts/intense.coffee
  39. +13 −0 vendor/assets/coffeescripts/jasmine-extensions.coffee
  40. +31 −1 vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee
  41. +1 −1 vendor/assets/javascripts/headless_reporter_result.js
  42. +5 −1 vendor/assets/javascripts/intense.js
  43. +26 −1 vendor/assets/javascripts/jasmine-extensions.js
  44. +37 −1 vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js
View
@@ -14,3 +14,4 @@ jhw-test
.jhw-cache/
_site/
jhw.*.html
+coverage/
View
@@ -15,3 +15,7 @@ gem 'mocha', '0.9.12'
gem 'guard-jasmine-headless-webkit', :git => 'git://github.com/johnbintz/guard-jasmine-headless-webkit.git'
gem 'facter'
+gem 'jquery-rails'
+gem 'ejs'
+
+gem 'simplecov'
View
@@ -43,3 +43,22 @@ task :build_runner do
end
end
+desc "Generate vendored JS"
+task :generate_js do
+ require 'sprockets'
+
+ source = 'vendor/assets/coffeescripts'
+ target = 'vendor/assets/javascripts'
+
+ env = Sprockets::Environment.new { |s| s.append_path 'vendor/assets/coffeescripts' }
+
+ Dir[File.join(File.expand_path(source), '*.coffee')].each do |file|
+ file_target = file.gsub(source, target).gsub('.coffee', '.js')
+ puts "#{file} => #{file_target}"
+
+ File.open(file_target, 'wb') do |fh|
+ fh.print env.find_asset(File.expand_path(file)).to_s
+ end
+ end
+end
+
@@ -1,31 +1,11 @@
#!/usr/bin/env ruby
require 'rubygems'
-require 'rainbow'
-def gem_dir
- File.expand_path('../..', __FILE__)
-end
+$: << File.expand_path('../../lib', __FILE__)
-$:.unshift(File.join(gem_dir, 'lib'))
require 'jasmine-headless-webkit'
require 'coffee-script'
-begin
- options = Jasmine::Headless::Options.from_command_line
- runner = Jasmine::Headless::Runner.new(options)
-
- if options[:do_list]
- files_list = Jasmine::FilesList.new(:config => runner.jasmine_config)
- files_list.files.each { |file| puts file }
- else
- exit runner.run
- end
-rescue CoffeeScript::CompilationError
- 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")
- exit 1
-end
+Jasmine::Headless::CommandLine.run!
@@ -20,8 +20,9 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_dependency 'jasmine-core', '~>1.1.beta'
- s.add_dependency 'coffee-script', '>= 2.2'
- s.add_dependency 'rainbow'
- s.add_dependency 'multi_json'
+ s.add_runtime_dependency 'jasmine-core', '~> 1.1'
+ s.add_runtime_dependency 'coffee-script'
+ s.add_runtime_dependency 'rainbow'
+ s.add_runtime_dependency 'multi_json'
+ s.add_runtime_dependency 'sprockets', '~> 2'
end
View
@@ -0,0 +1,20 @@
+module Digest
+ class JasmineTest
+ def self.file(file)
+ new
+ end
+
+ def file(file)
+ self
+ end
+
+ def hexdigest
+ 'test'
+ end
+
+ def update(prefix)
+ self
+ end
+ end
+end
+
@@ -1,7 +1,7 @@
-module Jasmine
- autoload :FilesList, 'jasmine/files_list'
-end
-
require 'jasmine/headless'
require 'jasmine/headless/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
+module Digest
+ autoload :JasmineTest, 'digest/jasmine_test'
+end
+
View
@@ -1,176 +0,0 @@
-require 'jasmine-core'
-require 'time'
-require 'multi_json'
-
-module Jasmine
- class FilesList
- attr_reader :files, :spec_files, :filtered_files, :spec_outside_scope
-
- class << self
- def find_vendored_asset_paths(*names)
- require 'rubygems'
-
- raise StandardError.new("A newer version of Rubygems is required to use vendored assets. Please upgrade.") if !Gem::Specification.respond_to?(:map)
- all_spec_files.find_all do |file|
- names.any? { |name| file["/#{name}.js"] }
- end
- end
-
- def all_spec_files
- @all_spec_files ||= Gem::Specification.map { |spec| spec.files.find_all { |file|
- file["vendor/assets/javascripts"]
- }.compact.collect { |file| File.join(spec.gem_dir, file) } }.flatten
- end
- end
-
- DEFAULT_FILES = [
- File.join(Jasmine::Core.path, "jasmine.js"),
- File.join(Jasmine::Core.path, "jasmine-html.js"),
- File.join(Jasmine::Core.path, "jasmine.css")
- ] + %w{jasmine-extensions intense headless_reporter_result jasmine.HeadlessConsoleReporter jsDump beautify-html}.collect { |name|
- Jasmine::Headless.root.join("vendor/assets/javascripts/#{name}.js").to_s
- }
-
- PLEASE_WAIT_IM_WORKING_TIME = 2
-
- def initialize(options = {})
- @options = options
- @files = DEFAULT_FILES.dup
- @filtered_files = @files.dup
- @spec_outside_scope = false
- @spec_files = []
- use_config! if config?
- end
-
- def has_spec_outside_scope?
- @spec_outside_scope
- end
-
- def filtered?
- files != filtered_files
- end
-
- def files_to_html
- to_html(files)
- end
-
- def filtered_files_to_html
- to_html(filtered_files)
- end
-
- def spec_file_line_numbers
- @spec_file_line_numbers ||= Hash[@spec_files.collect { |file|
- if File.exist?(file)
- if !(lines = Jasmine::Headless::SpecFileAnalyzer.for(file)).empty?
- [ file, lines ]
- end
- else
- nil
- end
- }.compact]
- end
-
- private
- def to_html(files)
- alert_time = Time.now + PLEASE_WAIT_IM_WORKING_TIME
-
- files.collect { |file|
- if alert_time && alert_time < Time.now
- puts "Rebuilding cache, please wait..."
- alert_time = nil
- end
-
- source = nil
-
- result = case File.extname(file)
- when '.coffee'
- begin
- cache = Jasmine::Headless::CoffeeScriptCache.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 CoffeeScript::CompilationError => ne
- puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), ne.message.to_s.color(:white) ]
- raise ne
- rescue StandardError => e
- puts "[%s] Error in compiling one of the followng: %s" % [ 'coffeescript'.color(:red), files.join(' ').color(:yellow) ]
- raise e
- end
- when '.js'
- %{<script type="text/javascript" src="#{file}"></script>}
- when '.css'
- %{<link rel="stylesheet" href="#{file}" type="text/css" />}
- end
-
- result
- }.flatten.compact.reject(&:empty?)
- end
-
- def spec_filter
- return @spec_filter if @spec_filter
-
- @spec_filter = begin
- if @options[:only]
- @options[:only].collect { |path| expanded_dir(path) }.flatten
- else
- []
- end
- end
- end
-
- def use_config!
- @filtered_files = @files.dup
-
- data = @options[:config].dup
- [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'vendored_helpers' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].each do |searches, root|
- if data[searches]
- case searches
- when 'vendored_helpers'
- data[searches].each do |name|
- found_files = self.class.find_vendored_asset_path(name)
-
- @files += found_files
- @filtered_files += found_files
- end
- else
- data[searches].flatten.collect do |search|
- path = search
- path = File.join(data[root], path) if data[root]
- found_files = expanded_dir(path) - @files
-
- @files += found_files
-
- if searches == 'spec_files'
- @spec_files += spec_filter.empty? ? found_files : (found_files & spec_filter)
- end
-
- @filtered_files += begin
- if searches == 'spec_files'
- @spec_outside_scope = ((spec_filter | found_files).sort != found_files.sort)
- spec_filter.empty? ? found_files : (spec_filter || found_files)
- else
- found_files
- end
- end
- end
- end
- end
- end
- end
-
- def config?
- @options[:config]
- end
-
- def expanded_dir(path)
- Dir[path].collect { |file| File.expand_path(file) }
- end
- end
-end
-
View
@@ -1,16 +1,24 @@
require 'pathname'
module Jasmine::Headless
+ autoload :CommandLine, 'jasmine/headless/command_line'
+
autoload :CoffeeScriptCache, 'jasmine/headless/coffee_script_cache'
autoload :SpecFileAnalyzer, 'jasmine/headless/spec_file_analyzer'
autoload :CacheableAction, 'jasmine/headless/cacheable_action'
autoload :VERSION, 'jasmine/headless/version'
autoload :Runner, 'jasmine/headless/runner'
autoload :Options, 'jasmine/headless/options'
autoload :Task, 'jasmine/headless/task'
+ autoload :FilesList, 'jasmine/headless/files_list'
autoload :TemplateWriter, 'jasmine/headless/template_writer'
+ autoload :CoffeeTemplate, 'jasmine/headless/coffee_template'
+ autoload :JSTemplate, 'jasmine/headless/js_template'
+ autoload :JSTTemplate, 'jasmine/headless/jst_template'
+ autoload :CSSTemplate, 'jasmine/headless/css_template'
+
autoload :Report, 'jasmine/headless/report'
autoload :ReportMessage, 'jasmine/headless/report_message'
@@ -0,0 +1,30 @@
+require 'tilt/template'
+require 'rainbow'
+
+module Jasmine::Headless
+ class CoffeeTemplate < Tilt::Template
+ self.default_mime_type = 'application/javascript'
+
+ def prepare ; end
+
+ def evaluate(scope, locals, &block)
+ begin
+ cache = Jasmine::Headless::CoffeeScriptCache.new(file)
+ source = cache.handle
+ if cache.cached?
+ %{<script from="jhw" type="text/javascript" src="#{cache.cache_file}"></script>
+ <script type="text/javascript">window.CSTF['#{File.split(cache.cache_file).last}'] = '#{file}';</script>}
+ else
+ %{<script from="jhw" type="text/javascript">#{source}</script>}
+ end
+ rescue CoffeeScript::CompilationError => ne
+ puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), "#{ne.message}".color(:white) ]
+ raise ne
+ rescue StandardError => e
+ puts "[%s] Error in compiling file: %s" % [ 'coffeescript'.color(:red), file.color(:yellow) ]
+ raise e
+ end
+ end
+ end
+end
+
@@ -0,0 +1,31 @@
+module Jasmine::Headless
+ class CommandLine
+ class << self
+ def run!
+ require 'coffee-script'
+ require 'rainbow'
+
+ begin
+ options = Options.from_command_line
+ runner = Runner.new(options)
+
+ if options[:do_list]
+ FilesList.reset!
+
+ files_list = FilesList.new(:config => runner.jasmine_config)
+ files_list.files.each { |file| puts file }
+ else
+ exit runner.run
+ end
+ rescue CoffeeScript::CompilationError
+ 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")
+ exit 1
+ end
+ end
+ end
+ end
+end
+
@@ -0,0 +1,14 @@
+require 'tilt/template'
+
+module Jasmine::Headless
+ class CSSTemplate < Tilt::Template
+ self.default_mime_type = 'text/css'
+
+ def prepare ; end
+
+ def evaluate(scope, locals, &block)
+ file ? %{<link rel="stylesheet" href="#{file}" type="text/css" />} : data
+ end
+ end
+end
+
Oops, something went wrong.

0 comments on commit 3911041

Please sign in to comment.