opal-rails 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +38 -0
  3. data/.gitignore +1 -0
  4. data/Appraisals +10 -14
  5. data/CHANGELOG.md +62 -0
  6. data/Gemfile +7 -4
  7. data/README.md +45 -9
  8. data/app/helpers/opal_helper.rb +6 -5
  9. data/bin/rackup +29 -0
  10. data/bin/rails +8 -0
  11. data/bin/rails-engine +13 -0
  12. data/bin/rails-sandbox +18 -0
  13. data/bin/rake +29 -0
  14. data/bin/rspec +29 -0
  15. data/bin/sandbox +39 -0
  16. data/bin/sandbox-setup +14 -0
  17. data/bin/setup +8 -0
  18. data/gemfiles/rails_6_0_opal_1_0.gemfile +9 -0
  19. data/gemfiles/rails_6_0_opal_1_1.gemfile +9 -0
  20. data/gemfiles/rails_6_1_opal_1_0.gemfile +9 -0
  21. data/gemfiles/rails_6_1_opal_1_1.gemfile +9 -0
  22. data/lib/assets/javascripts/opal_ujs.js.rb +1 -4
  23. data/lib/generators/opal/assets/assets_generator.rb +7 -0
  24. data/lib/{rails/generators → generators}/opal/assets/templates/javascript.js.rb +0 -0
  25. data/lib/generators/opal/install/USAGE +8 -0
  26. data/lib/generators/opal/install/install_generator.rb +12 -0
  27. data/lib/generators/opal/install/templates/application.js.rb +12 -0
  28. data/lib/opal/rails.rb +0 -4
  29. data/lib/opal/rails/engine.rb +9 -2
  30. data/lib/opal/rails/template_handler.rb +16 -7
  31. data/lib/opal/rails/version.rb +1 -1
  32. data/opal-rails.gemspec +45 -40
  33. data/spec/helpers/opal_helper_spec.rb +23 -9
  34. data/spec/integration/assigns_spec.rb +58 -2
  35. data/spec/integration/source_map_spec.rb +9 -5
  36. data/spec/support/capybara.rb +2 -0
  37. data/test_apps/{application_controller.rb → app/application_controller.rb} +1 -1
  38. data/test_apps/app/assets/config/manifest.js +1 -0
  39. data/test_apps/{assets → app/assets}/javascripts/application.js.rb +1 -0
  40. data/test_apps/{assets → app/assets}/javascripts/bar.rb +0 -0
  41. data/test_apps/{assets → app/assets}/javascripts/foo.js.rb +0 -0
  42. data/test_apps/{assets → app/assets}/javascripts/source_map_example.js.rb +0 -0
  43. data/test_apps/{assets → app/assets}/javascripts/with_assignments.js.rb +0 -0
  44. data/test_apps/{rails5.rb → rails6.rb} +1 -3
  45. metadata +49 -84
  46. data/.travis.yml +0 -42
  47. data/gemfiles/rails_5_1_opal_1_0.gemfile +0 -12
  48. data/gemfiles/rails_5_1_opal_master.gemfile +0 -11
  49. data/gemfiles/rails_5_2_opal_1_0.gemfile +0 -12
  50. data/gemfiles/rails_5_2_opal_master.gemfile +0 -11
  51. data/lib/rails/generators/opal/assets/assets_generator.rb +0 -12
  52. data/spec/integration/template_spec.rb +0 -9
  53. data/test_apps/rails4.rb +0 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9327fdd3f720f1807ebcde09f2901c1e017615c9fa8f4f910ec6483ade3216c6
4
- data.tar.gz: 0c014f66ab2633363b0ab40afa1b72b4e2c0f09d2e524a202ace14b61d979080
3
+ metadata.gz: 49586db0f49f4f31e3e289e1f813275e1b81ab083aa5e771887e5e93bc08b83b
4
+ data.tar.gz: 02d8db2458c45f4fe2554028571288b2664f8cfc64bba320a62d59a9ea120567
5
5
  SHA512:
