opal-rails 1.0.1 → 2.0.1

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/{main.yml → build.yml} +12 -5
  3. data/.gitignore +1 -0
  4. data/Appraisals +8 -17
  5. data/CHANGELOG.md +66 -0
  6. data/Gemfile +7 -4
  7. data/README.md +55 -13
  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 +0 -3
  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 +14 -0
  27. data/lib/generators/opal/install/templates/application.js.rb +12 -0
  28. data/lib/generators/opal/install/templates/initializer.rb +22 -0
  29. data/lib/opal/rails.rb +0 -4
  30. data/lib/opal/rails/engine.rb +9 -2
  31. data/lib/opal/rails/template_handler.rb +16 -7
  32. data/lib/opal/rails/version.rb +1 -1
  33. data/opal-rails.gemspec +45 -40
  34. data/spec/helpers/opal_helper_spec.rb +23 -9
  35. data/spec/integration/assigns_spec.rb +58 -2
  36. data/spec/integration/source_map_spec.rb +9 -5
  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/rails6.rb +1 -3
  45. metadata +48 -84
  46. data/gemfiles/rails_5_1_opal_1_0.gemfile +0 -12
  47. data/gemfiles/rails_5_1_opal_master.gemfile +0 -11
  48. data/gemfiles/rails_5_2_opal_1_0.gemfile +0 -12
  49. data/gemfiles/rails_5_2_opal_master.gemfile +0 -11
  50. data/gemfiles/rails_6_0_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/rails5.rb +0 -50
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1667d89f71ac1e122af6ac49faa4de25629c6d05c6c8fa3efa3dac2dcac905e7
4
- data.tar.gz: 875c55723b127a58a9419d2ee1c5c7bf563504d38b271c0377b9f745499c96ad
3
+ metadata.gz: 165e5b957c73079681eae29566b10478bddd1bb0a959d7cc2ce772ffe5778b85
4
+ data.tar.gz: 4f6dd4337a2f84796852b4ceb87e15decb2ae85afdc1c5012c1f0ab586c08e1c
5
5
  SHA512:
6
- metadata.gz: c46c91b5f4b67cd7c085ffcf66a40c094cbbb1fe33cc3fd6adf7e5b7a168d6fac2085dbd0242e8e0cf7fbeeee75aff578d8fa189ad34d83b1c00d5827818c7f4
7
- data.tar.gz: ede7e20e01eacc30da85dcda3409b7cabdd83c64c3f29f13c455a83c7dd6063f1e19ed6db389e8d8a792b870ccc8974066f1ec59bd687bcfb8f12cc3be494511
6
+ metadata.gz: 4537a41a8f9c848acbf0a440aa1767d5f40737dca75e62e8711efd860a369a44d8c093c2d981ee759090b135b42720a35953f65a559be21fbd86c04763ed9f8d
7
+ data.tar.gz: '05853c6bb0945b217118c92af19694771a3b8fe35207fe8c2ca1e4906b652808fab63beb25e0b96efdc00f1c979abfa9e1ad36864afe35ad1e58b94db0bccb58'
@@ -1,13 +1,20 @@
1
- name: CI
2
- on: [push]
1
+ on:
2
+ pull_request:
3
+ branches:
4
+ - master
5
+ push:
6
+ branches:
7
+ - ci-check
8
+ - "*/ci-check"
9
+ - master
3
10
 
4
11
  jobs:
5
12
  build:
6
13
  strategy:
7
14
  matrix:
8
- ruby: ['2.5.x', '2.6.x']
9
- rails: ['rails_5_1', 'rails_5_2', 'rails_6_0']
10
- opal: ['opal_1_0', 'opal_master']
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']
11
18
  runs-on: ubuntu-latest
12
19
 
13
20
  steps:
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ /sandbox
1
2
  /.bundle/
