opal-rails 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +12 -4
  3. data/.powder +1 -0
  4. data/.travis.yml +7 -3
  5. data/Appraisals +11 -0
  6. data/CHANGELOG.md +113 -50
  7. data/Gemfile +0 -16
  8. data/README.md +34 -52
  9. data/Rakefile +1 -5
  10. data/app/helpers/opal_helper.rb +2 -2
  11. data/config.ru +10 -0
  12. data/lib/opal/rails.rb +0 -2
  13. data/lib/opal/rails/engine.rb +2 -21
  14. data/lib/opal/rails/version.rb +1 -1
  15. data/opal-rails.gemspec +11 -5
  16. data/spec/spec_helper.rb +1 -14
  17. data/spec/support/test_app.rb +6 -0
  18. data/test_apps/application_controller.rb +52 -0
  19. data/{test_app/app → test_apps}/assets/javascripts/application.js.rb +0 -0
  20. data/{test_app/app → test_apps}/assets/javascripts/bar.rb +0 -0
  21. data/{test_app/app → test_apps}/assets/javascripts/foo.js.rb +0 -0
  22. data/{test_app/app → test_apps}/assets/javascripts/source_map_example.js.rb +0 -0
  23. data/test_apps/rails4.rb +43 -0
  24. data/test_apps/rails5.rb +42 -0
  25. metadata +83 -83
  26. data/app/controllers/opal_spec_controller.rb +0 -38
  27. data/app/views/layouts/opal_spec.html.erb +0 -13
  28. data/app/views/opal_spec/run.html.erb +0 -40
  29. data/lib/opal/rails/spec_builder.rb +0 -92
  30. data/lib/opal/rails/sprockets_cache_key_fix.rb +0 -19
  31. data/lib/tasks/opal-rails_tasks.rake +0 -26
  32. data/spec/integration/in_browser_specs_spec.rb +0 -21
  33. data/test_app/.gitignore +0 -15
  34. data/test_app/Rakefile +0 -7
  35. data/test_app/app/assets/images/rails.png +0 -0
  36. data/test_app/app/assets/stylesheets/application.css +0 -13
  37. data/test_app/app/controllers/application_controller.rb +0 -21
  38. data/test_app/app/views/application/index.html.erb +0 -3
  39. data/test_app/app/views/application/with_assignments.js.opal +0 -8
  40. data/test_app/app/views/layouts/application.html.erb +0 -14
  41. data/test_app/config.ru +0 -4
  42. data/test_app/config/application.rb +0 -75
  43. data/test_app/config/boot.rb +0 -6
  44. data/test_app/config/environment.rb +0 -5
  45. data/test_app/config/environments/development.rb +0 -33
  46. data/test_app/config/environments/production.rb +0 -65
  47. data/test_app/config/environments/test.rb +0 -42
  48. data/test_app/config/initializers/backtrace_silencers.rb +0 -7
  49. data/test_app/config/initializers/inflections.rb +0 -15
  50. data/test_app/config/initializers/mime_types.rb +0 -5
  51. data/test_app/config/initializers/secret_token.rb +0 -8
  52. data/test_app/config/initializers/session_store.rb +0 -8
  53. data/test_app/config/initializers/wrap_parameters.rb +0 -10
  54. data/test_app/config/locales/en.yml +0 -5
  55. data/test_app/config/routes.rb +0 -4
  56. data/test_app/lib/assets/.gitkeep +0 -0
  57. data/test_app/lib/tasks/.gitkeep +0 -0
  58. data/test_app/log/.gitkeep +0 -0
  59. data/test_app/public/404.html +0 -26
  60. data/test_app/public/422.html +0 -26
  61. data/test_app/public/500.html +0 -25
  62. data/test_app/public/favicon.ico +0 -0
  63. data/test_app/public/robots.txt +0 -5
  64. data/test_app/script/rails +0 -6
  65. data/test_app/spec-opal/example_spec.js.rb +0 -7
  66. data/test_app/spec-opal/requires_opal_spec.js.rb +0 -8
  67. data/test_app/spec-opal/spec_helper.rb +0 -3
  68. data/test_app/spec-opal/subdirectory/other_spec.js.rb +0 -7
