opal-rails 1.1.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) 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 +16 -0
  6. data/Gemfile +7 -4
  7. data/README.md +30 -6
  8. data/bin/rackup +29 -0
  9. data/bin/rails +8 -0
  10. data/bin/rails-engine +13 -0
  11. data/bin/rails-sandbox +18 -0
  12. data/bin/rake +29 -0
  13. data/bin/rspec +29 -0
  14. data/bin/sandbox +39 -0
  15. data/bin/sandbox-setup +14 -0
  16. data/bin/setup +8 -0
  17. data/gemfiles/rails_6_0_opal_1_0.gemfile +0 -3
  18. data/gemfiles/rails_6_0_opal_1_1.gemfile +9 -0
  19. data/gemfiles/rails_6_1_opal_1_0.gemfile +9 -0
  20. data/gemfiles/rails_6_1_opal_1_1.gemfile +9 -0
  21. data/lib/assets/javascripts/opal_ujs.js.rb +1 -4
  22. data/lib/generators/opal/assets/assets_generator.rb +7 -0
  23. data/lib/{rails/generators → generators}/opal/assets/templates/javascript.js.rb +0 -0
  24. data/lib/generators/opal/install/USAGE +8 -0
  25. data/lib/generators/opal/install/install_generator.rb +12 -0
  26. data/lib/generators/opal/install/templates/application.js.rb +12 -0
  27. data/lib/opal/rails.rb +0 -4
  28. data/lib/opal/rails/template_handler.rb +4 -2
  29. data/lib/opal/rails/version.rb +1 -1
  30. data/opal-rails.gemspec +45 -40
  31. data/spec/helpers/opal_helper_spec.rb +5 -3
  32. data/spec/integration/source_map_spec.rb +9 -5
  33. data/test_apps/{application_controller.rb → app/application_controller.rb} +1 -1
  34. data/test_apps/app/assets/config/manifest.js +1 -0
  35. data/test_apps/{assets → app/assets}/javascripts/application.js.rb +1 -0
  36. data/test_apps/{assets → app/assets}/javascripts/bar.rb +0 -0
  37. data/test_apps/{assets → app/assets}/javascripts/foo.js.rb +0 -0
  38. data/test_apps/{assets → app/assets}/javascripts/source_map_example.js.rb +0 -0
  39. data/test_apps/{assets → app/assets}/javascripts/with_assignments.js.rb +0 -0
  40. data/test_apps/rails6.rb +1 -3
  41. metadata +47 -82
  42. data/gemfiles/rails_5_1_opal_1_0.gemfile +0 -12
  43. data/gemfiles/rails_5_1_opal_master.gemfile +0 -11
  44. data/gemfiles/rails_5_2_opal_1_0.gemfile +0 -12
  45. data/gemfiles/rails_5_2_opal_master.gemfile +0 -11
  46. data/gemfiles/rails_6_0_opal_master.gemfile +0 -11
  47. data/lib/rails/generators/opal/assets/assets_generator.rb +0 -12
  48. data/test_apps/rails5.rb +0 -50
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fe52f8b8220d7217cdee145bf089a14e6992c1c187c1a62bba8585433d34081
4
- data.tar.gz: 413cd3f385011549dbaa800d3aeb46df5677d0d25e6dfd2e15eedb96f0c58e8c
3
+ metadata.gz: 49586db0f49f4f31e3e289e1f813275e1b81ab083aa5e771887e5e93bc08b83b
4
+ data.tar.gz: 02d8db2458c45f4fe2554028571288b2664f8cfc64bba320a62d59a9ea120567
5
5
  SHA512:
6
- metadata.gz: 87b789a075dd3f62c76e4dae46686ea291a2949a197a03cfd2c38aac96fc19b16c04e0e8903ed406e5aa9e679969a7e7bde793e6e436c54a63a6b12398eb98fd
7
- data.tar.gz: 855c4c73ad06af2c8334aaf7db85c886600210349568b9ced0cc9e49bf952dddd4143c7083fbd69e5f5816cf78e448fa86186606daf0012829edda5063aedc8c
6
+ metadata.gz: ec6e2d6ce3226094ef31bcb2b75a5317b7d0a1e05cb3af627022dfd00697787ad1ed6fdd739cfb485a741685e4cfd8b746d3fb29a1e4a29b6bcc1b6163aef362
7
+ data.tar.gz: eac8d359fbd8589edd16c7df490a619fe9d2e3a09640ab0d1d14ece16cd5f6d1fa31cb2d82f9bacb8ffe8bf6bf164a565ff72181e89f109f45566992d8a72631
@@ -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
@@ -18,7 +18,23 @@ 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
21
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
22
38
 