2
3
  /log/*.log
3
4
  /pkg/
data/Appraisals CHANGED
@@ -7,33 +7,24 @@ ENV['OPAL_VERSION'] = nil # ensure the env is clean
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"
27
- gem_opal[self]
28
- end if current_ruby >= ruby_2_4_0
29
-
30
- appraise "rails_5_2_#{opal_version}" do
31
- gem "rails", "~> 5.2.0"
32
- gem_opal[self]
33
- end if current_ruby >= ruby_2_4_0
34
-
35
21
  appraise "rails_6_0_#{opal_version}" do
36
22
  gem "rails", "~> 6.0.0"
37
23
  gem_opal[self]
38
24
  end if current_ruby >= ruby_2_5_0
25
+
26
+ appraise "rails_6_1_#{opal_version}" do
27
+ gem "rails", "~> 6.1.0"
28
+ gem_opal[self]
29
+ end if current_ruby >= ruby_2_5_0
39
30
  end
data/CHANGELOG.md CHANGED
@@ -20,6 +20,72 @@ Whitespace conventions:
20
20
 
21
21
 
22
22
 
23
+ ## [2.0.1](https://github.com/opal/opal-rails/compare/v2.0.0...v2.0.1) - 2021-03-03
24
+
25
+
26
+ ### Added
27
+
28
+ - The install generator now will add an `opal.rb` initializer with a default compiler configuration and the template assign support disabled
29
+
30
+ ### Fixed
31
+
32
+ - The install generator was missing a newline when changing the app layout
33
+
34
+
35
+ ## [2.0.0](https://github.com/opal/opal-rails/compare/v1.1.2...v2.0.0) - 2021-02-23
36
+
37
+ *This is a major version, since a number of dependencies are going to be opt-in and support for older Rails
38
+ and Sprockets versions is dropped*
39
+
40
+ ### Added
41
+
42
+ - Added support for Rails v6.1
43
+ - Added a generator for the initial setup (`bin/rails generate opal:install`) that will configure sprockets and create the main `application.js.rb`
44
+
45
+ ### Changed
46
+
47
+ - Now the template handler will encode/decode local and instance variables with ActiveSupport::JSON
48
+
49
+ ### Removed
50
+
51
+ - Removed support for Rails 5.x
52
+ - `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
53
+
54
+
55
+ ## [1.1.2](https://github.com/opal/opal-rails/compare/v1.1.1...v1.1.2) - 2019-09-26
56
+
57
+
58
+ ### Fixed
59
+
60
+ - 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.
61
+
62
+
63
+
64
+
65
+ ## [1.1.1](https://github.com/opal/opal-rails/compare/v1.1.0...v1.1.1) - 2019-09-14
66
+
67
+
68
+ ### Fixed
69
+
70
+ - Fix a problem with require order with regards to `opal-sprockets`.
71
+
72
+
73
+
74
+
75
+ ## [1.1.0](https://github.com/opal/opal-rails/compare/v1.0.1...v1.1.0) - 2019-09-14
76
+
77
+
78
+ ### Added
79
+
80
+ - 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`.
81
+
82
+
83
+ ### Changed
84
+
85
+ - 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
86
+
87
+
88
+
23
89
 
24
90
  ## [1.0.1](https://github.com/opal/opal-rails/compare/v1.0.0...v1.0.1) - 2019-09-07
25
91
 
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,19 +1,20 @@
1
1
  # Opal Rails
2
2
 
3
3
  [![Build Status](https://github.com/opal/opal-rails/workflows/CI/badge.svg)](https://github.com/opal/opal-rails/actions)
4
- [![Code Climate](https://img.shields.io/codeclimate/github/opal/opal-rails.svg)](https://codeclimate.com/github/opal/opal-rails)
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
9
  _Rails bindings for [Opal](http://opalrb.com). ([Changelog](https://github.com/opal/opal-rails/blob/master/CHANGELOG.md))_
10
10
 
11
- ### Looking Webpack support? 👀
11
+ ### Looking for Webpack support? 👀
12
12
 
13
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
14
 
15
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_.
16
16
 
17
+
17
18
  ## Installation
18
19
 
19
20
  In your `Gemfile`
@@ -22,28 +23,46 @@ In your `Gemfile`
22
23
  gem 'opal-rails'
23
24
  ```
24
25
 
25
- or when you build your new Rails app:
26
+ Add `app/assets/javascript` to your asset-pipeline manifest in `app/assets/config/manifest.js`:
26
27
 
27
- ```bash
28
- rails new <app-name> --javascript=opal
28
+ ```
29
+ bin/rails opal:install
29
30
  ```
30
31
 
31
32
 
32
33
  ### Configuration
33
34
 
34
- Add your configuration in `config/initializers/assets.rb` with the following contents:
35
+ #### For the compiler
36
+
37
+ Add your configuration for the compiler:
38
+
39
+ `config/initializers/opal.rb`
35
40
 
36
41
  ```ruby
37
42
  # Compiler options
38
- Rails.application.config.opal.method_missing = true
39
- Rails.application.config.opal.optimized_operators = true
40
- Rails.application.config.opal.arity_check = !Rails.env.production?
41
- Rails.application.config.opal.const_missing = true
43
+ Rails.application.config.opal.method_missing_enabled = true
44
+ Rails.application.config.opal.const_missing_enabled = true
45
+ Rails.application.config.opal.arity_check_enabled = true
46
+ Rails.application.config.opal.freezing_stubs_enabled = true
42
47
  Rails.application.config.opal.dynamic_require_severity = :ignore
43
48
  ```
44
49
 
45
- 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).
50
+ Check out the full list of the available configuration options at: [lib/opal/config.rb](https://github.com/opal/opal/blob/master/lib/opal/config.rb).
46
51
 
52
+ #### For template assigns
53
+
54
+ Add your configuration for rendering assigns when using the template handler from actions:
55
+
56
+ `config/initializers/opal.rb`
57
+
58
+ ```ruby
59
+ Rails.application.config.opal.assigns_in_templates = true
60
+ Rails.application.config.opal.assigns_in_templates = :locals # only locals
61
+ Rails.application.config.opal.assigns_in_templates = :ivars # only instance variables
62
+ ```
63
+
64
+
65
+ Local and instance variables will be sent down to the view after converting their values to JSON.
47
66
 
48
67
 
49
68
  ## Usage
@@ -182,7 +201,6 @@ Of course you need to require `haml-rails` separately since its presence is not
182
201
  Element.find('.comments').effect(:fade_in)
183
202
  end
184
203
  end
185
-
186
204
  ```
187
205
 
188
206
 
@@ -248,10 +266,34 @@ Opal.use_gem 'cannonbol'
248
266
  ```
249
267
 
250
268
 
269
+ ## Contributing
270
+
271
+ Run the specs:
272
+
273
+ ```
274
+ bin/setup
275
+ bin/rake
276
+ ```
277
+
278
+ Inspect the test app:
279
+
280
+ ```
281
+ bin/rackup
282
+ # visit localhost:9292
283
+ ```
284
+
285
+ Tinker with a sandbox app:
286
+
287
+ ```
288
+ bin/sandbox # will re-create the app
289
+ bin/rails s # will start the sandbox app server
290
+ # visit localhost:3000
291
+ ```
292
+
251
293
 
252
294
  ## License
253
295
 
254
- © 2012-2019 Elia Schito
296
+ © 2012-2021 Elia Schito
255
297
 
256
298
  Permission is hereby granted, free of charge, to any person obtaining a copy
257
299
  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")