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
@@ -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.0.1
4
+ version: 2.0.1
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-07 00:00:00.000000000 Z
11
+ date: 2021-03-03 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,27 @@ 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
224
+ - lib/generators/opal/install/templates/initializer.rb
260
225
  - lib/opal-rails.rb
261
226
  - lib/opal/rails.rb
262
227
  - lib/opal/rails/engine.rb
@@ -264,32 +229,32 @@ files:
264
229
  - lib/opal/rails/slim_filter.rb
265
230
  - lib/opal/rails/template_handler.rb
266
231
  - 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
232
  - opal-rails.gemspec
270
233
  - spec/helpers/opal_helper_spec.rb
271
234
  - spec/integration/assigns_spec.rb
272
235
  - spec/integration/js_spec.rb
273
236
  - spec/integration/source_map_spec.rb
274
- - spec/integration/template_spec.rb
275
237
  - spec/spec_helper.rb
276
238
  - spec/support/capybara.rb
277
239
  - spec/support/reset_assets_cache.rb
278
240
  - spec/support/reset_config.rb
279
241
  - spec/support/test_app.rb
280
- - test_apps/application_controller.rb
281
- - test_apps/assets/javascripts/application.js.rb
282
- - test_apps/assets/javascripts/bar.rb
283
- - test_apps/assets/javascripts/foo.js.rb
284
- - test_apps/assets/javascripts/source_map_example.js.rb
285
- - test_apps/assets/javascripts/with_assignments.js.rb
286
- - test_apps/rails5.rb
242
+ - test_apps/app/application_controller.rb
243
+ - test_apps/app/assets/config/manifest.js
244
+ - test_apps/app/assets/javascripts/application.js.rb
245
+ - test_apps/app/assets/javascripts/bar.rb
246
+ - test_apps/app/assets/javascripts/foo.js.rb
247
+ - test_apps/app/assets/javascripts/source_map_example.js.rb
248
+ - test_apps/app/assets/javascripts/with_assignments.js.rb
287
249
  - test_apps/rails6.rb
288
250
  homepage: https://github.com/opal/opal-rails#readme
289
251
  licenses:
290
252
  - MIT-LICENSE
291
- metadata: {}
292
- post_install_message:
253
+ metadata:
254
+ homepage_uri: https://github.com/opal/opal-rails#readme
255
+ source_code_uri: https://github.com/opal/opal-rails#readme
256
+ changelog_uri: https://github.com/opal/opal-rails/blob/master/CHANGELOG.md
257
+ post_install_message:
293
258
  rdoc_options: []
294
259
  require_paths:
295
260
  - lib
@@ -297,15 +262,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
297
262
  requirements:
298
263
  - - ">="
299
264
  - !ruby/object:Gem::Version
300
- version: '0'
265
+ version: '2.5'
301
266
  required_rubygems_version: !ruby/object:Gem::Requirement
302
267
  requirements:
303
268
  - - ">="
304
269
  - !ruby/object:Gem::Version
305
270
  version: '0'
306
271
  requirements: []
307
- rubygems_version: 3.0.3
308
- signing_key:
272
+ rubygems_version: 3.2.3
273
+ signing_key:
309
274
  specification_version: 4
310
275
  summary: Rails bindings for opal JS engine
311
276
  test_files:
@@ -313,7 +278,6 @@ test_files:
313
278
  - spec/integration/assigns_spec.rb
314
279
  - spec/integration/js_spec.rb
315
280
  - spec/integration/source_map_spec.rb
316
- - spec/integration/template_spec.rb
317
281
  - spec/spec_helper.rb
318
282
  - spec/support/capybara.rb
319
283
  - spec/support/reset_assets_cache.rb
@@ -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
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'template handler' do
4
- it 'has the correct content type' do
5
- get '/application/with_assignments.js'
6
- expect(response).to be_successful
7
- expect(response.headers['Content-Type']).to eq('text/javascript; charset=utf-8')
8
- end
9
- 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!