23
39
 
24
40
  ## [1.1.2](https://github.com/opal/opal-rails/compare/v1.1.1...v1.1.2) - 2019-09-26
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
@@ -8,12 +8,13 @@
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,10 +23,10 @@ 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
 
@@ -190,7 +191,6 @@ Of course you need to require `haml-rails` separately since its presence is not
190
191
  Element.find('.comments').effect(:fade_in)
191
192
  end
192
193
  end
193
-
194
194
  ```
195
195
 
196
196
 
@@ -256,10 +256,34 @@ Opal.use_gem 'cannonbol'
256
256
  ```
257
257
 
258
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
+
259
283
 
260
284
  ## License
261
285
 
262
- © 2012-2019 Elia Schito
286
+ © 2012-2021 Elia Schito
263
287
 
264
288
  Permission is hereby granted, free of charge, to any person obtaining a copy
265
289
  of this software and associated documentation files (the "Software"), to deal
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")
data/bin/sandbox ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem_name="$(ruby -rpathname -e"puts Pathname(ARGV.first).join('../..').expand_path.glob('*.gemspec').first.basename('.gemspec')" -- $0)"
4
+
5
+ # Stay away from the bundler env of the containing extension.
6
+ function unbundled {
7
+ ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
8
+ }
9
+
10
+ rm -rf ./sandbox
11
+ unbundled bundle exec rails new sandbox \
12
+ --skip-bundle \
13
+ --skip-git \
14
+ --skip-keeps \
15
+ --skip-rc \
16
+ --skip-spring \
17
+ --skip-test \
18
+ $@
19
+
20
+ if [ ! -d "sandbox" ]; then
21
+ echo 'sandbox rails application failed'
22
+ exit 1
23
+ fi
24
+
25
+ cd ./sandbox
26
+ cat <<RUBY >> Gemfile
27
+ gem '$gem_name', path: '..'
28
+ RUBY
29
+
30
+ unbundled bundle install --gemfile Gemfile
31
+ unbundled bin/rails webpacker:install
32
+
33
+
34
+ cd .. # Back to the project root.
35
+ bin/sandbox-setup # Run any custom setup.
36
+
37
+ echo
38
+ echo "🚀 Sandbox app successfully created for $gem_name!"
39
+
data/bin/sandbox-setup ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+
5
+ root = Pathname('sandbox')
6
+
7
+ system 'bin/rails opal:install'
8
+ system 'bin/rails g controller home index -f'
9
+
10
+ root.join('config/routes.rb').write <<~RUBY
11
+ Rails.application.routes.draw do
12
+ root to: "home#index"
13
+ end
14
+ RUBY
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+
8
+ bundle update
@@ -2,11 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "c_lexer"
6
5
  gem "rails", "~> 6.0.0"
7
6
  gem "opal", "~> 1.0.0"
8
- gem "opal-rspec", git: "https://github.com/opal/opal-rspec.git", branch: :master
9
- gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: :master
10
7
  gem "opal-sprockets"
11
8
 
12
9
  gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.0.0"
6
+ gem "opal", "~> 1.1.0"
7
+ gem "opal-sprockets"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.1.0"
6
+ gem "opal", "~> 1.0.0"
7
+ gem "opal-sprockets"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.1.0"
6
+ gem "opal", "~> 1.1.0"
7
+ gem "opal-sprockets"
8
+
9
+ gemspec path: "../"
@@ -1,4 +1 @@
1
- require 'jquery'
2
- require 'jquery_ujs'
3
- require 'opal'
4
- require 'opal-jquery'
1
+ warn "`opal_ujs` is deprecated and no longer works"
@@ -0,0 +1,7 @@
1
+ class Opal::AssetsGenerator < ::Rails::Generators::NamedBase
2
+ source_root File.expand_path('templates', __dir__)
3
+
4
+ def copy_opal
5
+ template 'javascript.js.rb', File.join('app/assets/javascripts', class_path, "#{file_name}.js.rb")
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ bin/rails generate install Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,12 @@
1
+ class Opal::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('templates', __dir__)
3
+
4
+ def configure_sprockets
5
+ append_to_file 'app/assets/config/manifest.js', '//= link_directory ../javascript .js'
6
+ template "application.js.rb", "app/assets/javascript/application.js.rb"
7
+
8
+ # Add the javascript tag to the application head tag
9
+ gsub_file 'app/views/layouts/application.html.erb', %r{^( *)</head>},
10
+ '\1 <%= javascript_include_tag "application", "data-turbolinks-track": "reload" %>\1</head>'
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require "opal"
2
+
3
+ # Uncomment the following to print out you're hello-world with Opal:
4
+ #
5
+ # puts "hello world!"
6
+ #
7
+ # The following will append a hello-world to your <body> element:
8
+ #
9
+ # require "native"
10
+ # $$[:document].addEventListener :DOMContentLoaded do
11
+ # $$[:document][:body][:innerHTML] += '<h2>Hello World!</h2>'
12
+ # end
data/lib/opal/rails.rb CHANGED
@@ -1,9 +1,5 @@
1
1
  require 'opal'