@@ -1,38 +0,0 @@
1
- require 'opal/rails/spec_builder'
2
- require 'fileutils'
3
- require 'pathname'
4
-
5
- class OpalSpecController < ActionController::Base
6
- helper_method :spec_files, :pattern, :clean_spec_path, :runner_name
7
- helper_method :check_errors_for, :builder
8
-
9
- def run
10
- end
11
-
12
-
13
- private
14
-
15
- # This will deactivate the requirement to precompile assets in this controller
16
- # as specs shouldn't go to production anyway.
17
- def check_errors_for(*)
18
- #noop
19
- end
20
-
21
- def pattern
22
- params[:pattern]
23
- end
24
-
25
- def builder
26
- @builder ||= Opal::Rails::SpecBuilder.new(
27
- spec_location: Rails.application.config.opal.spec_location,
28
- sprockets: Rails.application.config.assets,
29
- pattern: pattern,
30
- )
31
- end
32
-
33
- def runner_name
34
- builder.runner_pathname.basename.to_s.gsub(/(\.js)?\.rb$/, '')
35
- end
36
-
37
- delegate :spec_files, :clean_spec_path, to: :builder
38
- end
@@ -1,13 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <title>Opal Spec Runner</title>
6
- <style>
7
- body { font-family: sans-serif; }
8
- </style>
9
- </head>
10
- <body>
11
- <%= yield %>
12
- </body>
13
- </html>
@@ -1,40 +0,0 @@
1
- <% if pattern.present? %>
2
- <%= link_to 'All specs', opal_spec_path %>
3
- <% end %>
4
-
5
- <h2>Running:</h2>
6
- <ul>
7
- <% spec_files.each do |spec_file| %>
8
- <li>
9
- <% spec_file = clean_spec_path(spec_file) %>
10
- <%= link_to spec_file, opal_spec_path(pattern: spec_file) %>
11
- </li>
12
- <% end %>
13
- </ul>
14
-
15
- <%# The list of all asset dependency %>
16
- <% all_specs = [] %>
17
-
18
- <%# Track root assets that will need to be bootstrapped %>
19
- <% root_assets = {} %>
20
-
21
- <%# Collect all assets with their dependencies %>
22
- <% builder.clean_spec_files.each do |require_path| %>
23
- <% asset = lookup_asset_for_path(require_path, type: :javascript) %>
24
- <% dependency_paths = asset.to_a.map { |a| a.logical_path } %>
25
- <% all_specs += dependency_paths %>
26
- <% root_assets[dependency_paths.last] = require_path %>
27
- <% end %>
28
-
29
- <%# We'll ececute the boot code all at once in the end %>
30
- <% load_code = [] %>
31
-
32
- <%# Add include tags and boot code, we use #uniq as we don't want to source the same asset twice %>
33
- <% all_specs.uniq.each do |asset_path| %>
34
- <%- root_asset = root_assets[asset_path] -%>
35
- <%= javascript_include_tag asset_path, skip_opal_loader: true %>
36
- <%- load_code << javascript_tag(Opal::Processor.load_asset_code(Rails.application.assets, root_asset)) if root_asset -%>
37
- <% end %>
38
-
39
- <%# Boot! %>
40
- <%= load_code.join.html_safe %>
@@ -1,92 +0,0 @@
1
- require 'digest'
2
-
3
- module Opal
4
- module Rails
5
- class SpecBuilder
6
- def initialize(options)
7
- @root = options.fetch(:root) { ::Rails.root }
8
- @pattern = options[:pattern] || '**/*_spec'
9
- @sprockets = options.fetch(:sprockets)
10
- @spec_location = options.fetch(:spec_location)
11
- end
12
-
13
- attr_reader :sprockets, :pattern, :spec_location, :root
14
-
15
- def to_s
16
- builder.build_str main_code, 'opal_spec'
17
- builder.to_s + 'Opal.load("opal_spec");'
18
- end
19
-
20
- def builder
21
- @builder ||= begin
22
- path_finder = Opal::HikePathFinder.new(paths)
23
-
24
- Opal::Builder.new(
25
- compiler_options: Opal::Processor.compiler_options,
26
- stubs: Opal::Processor.stubbed_files,
27
- path_reader: Opal::PathReader.new(path_finder),
28
- )
29
- end
30
- end
31
-
32
- def paths
33
- [
34
- root.join(spec_location).to_s,
35
- runner_dir.to_s,
36
- *Opal.paths,
37
- *sprockets.paths,
38
- ]
39
- end
40
-
41
- def self.runner_dir(root)
42
- root.join('tmp/opal_spec')
43
- end
44
-
45
- def runner_dir
46
- self.class.runner_dir(root)
47
- end
48
-
49
- def main_code
50
- requires.map { |file| "require #{file.inspect}\n" }.join + boot_code
51
- end
52
-
53
- def runner_pathname
54
- runner_dir.join("#{runner_logical_path}.js.rb")
55
- end
56
-
57
- def runner_logical_path
58
- "opal_spec_runner_#{digest}"
59
- end
60
-
61
- def digest
62
- # The digest is cached as it shouldn't change
63
- # for a given builder instance
64
- @digest ||= Digest::SHA1.new.update(requires.join).to_s
65
- end
66
-
67
- def requires
68
- ['opal', 'opal-rspec', *clean_spec_files]
69
- end
70
-
71
- def clean_spec_files
72
- spec_files.map{|f| clean_spec_path(f)}
73
- end
74
-
75
- def boot_code
76
- 'Opal::RSpec::Runner.autorun'
77
- end
78
-
79
- def spec_files
80
- @spec_files ||= pattern.split(':').map { |path| spec_files_for_glob(path) }.flatten
81
- end
82
-
83
- def spec_files_for_glob(glob)
84
- Dir[root.join("#{spec_location}/#{glob}{,.js}.{rb,opal}").to_s]
85
- end
86
-
87
- def clean_spec_path(path)
88
- path.split("#{spec_location}/").flatten.last.gsub(/(\.js)?\.(rb|opal)$/, '')
89
- end
90
- end
91
- end
92
- end
@@ -1,19 +0,0 @@
1
- require 'sprockets/base'
2
- require 'opal/version'
3
- require 'opal/sprockets/processor'
4
-
5
- def (Opal::Processor).version
6
- Opal::VERSION
7
- end unless Opal::Processor.respond_to? :version
8
-
9
- class Sprockets::Base
10
- def cache_key_for(path, options)
11
- processors = attributes_for(path).processors
12
- processors_key = processors.map do |p|
13
- version = p.respond_to?(:version) ? p.version : '0'
14
- "#{p.name}-#{version}"
15
- end.join(':')
16
-
17
- "#{path}:#{options[:bundle] ? '1' : '0'}:#{processors_key}"
18
- end
19
- end
@@ -1,26 +0,0 @@
1
- require 'opal/rspec/rake_task'
2
-
3
- Opal::RSpec::RakeTask.new('opal:spec' => :environment) do |server|
4
- require 'opal/rails/spec_builder'
5
- pattern = ENV['PATTERN'] || nil
6
-
7
- builder = Opal::Rails::SpecBuilder.new(
8
- spec_location: Rails.application.config.opal.spec_location,
9
- sprockets: Rails.application.config.assets,
10
- pattern: pattern,
11
- )
12
-
13
- runner = builder.runner_pathname
14
- runner.dirname.mkpath
15
- runner.open('w') { |f| f << builder.main_code }
16
-
17
- server.sprockets.clear_paths
18
- builder.paths.each { |path| server.append_path path }
19
-
20
- main_name = builder.runner_logical_path
21
-
22
- # Sometimes seems that sprockets will need a moment to pickup the new file
23
- sleep 0.1 unless server.sprockets[main_name]
24
-
25
- server.main = main_name
26
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- feature 'In-browser specs runner' do
4
- scenario 'runs all specs', :js do
5
- visit '/opal_spec'
6
- page.should have_content('example_spec ')
7
- page.should have_content('requires_opal_spec ')
8
- page.should have_content('subdirectory/other_spec ')
9
- page.should have_content('3 examples, 0 failures')
10
- end
11
-
12
- scenario "runs single spec file", :js do
13
- visit '/opal_spec'
14
- click_link 'subdirectory/other_spec'
15
-
16
- page.should_not have_content('example_spec ')
17
- page.should_not have_content('requires_opal_spec ')
18
- page.should have_content('subdirectory/other_spec ')
19
- page.should have_content('1 examples, 0 failures')
20
- end
21
- end
@@ -1,15 +0,0 @@
1
- # See http://help.github.com/ignore-files/ for more about ignoring files.
2
- #
3
- # If you find yourself ignoring temporary files generated by your text editor
4
- # or operating system, you probably want to add a global ignore instead:
5
- # git config --global core.excludesfile ~/.gitignore_global
6
-
7
- # Ignore bundler config
8
- /.bundle
9
-
10
- # Ignore the default SQLite database.
11
- /db/*.sqlite3
12
-
13
- # Ignore all logfiles and tempfiles.
14
- /log/*.log
15
- /tmp
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env rake
2
- # Add your own tasks in files placed in lib/tasks ending in .rake,
3
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
-
5
- require File.expand_path('../config/application', __FILE__)
6
-
7
- TestApp::Application.load_tasks
@@ -1,13 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require_self
12
- *= require_tree .
13
- */
@@ -1,21 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- # protect_from_forgery
3
-
4
- def index
5
- end
6
-
7
- def with_assignments
8
- object = Object.new
9
- def object.as_json options = {}
10
- {:contents => 'json representation'}
11
- end
12
-
13
- @number_var = 1234
14
- @string_var = 'hello'
15
- @array_var = [1,'a']
16
- @hash_var = {:a => 1, :b => 2}
17
- @object_var = object
18
-
19
- render :type => :js, :locals => { :local_var => 'i am local' }
20
- end
21
- end
@@ -1,3 +0,0 @@
1
- <script type="text/ruby">
2
- raise 'pippo'
3
- </script>
@@ -1,8 +0,0 @@
1
- return {
2
- number_var: @number_var,
3
- string_var: @string_var,
4
- array_var: @array_var,
5
- hash_var: @hash_var,
6
- object_var: @object_var,
7
- local_var: local_var
8
- }.to_n
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>TestApp</title>
5
- <%= stylesheet_link_tag "application", :media => "all" %>
6
- <%= javascript_include_tag "application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run TestApp::Application
@@ -1,75 +0,0 @@
1
- require 'fileutils'
2
- # Clear assets cache to avoid false errors
3
- FileUtils.rmtree(File.expand_path('../../tmp/cache/assets'))
4
-
5
- require File.expand_path('../boot', __FILE__)
6
-
7
- # Pick the frameworks you want:
8
- # require "active_record/railtie"
9
- require "action_controller/railtie"
10
- require "action_mailer/railtie"
11
- require "active_resource/railtie" unless Rails.version.to_i == 4
12
- require "sprockets/railtie"
13
- require "rails/test_unit/railtie"
14
-
15
- if defined?(Bundler)
16
- # If you precompile assets before deploying to production, use this line
17
- Bundler.require(*Rails.groups(:assets => %w(development test)))
18
- # If you want your assets lazily compiled in production, use this line
19
- # Bundler.require(:default, :assets, Rails.env)
20
- end
21
-
22
- module TestApp
23
- class Application < Rails::Application
24
- # Settings in config/environments/* take precedence over those specified here.
25
- # Application configuration should go into files in config/initializers
26
- # -- all .rb files in that directory are automatically loaded.
27
-
28
- # Custom directories with classes and modules you want to be autoloadable.
29
- # config.autoload_paths += %W(#{config.root}/extras)
30
-
31
- # Only load the plugins named here, in the order given (default is alphabetical).
32
- # :all can be used as a placeholder for all plugins not explicitly named.
33
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
34
-
35
- # Activate observers that should always be running.
36
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
37
-
38
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
39
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
40
- # config.time_zone = 'Central Time (US & Canada)'
41
-
42
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
43
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
44
- # config.i18n.default_locale = :de
45
-
46
- # Configure the default encoding used in templates for Ruby 1.9.
47
- config.encoding = "utf-8"
48
-
49
- # Configure sensitive parameters which will be filtered from the log file.
50
- config.filter_parameters += [:password]
51
-
52
- # Enable escaping HTML in JSON.
53
- config.active_support.escape_html_entities_in_json = true
54
-
55
- # Use SQL instead of Active Record's schema dumper when creating the database.
56
- # This is necessary if your schema can't be completely dumped by the schema dumper,
57
- # like if you have constraints or database-specific column types
58
- # config.active_record.schema_format = :sql
59
-
60
- # Enforce whitelist mode for mass assignment.
61
- # This will create an empty whitelist of attributes available for mass-assignment for all models
62
- # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
63
- # parameters by using an attr_accessible or attr_protected declaration.
64
- # config.active_record.whitelist_attributes = true
65
-
66
- # Enable the asset pipeline
67
- config.assets.enabled = true
68
-
69
- # Version of your assets, change this if you want to expire all your assets
70
- config.assets.version = '1.0'
71
-
72
- # Disabled by default, we need it for tests
73
- config.opal.source_map_enabled = true
74
- end
75
- end
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
-
3
- # Set up gems listed in the Gemfile.
4
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __FILE__)
5
-
6
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
5
- TestApp::Application.initialize!