6
- metadata.gz: 7e667155ae6975139b8f1e1359733a61cf9b511e591a1663a7ed8a2b2068e9ae7be506798842f48091fd311394c7fcbed6d222c2f1f44f995d06957007adc7e9
7
- data.tar.gz: 190642ae14e588b7875d9698f19f1c7b532858cf217d184df759b64d67bfb694d4865cd1d6c1f94915bd7ba1347d6644e081cabd43b7769af4dd4d821647bb50
6
+ metadata.gz: ec6e2d6ce3226094ef31bcb2b75a5317b7d0a1e05cb3af627022dfd00697787ad1ed6fdd739cfb485a741685e4cfd8b746d3fb29a1e4a29b6bcc1b6163aef362
7
+ data.tar.gz: eac8d359fbd8589edd16c7df490a619fe9d2e3a09640ab0d1d14ece16cd5f6d1fa31cb2d82f9bacb8ffe8bf6bf164a565ff72181e89f109f45566992d8a72631
@@ -0,0 +1,38 @@
1
+ on:
2
+ pull_request:
3
+ branches:
4
+ - master
5
+ push:
6
+ branches:
7
+ - ci-check
8
+ - "*/ci-check"
9
+ - master
10
+
11
+ jobs:
12
+ build:
13
+ strategy:
14
+ matrix:
15
+ ruby: ['2.5.x', '2.6.x', '2.7.x', '3.0.x']
16
+ rails: ['rails_6_0', 'rails_6_1']
17
+ opal: ['opal_1_0', 'opal_1_1']
18
+ runs-on: ubuntu-latest
19
+
20
+ steps:
21
+ - name: Install libraries
22
+ run: |
23
+ sudo apt-get update
24
+ sudo apt-get install -y sqlite3 libsqlite3-dev
25
+ - uses: actions/checkout@v1
26
+ - name: Set up Ruby
27
+ uses: actions/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby }}
30
+ - name: Install Dependencies
31
+ run: |
32
+ export BUNDLE_GEMFILE="gemfiles/${{ matrix.rails }}_${{ matrix.opal }}.gemfile"
33
+ gem install bundler
34
+ bundle install --jobs 4 --retry 3
35
+ - name: Test with Rake
36
+ run: |
37
+ export BUNDLE_GEMFILE="gemfiles/${{ matrix.rails }}_${{ matrix.opal }}.gemfile"
38
+ bundle exec rake
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ /sandbox
1
2
  /.bundle/