2
- require 'opal-jquery'
3
- require 'opal-activesupport'
4
2
 
5
3
  require 'opal/rails/engine'
6
4
  require 'opal/rails/template_handler'
7
5
  require 'opal/rails/version'
8
-
9
- require 'jquery-rails'
@@ -1,3 +1,5 @@
1
+ require 'active_support/json'
2
+
1
3
  module Opal
2
4
  module Rails
3
5
  class TemplateHandler
@@ -17,11 +19,11 @@ module Opal
17
19
  code << 'Object.new.instance_eval {'
18
20
 
19
21
  if config.assign_locals_in_templates?
20
- code << JSON.parse(local_assigns.to_json).map { |key, val| "\#{key} = \#{val.inspect};" }.join
22
+ code << ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(local_assigns)).map { |key, val| "\#{key} = \#{val.inspect};" }.join
21
23
  end
22
24
 
23
25
  if config.assign_instance_variables_in_templates?
24
- code << JSON.parse(@_assigns.to_json).map { |key, val| "@\#{key} = \#{val.inspect};" }.join
26
+ code << ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(@_assigns)).map { |key, val| "@\#{key} = \#{val.inspect};" }.join
25
27
  end
26
28
 
27
29
  code << #{string}
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Rails
3
- VERSION = '1.1.2'
3
+ VERSION = '2.0.0'
4
4
  end
5
5
  end
data/opal-rails.gemspec CHANGED
@@ -1,41 +1,46 @@
1
- # coding: utf-8
2
- $:.push File.expand_path('../lib', __FILE__)
3
- require 'opal/rails/version'
4
-
5
- Gem::Specification.new do |s|
6
- s.name = 'opal-rails'
7
- s.version = Opal::Rails::VERSION
8
- s.authors = ['Elia Schito']
9
- s.email = ['elia@schito.me']
10
- s.homepage = 'https://github.com/opal/opal-rails#readme'
11
- s.summary = %q{Rails bindings for opal JS engine}
12
- s.description = %q{Rails bindings for opal JS engine}
13
- s.license = 'MIT-LICENSE'
14
-
15
- s.rubyforge_project = 'opal-rails'
16
-
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ['lib']
21
-
22
- required_ruby_version = '>= 2.3'
23
-
24
- s.add_dependency 'rails', '>= 5.1', '< 6.1'
25
- s.add_dependency 'sprockets-rails', '>= 2.3.3', '< 4.0'
26
- s.add_dependency 'jquery-rails'
27
-
28
- s.add_dependency 'opal', '~> 1.0.0'
29
- s.add_dependency 'opal-jquery', '~> 0.4.4'
30
- s.add_dependency 'opal-sprockets', '~> 0.4.6'
31
- s.add_dependency 'opal-activesupport', '>= 0.0.5'
32
-
33
- s.add_development_dependency 'execjs'
34
- s.add_development_dependency 'launchy'
35
- s.add_development_dependency 'capybara', '~> 3.25'
36
- s.add_development_dependency 'apparition'
37
- s.add_development_dependency 'rspec-rails'
38
- s.add_development_dependency 'appraisal', '~> 2.1'
39
- s.add_development_dependency 'sqlite3'
40
- s.add_development_dependency 'puma'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/opal/rails/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'opal-rails'
7
+ spec.version = Opal::Rails::VERSION
8
+ spec.authors = ['Elia Schito']
9
+ spec.email = ['elia@schito.me']
10
+
11
+ spec.summary = %q{Rails bindings for opal JS engine}
12
+ spec.description = %q{Rails bindings for opal JS engine}
13
+ spec.homepage = 'https://github.com/opal/opal-rails#readme'
14
+ spec.license = 'MIT-LICENSE'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/opal/opal-rails#readme'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/opal/opal-rails/blob/master/CHANGELOG.md'
19
+
20
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5')
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
25
+
26
+ spec.files = files.grep_v(%r{^(test|spec|features)/})
27
+ spec.test_files = files.grep(%r{^(test|spec|features)/})
28
+ spec.bindir = "exe"
29
+ spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency 'rails', '>= 6.0', '< 7'
33
+ spec.add_dependency 'sprockets-rails', '>= 3.0'
34
+
35
+ spec.add_dependency 'opal', '~> 1.0'
36
+ spec.add_dependency 'opal-sprockets', '~> 1.0'
37
+
38
+ spec.add_development_dependency 'execjs'
39
+ spec.add_development_dependency 'launchy'
40
+ spec.add_development_dependency 'capybara', '~> 3.25'
41
+ spec.add_development_dependency 'apparition'
42
+ spec.add_development_dependency 'rspec-rails'
43
+ spec.add_development_dependency 'appraisal', '~> 2.1'
44
+ spec.add_development_dependency 'sqlite3'
45
+ spec.add_development_dependency 'puma'
41
46
  end
@@ -1,7 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe OpalHelper, type: :helper do
4
- # subject(:helper) { double(javascript_include_tag: '<super>').extend described_class }
3
+ # We need the view type because helpers specs are to are too minimalistic
4
+ # and are missing some initialization stuff.
5
+ describe OpalHelper, :js, type: :view do
6
+ let(:helper) { view }
5
7
 
6
8
  describe '#opal_tag' do
7
9
  it 'compiles to js' do
@@ -21,7 +23,7 @@ describe OpalHelper, type: :helper do
21
23
  allow(Rails.application).to receive(:assets).and_return(nil)
22
24
 
23
25
  loading_code = [
24
- %<if(window.Opal && Opal.modules["application"]){Opal.loaded(OpalLoaded || []);>,
26
+ %<if(window.Opal && Opal.modules["application"]){Opal.loaded(typeof(OpalLoaded) === "undefined" ? [] : OpalLoaded);>,
25
27
  %<Opal.require("application");}>,
26
28
  ].join("\n")
27
29
 
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  require 'opal/source_map'
4
4
 
5
5
  describe Opal::SourceMap do
6
- let(:js_asset_path) { '/assets/source_map_example.self.js' }
6
+ let(:js_asset_path) { '/assets/source_map_example.debug.js' }
7
7
 
8
8
  before do
9
9
  expect(Rails.application.config.opal.source_map_enabled).to be_truthy
@@ -21,13 +21,16 @@ describe Opal::SourceMap do
21
21
  Base64.decode64(response.body.lines.last.split(inline_map_prefix, 2)[1])
22
22
  else
23
23
  source_map_regexp = %r{^//[@#] sourceMappingURL=([^\n]+)}
24
+
24
25
  header_map_path = response.headers['X-SourceMap'].presence
25
26
  comment_map_path = response.body.scan(source_map_regexp).flatten.first.to_s.strip.presence
26
27
 
27
- map_path = header_map_path || comment_map_path
28
+ map_path = (header_map_path || comment_map_path)&.strip
29
+
30
+ get URI.join("http://example.com/", js_asset_path, map_path).path
28
31
 
29
- get map_path
30
32
  expect(response).to be_successful, "url: #{map_path}\nstatus: #{response.status}"
33
+
31
34
  response.body
32
35
  end
33
36
  end
@@ -36,7 +39,8 @@ describe Opal::SourceMap do
36
39
 
37
40
  it 'has the source map be there' do
38
41
  expect(map).to be_present
39
- expect(map[:sources]).to be_present
40
- expect(map[:mappings]).to be_present
42
+ expect(map[:sections].size).to eq(1)
43
+ expect(map[:sections][0][:map][:sources]).to be_present
44
+ expect(map[:sections][0][:map][:mappings]).to be_present
41
45
  end
42
46
  end
@@ -14,7 +14,7 @@ HTML
14
14
 
15
15
  WITH_ASSIGNMENTS = File.read "#{__dir__}/assets/javascripts/with_assignments.js.rb"
16
16
 
17
- require_relative '../app/helpers/opal_helper'
17
+ require_relative '../../app/helpers/opal_helper'
18
18
 
19
19
  class ApplicationController < ActionController::Base
20
20
  include Rails.application.routes.url_helpers
@@ -0,0 +1 @@
1
+ //= link_directory ../javascripts .js
@@ -1,6 +1,7 @@
1
1
  require 'opal'
2
2
  require 'opal_ujs'
3
3
  require 'opal-parser'
4
+ require 'json'
4
5
 
5
6
  require_tree '.'
6
7
  `window.opal_loaded = true`
File without changes
data/test_apps/rails6.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # FROM: http://www.rubytutorial.io/how-to-test-your-gem-against-multiple-rails/
2
2
 
3
- # test/apps/rails5.rb
4
3
  require 'rails'
5
4
  require 'rails/all'
6
5
  require 'action_view/testing/resolvers'
@@ -37,7 +36,6 @@ module RailsApp
37
36
  get '/favicon.ico' => -> { [404,{},[]] }
38
37
  end
39
38
 
40
- config.assets.paths << File.join(__dir__, 'assets/javascripts')
41
39
  config.assets.debug = true
42
40
  config.assets.digest = true
43
41
 
@@ -46,5 +44,5 @@ module RailsApp
46
44
  end
47
45
  end
48
46
 
49
- require_relative './application_controller'
47
+ require_relative './app/application_controller'
50
48
  RailsApp::Application.initialize!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
8
- autorequire:
9
- bindir: bin
8
+ autorequire:
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-26 00:00:00.000000000 Z
11
+ date: 2021-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,110 +16,62 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.1'
19
+ version: '6.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.1'
22
+ version: '7'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '5.1'
29
+ version: '6.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.1'
32
+ version: '7'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: sprockets-rails
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 2.3.3
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '4.0'
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 2.3.3
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '4.0'
53
- - !ruby/object:Gem::Dependency
54
- name: jquery-rails
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: '0'
39
+ version: '3.0'
60
40
  type: :runtime
61
41
  prerelease: false
62
42
  version_requirements: !ruby/object:Gem::Requirement
63
43
  requirements:
64
44
  - - ">="
65
45
  - !ruby/object:Gem::Version
66
- version: '0'
46
+ version: '3.0'
67
47
  - !ruby/object:Gem::Dependency
68
48
  name: opal
69
49
  requirement: !ruby/object:Gem::Requirement
70
50
  requirements:
71
51
  - - "~>"
72
52
  - !ruby/object:Gem::Version
73
- version: 1.0.0
74
- type: :runtime
75
- prerelease: false
76
- version_requirements: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - "~>"
79
- - !ruby/object:Gem::Version
80
- version: 1.0.0
81
- - !ruby/object:Gem::Dependency
82
- name: opal-jquery
83
- requirement: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: 0.4.4
53
+ version: '1.0'
88
54
  type: :runtime
89
55
  prerelease: false
90
56
  version_requirements: !ruby/object:Gem::Requirement
91
57
  requirements:
92
58
  - - "~>"
93
59
  - !ruby/object:Gem::Version
94
- version: 0.4.4
60
+ version: '1.0'
95
61
  - !ruby/object:Gem::Dependency
96
62
  name: opal-sprockets
97
63
  requirement: !ruby/object:Gem::Requirement
98
64
  requirements:
99
65
  - - "~>"
100
66
  - !ruby/object:Gem::Version
101
- version: 0.4.6
67
+ version: '1.0'
102
68
  type: :runtime
103
69
  prerelease: false
104
70
  version_requirements: !ruby/object:Gem::Requirement
105
71
  requirements:
106
72
  - - "~>"
107
73
  - !ruby/object:Gem::Version
108
- version: 0.4.6
109
- - !ruby/object:Gem::Dependency
110
- name: opal-activesupport
111
- requirement: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- version: 0.0.5
116
- type: :runtime
117
- prerelease: false
118
- version_requirements: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: 0.0.5
74
+ version: '1.0'
123
75
  - !ruby/object:Gem::Dependency
124
76
  name: execjs
125
77
  requirement: !ruby/object:Gem::Requirement
@@ -239,7 +191,7 @@ executables: []
239
191
  extensions: []
240
192
  extra_rdoc_files: []
241
193
  files:
242
- - ".github/workflows/main.yml"
194
+ - ".github/workflows/build.yml"
243
195
  - ".gitignore"
244
196
  - ".powder"
245
197
  - ".rspec"
@@ -249,14 +201,26 @@ files:
249
201
  - README.md
250
202
  - Rakefile
251
203
  - app/helpers/opal_helper.rb
204
+ - bin/rackup
205
+ - bin/rails
206
+ - bin/rails-engine
207
+ - bin/rails-sandbox
208
+ - bin/rake
209
+ - bin/rspec
210
+ - bin/sandbox
211
+ - bin/sandbox-setup
212
+ - bin/setup
252
213
  - config.ru
253
- - gemfiles/rails_5_1_opal_1_0.gemfile
254
- - gemfiles/rails_5_1_opal_master.gemfile
255
- - gemfiles/rails_5_2_opal_1_0.gemfile
256
- - gemfiles/rails_5_2_opal_master.gemfile
257
214
  - gemfiles/rails_6_0_opal_1_0.gemfile
258
- - gemfiles/rails_6_0_opal_master.gemfile
215
+ - gemfiles/rails_6_0_opal_1_1.gemfile
216
+ - gemfiles/rails_6_1_opal_1_0.gemfile
217
+ - gemfiles/rails_6_1_opal_1_1.gemfile
259
218
  - lib/assets/javascripts/opal_ujs.js.rb
219
+ - lib/generators/opal/assets/assets_generator.rb
220
+ - lib/generators/opal/assets/templates/javascript.js.rb
221
+ - lib/generators/opal/install/USAGE
222
+ - lib/generators/opal/install/install_generator.rb
223
+ - lib/generators/opal/install/templates/application.js.rb
260
224
  - lib/opal-rails.rb
261
225
  - lib/opal/rails.rb
262
226
  - lib/opal/rails/engine.rb
@@ -264,8 +228,6 @@ files:
264
228
  - lib/opal/rails/slim_filter.rb
265
229
  - lib/opal/rails/template_handler.rb
266
230
  - lib/opal/rails/version.rb
267
- - lib/rails/generators/opal/assets/assets_generator.rb
268
- - lib/rails/generators/opal/assets/templates/javascript.js.rb
269
231
  - opal-rails.gemspec
270
232
  - spec/helpers/opal_helper_spec.rb
271
233
  - spec/integration/assigns_spec.rb
@@ -276,19 +238,22 @@ files:
276
238
  - spec/support/reset_assets_cache.rb
277
239
  - spec/support/reset_config.rb
278
240
  - spec/support/test_app.rb
279
- - test_apps/application_controller.rb
280
- - test_apps/assets/javascripts/application.js.rb
281
- - test_apps/assets/javascripts/bar.rb
282
- - test_apps/assets/javascripts/foo.js.rb
283
- - test_apps/assets/javascripts/source_map_example.js.rb
284
- - test_apps/assets/javascripts/with_assignments.js.rb
285
- - test_apps/rails5.rb
241
+ - test_apps/app/application_controller.rb
242
+ - test_apps/app/assets/config/manifest.js
243
+ - test_apps/app/assets/javascripts/application.js.rb
244
+ - test_apps/app/assets/javascripts/bar.rb
245
+ - test_apps/app/assets/javascripts/foo.js.rb
246
+ - test_apps/app/assets/javascripts/source_map_example.js.rb
247
+ - test_apps/app/assets/javascripts/with_assignments.js.rb
286
248
  - test_apps/rails6.rb
287
249
  homepage: https://github.com/opal/opal-rails#readme
288
250
  licenses:
289
251
  - MIT-LICENSE
290
- metadata: {}
291
- post_install_message:
252
+ metadata:
253
+ homepage_uri: https://github.com/opal/opal-rails#readme
254
+ source_code_uri: https://github.com/opal/opal-rails#readme
255
+ changelog_uri: https://github.com/opal/opal-rails/blob/master/CHANGELOG.md
256
+ post_install_message:
292
257
  rdoc_options: []
293
258
  require_paths:
294
259
  - lib
@@ -296,15 +261,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
296
261
  requirements:
297
262
  - - ">="
298
263
  - !ruby/object:Gem::Version
299
- version: '0'
264
+ version: '2.5'
300
265
  required_rubygems_version: !ruby/object:Gem::Requirement
301
266
  requirements:
302
267
  - - ">="
303
268
  - !ruby/object:Gem::Version
304
269
  version: '0'
305
270
  requirements: []
306
- rubygems_version: 3.0.3
307
- signing_key:
271
+ rubygems_version: 3.2.3
272
+ signing_key:
308
273
  specification_version: 4
309
274
  summary: Rails bindings for opal JS engine
310
275
  test_files:
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "c_lexer"
6
- gem "rails", "~> 5.1.0"
7
- gem "opal", "~> 1.0.0"
8
- gem "opal-rspec", git: "https://github.com/opal/opal-rspec.git", branch: :master
9
- gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: :master
10
- gem "opal-sprockets"
11
-
12
- gemspec path: "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "c_lexer"
6
- gem "rails", "~> 5.1.0"
7
- gem "opal", git: "https://github.com/opal/opal.git", branch: :master
8
- gem "opal-rspec", git: "https://github.com/opal/opal-rspec.git", branch: :master
9
- gem "opal-sprockets", git: "https://github.com/opal/opal-sprockets.git", branch: :master
10
-
11
- gemspec path: "../"
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "c_lexer"
6
- gem "rails", "~> 5.2.0"
7
- gem "opal", "~> 1.0.0"
8
- gem "opal-rspec", git: "https://github.com/opal/opal-rspec.git", branch: :master
9
- gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: :master
10
- gem "opal-sprockets"
11
-
12
- gemspec path: "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "c_lexer"
6
- gem "rails", "~> 5.2.0"
7
- gem "opal", git: "https://github.com/opal/opal.git", branch: :master
8
- gem "opal-rspec", git: "https://github.com/opal/opal-rspec.git", branch: :master
9
- gem "opal-sprockets", git: "https://github.com/opal/opal-sprockets.git", branch: :master
10
-
11
- gemspec path: "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "c_lexer"
6
- gem "rails", "~> 6.0.0"
7
- gem "opal", git: "https://github.com/opal/opal.git", branch: :master
8
- gem "opal-rspec", git: "https://github.com/opal/opal-rspec.git", branch: :master
9
- gem "opal-sprockets", git: "https://github.com/opal/opal-sprockets.git", branch: :master
10
-
11
- gemspec path: "../"
@@ -1,12 +0,0 @@
1
- require 'rails/generators/named_base'
2
-
3
- module Opal
4
- module Generators
5
- class AssetsGenerator < ::Rails::Generators::NamedBase
6
- source_root __dir__+'/templates'
7
- def copy_opal
8
- template 'javascript.js.rb', File.join('app/assets/javascripts', class_path, "#{file_name}.js.rb")
9
- end
10
- end
11
- end
12
- end
data/test_apps/rails5.rb DELETED
@@ -1,50 +0,0 @@
1
- # FROM: http://www.rubytutorial.io/how-to-test-your-gem-against-multiple-rails/
2
-
3
- # test/apps/rails5.rb
4
- require 'rails'
5
- require 'rails/all'
6
- require 'action_view/testing/resolvers'
7
-
8
- require 'opal-rails' # our gem
9
-
10
- module RailsApp
11
- class Application < Rails::Application
12
- config.root = __dir__
13
- config.cache_classes = true
14
- config.eager_load = false
15
- config.public_file_server.enabled = true
16
- config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
17
- config.consider_all_requests_local = true
18
- config.action_controller.perform_caching = false
19
- config.action_dispatch.show_exceptions = false
20
- config.action_controller.allow_forgery_protection = false
21
- config.active_support.deprecation = :stderr
22
- config.secret_key_base = '49837489qkuweoiuoqwe'
23
-
24
- if config.active_record.sqlite3
25
- config.active_record.sqlite3.represent_boolean_as_integer = true
26
- end
27
-
28
- config.middleware.delete Rack::Lock
29
- config.middleware.delete ActionDispatch::Flash
30
-
31
- routes.append do
32
- get '/' => 'application#index'
33
- get '/application/with_assignments' => 'application#with_assignments'
34
-
35
- # just to reduce noise
36
- get '/apple-touch-icon-precomposed.png' => -> { [404,{},[]] }
37
- get '/favicon.ico' => -> { [404,{},[]] }
38
- end
39
-
40
- config.assets.paths << File.join(__dir__, 'assets/javascripts')
41
- config.assets.debug = true
42
- config.assets.digest = true
43
-
44
- # Opal specific:
45
- config.opal.source_map_enabled = true
46
- end
47
- end
48
-
49
- require_relative './application_controller'
50
- RailsApp::Application.initialize!