2
3
  /log/*.log
3
4
  /pkg/
data/Appraisals CHANGED
@@ -1,34 +1,30 @@
1
1
  current_ruby = Gem::Version.new(RUBY_VERSION)
2
- ruby_2_2_2 = Gem::Version.new('2.2.2')
3
2
  ruby_2_4_0 = Gem::Version.new('2.4.0')
3
+ ruby_2_5_0 = Gem::Version.new('2.5.0')
4
4
 
5
5
  ENV['OPAL_VERSION'] = nil # ensure the env is clean
6
6
 
7
7
  github = -> repo_name { "https://github.com/#{repo_name}.git" }
8
8
 
9
9
  {
10
-
11
- opal_master: -> gemfile do
12
- gemfile.gem 'opal', git: github['opal/opal'], branch: :master
13
- gemfile.gem 'opal-rspec', git: github['opal/opal-rspec'], branch: :master
14
- gemfile.gem 'opal-sprockets', git: github['opal/opal-sprockets'], branch: :master
10
+ opal_1_1: -> gemfile do
11
+ gemfile.gem 'opal', '~> 1.1.0'
12
+ gemfile.gem 'opal-sprockets'
15
13
  end,
16
14
 
17
15
  opal_1_0: -> gemfile do
18
16
  gemfile.gem 'opal', '~> 1.0.0'
19
- gemfile.gem 'opal-rspec', git: github['opal/opal-rspec'], branch: :master
20
- gemfile.gem 'opal-jquery', git: github['opal/opal-jquery'], branch: :master
21
17
  gemfile.gem 'opal-sprockets'
22
18
  end,
23
19
 
24
20
  }.each do |opal_version, gem_opal|
25
- appraise "rails_5_1_#{opal_version}" do
26
- gem "rails", "~> 5.1.0"
21
+ appraise "rails_6_0_#{opal_version}" do
22
+ gem "rails", "~> 6.0.0"
27
23
  gem_opal[self]
28
- end if current_ruby >= ruby_2_2_2
24
+ end if current_ruby >= ruby_2_5_0
29
25
 
30
- appraise "rails_5_2_#{opal_version}" do
31
- gem "rails", "~> 5.2.0"
26
+ appraise "rails_6_1_#{opal_version}" do
27
+ gem "rails", "~> 6.1.0"
32
28
  gem_opal[self]
33
- end if current_ruby >= ruby_2_2_2
29
+ end if current_ruby >= ruby_2_5_0
34
30
  end
data/CHANGELOG.md CHANGED
@@ -18,6 +18,67 @@ Whitespace conventions:
18
18
  - 1 spaces before normal text
19
19
  -->
20
20
 
21
+ ## [2.0](https://github.com/opal/opal-rails/compare/v1.1.2...v2.0.0) - unreleased
22
+
23
+ *Bumping a major version, since this version will make a number of dependencies opt-in and drop older Rails and Sprockets versions*
24
+
25
+ ### Added
26
+
27
+ - Added support for Rails v6.1
28
+ - Added a generator for the initial setup (`bin/rails generate opal:install`) that will configure sprockets and create the main `application.js.rb`
29
+
30
+ ### Changed
31
+
32
+ - Now the template handler will encode/decode local and instance variables with ActiveSupport::JSON
33
+
34
+ ### Removed
35
+
36
+ - Removed support for Rails 5.x
37
+ - `opal-jquery` and `opal-activesupport` are no longer dependencies of `opal-rails`, if you need them you'll need to require and setup them manually
38
+
39
+
40
+ ## [1.1.2](https://github.com/opal/opal-rails/compare/v1.1.1...v1.1.2) - 2019-09-26
41
+
42
+
43
+ ### Fixed
44
+
45
+ - Default `skip_onload` to `true` when `javascript_asset_tag` is in debug mode, otherwise some assets may be loaded in the browser after the main source, thus being never loading by the Opal runtime.
46
+
47
+
48
+
49
+
50
+ ## [1.1.1](https://github.com/opal/opal-rails/compare/v1.1.0...v1.1.1) - 2019-09-14
51
+
52
+
53
+ ### Fixed
54
+
55
+ - Fix a problem with require order with regards to `opal-sprockets`.
56
+
57
+
58
+
59
+
60
+ ## [1.1.0](https://github.com/opal/opal-rails/compare/v1.0.1...v1.1.0) - 2019-09-14
61
+
62
+
63
+ ### Added
64
+
65
+ - Added the ability to pass only locals or only ivars when reproducing assigns in Opal templates, `Rails.application.config.opal.assigns_in_templates` can now be set to `:locals` or `:ivars` in addition to the already possible `true`.
66
+
67
+
68
+ ### Changed
69
+
70
+ - The template handler now allows for the new Rails 6 api taking in both the template object and a source argument, but still allows the old behavior
71
+
72
+
73
+
74
+
75
+ ## [1.0.1](https://github.com/opal/opal-rails/compare/v1.0.0...v1.0.1) - 2019-09-07
76
+
77
+
78
+ ### Added
79
+
80
+ - Added support for Rails v6.0 (Sprockets)
81
+
21
82
 
22
83
 
23
84
 
@@ -43,6 +104,7 @@ Whitespace conventions:
43
104
 
44
105
 
45
106
 
107
+
46
108
  ## [0.9.5](https://github.com/opal/opal-rails/compare/v0.9.4...v0.9.5) - 2018-09-07
47
109
 
48
110
 
data/Gemfile CHANGED
@@ -2,10 +2,13 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
  github = -> repo { "https://github.com/#{repo}.git" }
4
4
 
5
- if ENV['OPAL_VERSION'] == 'master'
5
+ case ENV['OPAL_VERSION']
6
+ when 'local'
7
+ gem 'opal', path: '../opal'
8
+ gem 'opal-rspec', path: '../opal-rspec'
9
+ gem 'opal-sprockets', path: '../opal-sprockets'
10
+ gem 'pry'
11
+ when 'master'
6
12
  gem 'opal', git: github['opal/opal'], branch: :master
7
- gem 'opal-rspec', git: github['opal/opal-rspec'], branch: :master
8
13
  gem 'opal-sprockets', git: github['opal/opal-sprockets'], branch: :master
9
14
  end
10
-
11
- gem 'c_lexer'
data/README.md CHANGED
@@ -1,13 +1,18 @@
1
1
  # Opal Rails
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/opal/opal-rails.svg)](http://travis-ci.org/opal/opal-rails)
4
- [![Code Climate](https://img.shields.io/codeclimate/github/opal/opal-rails.svg)](https://codeclimate.com/github/opal/opal-rails)
3
+ [![Build Status](https://github.com/opal/opal-rails/workflows/CI/badge.svg)](https://github.com/opal/opal-rails/actions)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/31dda24adcecb836348f/maintainability)](https://codeclimate.com/github/opal/opal-rails/maintainability)
5
5
  [![Gem Version](https://badge.fury.io/rb/opal-rails.svg)](http://badge.fury.io/rb/opal-rails)
6
6
  ![fun guaranteed](https://img.shields.io/badge/fun-guaranteed-brightgreen.svg)
7
7
  ![web scale](http://img.shields.io/badge/webscale-over%209000-green.svg)
8
8
 
9
- _Rails bindings for [Opal Ruby](http://opalrb.com) engine. ([Changelog](https://github.com/opal/opal-rails/blob/master/CHANGELOG.md))_
9
+ _Rails bindings for [Opal](http://opalrb.com). ([Changelog](https://github.com/opal/opal-rails/blob/master/CHANGELOG.md))_
10
10
 
11
+ ### Looking for Webpack support? 👀
12
+
13
+ If you want to integrate Opal via Webpack please refer to [opal-webpack-loader](https://github.com/isomorfeus/opal-webpack-loader#installation) installation instructions.
14
+
15
+ ℹ️ Webpack and ES6 modules are not yet officially supported, but we're working on it thanks to the awesome work done in _opal-webpack-loader_.
11
16
 
12
17
 
13
18
  ## Installation
@@ -18,10 +23,10 @@ In your `Gemfile`
18
23
  gem 'opal-rails'
19
24
  ```
20
25
 
21
- or when you build your new Rails app:
26
+ Add `app/assets/javascript` to your asset-pipeline manifest in `app/assets/config/manifest.js`:
22
27
 
23
- ```bash
24
- rails new <app-name> --javascript=opal
28
+ ```
29
+ bin/rails opal:install
25
30
  ```
26
31
 
27
32
 
@@ -36,9 +41,17 @@ Rails.application.config.opal.optimized_operators = true
36
41
  Rails.application.config.opal.arity_check = !Rails.env.production?
37
42
  Rails.application.config.opal.const_missing = true
38
43
  Rails.application.config.opal.dynamic_require_severity = :ignore
44
+
45
+ # Other options
46
+
47
+ # Send local and instance variables down to the view after converting
48
+ # thier value with `.to_json`
49
+ Rails.application.config.opal.assigns_in_templates = true
50
+ Rails.application.config.opal.assigns_in_templates = :locals # only locals
51
+ Rails.application.config.opal.assigns_in_templates = :ivars # only instance variables
39
52
  ```
40
53
 
41
- For a full list of the available configuration options please refer to: [lib/opal/config.rb](https://github.com/opal/opal/blob/master/lib/opal/config.rb).
54
+ For a full list of the available configuration options for the compiler please refer to: [lib/opal/config.rb](https://github.com/opal/opal/blob/master/lib/opal/config.rb).
42
55
 
43
56
 
44
57
 
@@ -178,7 +191,6 @@ Of course you need to require `haml-rails` separately since its presence is not
178
191
  Element.find('.comments').effect(:fade_in)
179
192
  end
180
193
  end
181
-
182
194
  ```
183
195
 
184
196
 
@@ -244,10 +256,34 @@ Opal.use_gem 'cannonbol'
244
256
  ```
245
257
 
246
258
 
259
+ ## Contributing
260
+
261
+ Run the specs:
262
+
263
+ ```
264
+ bin/setup
265
+ bin/rake
266
+ ```
267
+
268
+ Inspect the test app:
269
+
270
+ ```
271
+ bin/rackup
272
+ # visit localhost:9292
273
+ ```
274
+
275
+ Tinker with a sandbox app:
276
+
277
+ ```
278
+ bin/sandbox # will re-create the app
279
+ bin/rails s # will start the sandbox app server
280
+ # visit localhost:3000
281
+ ```
282
+
247
283
 
248
284
  ## License
249
285
 
250
- © 2012-2016 Elia Schito
286
+ © 2012-2021 Elia Schito
251
287
 
252
288
  Permission is hereby granted, free of charge, to any person obtaining a copy
253
289
  of this software and associated documentation files (the "Software"), to deal
@@ -10,20 +10,21 @@ module OpalHelper
10
10
  end
11
11
 
12
12
  def javascript_include_tag(*sources)
13
- options = sources.extract_options!
13
+ options = sources.extract_options!.symbolize_keys
14
+ debug = options[:debug] != false
14
15
  skip_loader = options.delete(:skip_opal_loader)
15
- skip_onload = options.delete(:force_opal_loader_tag)
16
+ force_opal_loader_tag = options.delete(:force_opal_loader_tag) || debug
16
17
 
17
- return super(*sources, options) if skip_loader
18
+ return super(*sources, options) if skip_loader && !force_opal_loader_tag
18
19
 
19
20
  script_tags = "".html_safe
20
21
  sources.each do |source|
21
22
  load_asset_code = Opal::Sprockets.load_asset(source)
22
23
  loading_code = "if(window.Opal && Opal.modules[#{source.to_json}]){#{load_asset_code}}"
23
24
 
24
- if skip_onload
25
+ if force_opal_loader_tag
25
26
  script_tags << super(source, options)
26
- script_tags << javascript_tag(loading_code)
27
+ script_tags << "\n".html_safe + javascript_tag(loading_code)
27
28
  else
28
29
  script_tags << super(source, options.merge(onload: loading_code))
29
30
  end
data/bin/rackup ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rackup' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rack", "rackup")
data/bin/rails ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if %w[e engine].include? ARGV.first
4
+ ARGV.shift # remove the first argument
5
+ exec "#{__dir__}/rails-engine", *ARGV
6
+ else
7
+ exec "#{__dir__}/rails-sandbox", *ARGV
8
+ end
data/bin/rails-engine ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/opal/rails/engine', __dir__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
data/bin/rails-sandbox ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ app_root = 'sandbox'
6
+
7
+ unless File.exist? "#{app_root}/bin/rails"
8
+ warn 'Creating the sandbox app...'
9
+ Dir.chdir "#{__dir__}/.." do
10
+ system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
11
+ warn 'Automatic creation of the sandbox app failed'
12
+ exit 1
13
+ end
14
+ end
15
+ end
16
+
17
+ Dir.chdir app_root
18
+ exec 'bin/rails', *ARGV
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")