opal-rails 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +3 -2
- data/Appraisals +2 -2
- data/CHANGELOG.md +4 -0
- data/README.md +62 -17
- data/gemfiles/{rails_6_0_opal_1_4.gemfile → rails_6_0_opal_1_7.gemfile} +1 -1
- data/gemfiles/{rails_6_1_opal_1_4.gemfile → rails_6_1_opal_1_7.gemfile} +1 -1
- data/gemfiles/{rails_7_0_opal_1_4.gemfile → rails_7_0_opal_1_7.gemfile} +1 -1
- data/lib/generators/opal/install/templates/application.js.rb +1 -1
- data/lib/opal/rails/haml5_filter.rb +28 -0
- data/lib/opal/rails/haml6_filter.rb +23 -0
- data/lib/opal/rails/haml_filter.rb +6 -21
- data/lib/opal/rails/version.rb +1 -1
- data/opal-rails.gemspec +3 -1
- data/spec/integration/haml_filter_spec.rb +7 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/capybara.rb +1 -10
- data/test_apps/app/application_controller.rb +9 -0
- data/test_apps/app/assets/javascripts/with_assignments.js.rb +1 -1
- data/test_apps/rails.rb +4 -2
- metadata +25 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 875fb1f95adc2d5c12870d36c2fbd91b527d7d3361c97bb11651f83cb5206a93
|
4
|
+
data.tar.gz: 1640ba02072c130623acc881a00b91702720a21d6894c1bca9a2c44fdd0be7ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54b2acdaa18cd7354ab49623b951aa2c23f3a1da08bbebd5bddefbc18e56688b9777d7b1afb6c8648a200f335d24bf796d9d7dc2f87d47f2cc9f7a0bac3aa0ff
|
7
|
+
data.tar.gz: 471d1b6825196c2fe29310bf674fba3c0117452218bc8f56722435f81513e673e72a2ebce8f698d524973f15d5d4ead2acb6917b6eccdb5b98ada75463114cb1
|
data/.github/workflows/build.yml
CHANGED
@@ -11,10 +11,11 @@ on:
|
|
11
11
|
jobs:
|
12
12
|
build:
|
13
13
|
strategy:
|
14
|
+
fail-fast: false
|
14
15
|
matrix:
|
15
|
-
ruby: ['
|
16
|
+
ruby: ['3.0', '3.1', '3.2']
|
16
17
|
rails: ['rails_6_0', 'rails_6_1', 'rails_7_0']
|
17
|
-
opal: ['opal_1_0', 'opal_1_3', '
|
18
|
+
opal: ['opal_1_0', 'opal_1_3', 'opal_1_7']
|
18
19
|
runs-on: ubuntu-latest
|
19
20
|
|
20
21
|
steps:
|
data/Appraisals
CHANGED
@@ -7,8 +7,8 @@ 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
|
-
gemfile.gem 'opal', '~> 1.
|
10
|
+
opal_1_7: -> gemfile do
|
11
|
+
gemfile.gem 'opal', '~> 1.7.0'
|
12
12
|
gemfile.gem 'opal-sprockets'
|
13
13
|
end,
|
14
14
|
|
data/CHANGELOG.md
CHANGED
@@ -18,7 +18,11 @@ Whitespace conventions:
|
|
18
18
|
- 1 spaces before normal text
|
19
19
|
-->
|
20
20
|
|
21
|
+
## [2.0.3](https://github.com/opal/opal-rails/compare/v2.0.2...v2.0.3) - 2021-12-29
|
21
22
|
|
23
|
+
### Added
|
24
|
+
|
25
|
+
- Add HAML 6 support
|
22
26
|
|
23
27
|
## [2.0.2](https://github.com/opal/opal-rails/compare/v2.0.1...v2.0.2) - 2021-12-29
|
24
28
|
|
data/README.md
CHANGED
@@ -23,10 +23,10 @@ In your `Gemfile`
|
|
23
23
|
gem 'opal-rails'
|
24
24
|
```
|
25
25
|
|
26
|
-
|
26
|
+
Run `opal:install` Rails generator to add `app/assets/javascript` to your asset-pipeline manifest in `app/assets/config/manifest.js`:
|
27
27
|
|
28
28
|
```
|
29
|
-
bin/rails opal:install
|
29
|
+
bin/rails g opal:install
|
30
30
|
```
|
31
31
|
|
32
32
|
|
@@ -34,31 +34,36 @@ bin/rails opal:install
|
|
34
34
|
|
35
35
|
#### For the compiler
|
36
36
|
|
37
|
-
|
37
|
+
The following automatically gets added to your configuration for the compiler when running the `opal:install` Rails generator:
|
38
38
|
|
39
39
|
`config/initializers/opal.rb`
|
40
40
|
|
41
41
|
```ruby
|
42
42
|
# Compiler options
|
43
|
-
Rails.application.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
Rails.application.configure do
|
44
|
+
config.opal.method_missing_enabled = true
|
45
|
+
config.opal.const_missing_enabled = true
|
46
|
+
config.opal.arity_check_enabled = true
|
47
|
+
config.opal.freezing_stubs_enabled = true
|
48
|
+
config.opal.dynamic_require_severity = :ignore
|
49
|
+
end
|
48
50
|
```
|
49
51
|
|
50
52
|
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).
|
51
53
|
|
52
54
|
#### For template assigns
|
53
55
|
|
54
|
-
|
56
|
+
You may optionally add configuration for rendering assigns when using the template handler from actions:
|
55
57
|
|
56
58
|
`config/initializers/opal.rb`
|
57
59
|
|
58
60
|
```ruby
|
59
|
-
Rails.application.
|
60
|
-
|
61
|
-
|
61
|
+
Rails.application.configure do
|
62
|
+
# ...
|
63
|
+
config.opal.assigns_in_templates = true
|
64
|
+
config.opal.assigns_in_templates = :locals # only locals
|
65
|
+
config.opal.assigns_in_templates = :ivars # only instance variables
|
66
|
+
end
|
62
67
|
```
|
63
68
|
|
64
69
|
|
@@ -69,6 +74,42 @@ Local and instance variables will be sent down to the view after converting thei
|
|
69
74
|
|
70
75
|
### Basic example
|
71
76
|
|
77
|
+
#### Rails 7 example
|
78
|
+
|
79
|
+
This example assumes Rails 7 and having followed the [Installation](#installation) instructions.
|
80
|
+
|
81
|
+
1- Delete `app/javascript/application.js`
|
82
|
+
|
83
|
+
2- Enable the following lines in the generated `app/assets/javascript/application.js.rb` below `require "opal"`:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
puts "hello world!"
|
87
|
+
require "native"
|
88
|
+
$$[:document].addEventListener :DOMContentLoaded do
|
89
|
+
$$[:document][:body][:innerHTML] = '<h2>Hello World!</h2>'
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
3- Run `rails g scaffold welcome`
|
94
|
+
|
95
|
+
4- Run `rails db:migrate`
|
96
|
+
|
97
|
+
5- Clear `app/views/welcomes/index.html.erb` (empty its content)
|
98
|
+
|
99
|
+
6- Run `rails s`
|
100
|
+
|
101
|
+
7- Visit `http://localhost:3000/welcomes`
|
102
|
+
|
103
|
+
In the browser webpage, you should see:
|
104
|
+
|
105
|
+
<h2>Hello World!</h2>
|
106
|
+
|
107
|
+
Also, you should see `hello world!` in the browser console.
|
108
|
+
|
109
|
+
#### Rails 5 example
|
110
|
+
|
111
|
+
This example assumes Rails 5.
|
112
|
+
|
72
113
|
1. Rename `app/assets/javascripts/application.js` to `app/assets/javascripts/application.js.rb`
|
73
114
|
2. Replace the Sprockets directives with plain requires
|
74
115
|
|
@@ -88,7 +129,7 @@ require_tree '.'
|
|
88
129
|
puts "hello world!"
|
89
130
|
```
|
90
131
|
|
91
|
-
|
132
|
+
#### A more extensive Rails 5 example
|
92
133
|
|
93
134
|
```ruby
|
94
135
|
require 'opal'
|
@@ -166,12 +207,16 @@ post.find('.comments').html = comments_html
|
|
166
207
|
|
167
208
|
#### Instance and local variables in templates
|
168
209
|
|
169
|
-
By default `opal-rails
|
210
|
+
By default `opal-rails`, will NOT forward any instance and local variable you'll pass to the template.
|
170
211
|
|
171
|
-
This behavior can be
|
212
|
+
This behavior can be enabled by setting `Rails.application.config.opal.assigns_in_templates` to `true` in `config/initializers/assets.rb`:
|
172
213
|
|
173
214
|
```ruby
|
174
|
-
Rails.application.
|
215
|
+
Rails.application.configure do
|
216
|
+
# ...
|
217
|
+
config.opal.assigns_in_templates = true
|
218
|
+
# ...
|
219
|
+
end
|
175
220
|
```
|
176
221
|
|
177
222
|
|
@@ -293,7 +338,7 @@ bin/rails s # will start the sandbox app server
|
|
293
338
|
|
294
339
|
## License
|
295
340
|
|
296
|
-
© 2012-
|
341
|
+
© 2012-2022 Elia Schito
|
297
342
|
|
298
343
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
299
344
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Haml::Filters::Opal
|
2
|
+
include Haml::Filters::Base
|
3
|
+
|
4
|
+
def mime_type
|
5
|
+
::Opal::Config.esm ? 'module' : 'text/javascript'
|
6
|
+
end
|
7
|
+
|
8
|
+
def render_with_options ruby, options
|
9
|
+
text = ::Opal.compile(ruby)
|
10
|
+
|
11
|
+
if options[:format] == :html5
|
12
|
+
type = ''
|
13
|
+
else
|
14
|
+
type = " type=#{options[:attr_wrapper]}#{mime_type}#{options[:attr_wrapper]}"
|
15
|
+
end
|
16
|
+
|
17
|
+
text.rstrip!
|
18
|
+
text.gsub!("\n", "\n ")
|
19
|
+
|
20
|
+
<<HTML
|
21
|
+
<script#{type}>
|
22
|
+
//<![CDATA[
|
23
|
+
#{text}
|
24
|
+
//]]>
|
25
|
+
</script>
|
26
|
+
HTML
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "haml"
|
2
|
+
require "haml/filters"
|
3
|
+
require "haml/filters/base"
|
4
|
+
|
5
|
+
module Haml
|
6
|
+
class Filters
|
7
|
+
class Opal < Base
|
8
|
+
def mime_type
|
9
|
+
end
|
10
|
+
|
11
|
+
def compile(node)
|
12
|
+
template = [:multi]
|
13
|
+
template << [:static, "<script type='#{mime_type}'>\n"]
|
14
|
+
template << [:static, ::Opal.compile(node.value[:text]) ]
|
15
|
+
template << [:static, "\n</script>"]
|
16
|
+
template
|
17
|
+
end
|
18
|
+
end
|
19
|
+
::Opal::Config.esm ? 'module' : 'text/javascript'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Haml::Filters.registered[:opal] ||= Haml::Filters::Opal
|
@@ -1,24 +1,9 @@
|
|
1
|
-
|
2
|
-
include Haml::Filters::Base
|
1
|
+
require 'haml'
|
3
2
|
|
4
|
-
|
5
|
-
text = ::Opal.compile(ruby)
|
3
|
+
haml_version = Haml::VERSION.to_i
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
text.rstrip!
|
14
|
-
text.gsub!("\n", "\n ")
|
15
|
-
|
16
|
-
<<HTML
|
17
|
-
<script#{type}>
|
18
|
-
//<![CDATA[
|
19
|
-
#{text}
|
20
|
-
//]]>
|
21
|
-
</script>
|
22
|
-
HTML
|
23
|
-
end
|
5
|
+
if haml_version < 6
|
6
|
+
require 'opal/rails/haml5_filter'
|
7
|
+
else
|
8
|
+
require 'opal/rails/haml6_filter'
|
24
9
|
end
|
data/lib/opal/rails/version.rb
CHANGED
data/opal-rails.gemspec
CHANGED
@@ -35,10 +35,12 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_dependency 'opal', '~> 1.0'
|
36
36
|
spec.add_dependency 'opal-sprockets', '~> 1.0'
|
37
37
|
|
38
|
+
spec.add_development_dependency 'haml'
|
39
|
+
|
38
40
|
spec.add_development_dependency 'execjs'
|
39
41
|
spec.add_development_dependency 'launchy'
|
40
42
|
spec.add_development_dependency 'capybara', '~> 3.25'
|
41
|
-
spec.add_development_dependency '
|
43
|
+
spec.add_development_dependency 'cuprite'
|
42
44
|
spec.add_development_dependency 'rspec-rails'
|
43
45
|
spec.add_development_dependency 'appraisal', '~> 2.1'
|
44
46
|
spec.add_development_dependency 'sqlite3'
|
data/spec/spec_helper.rb
CHANGED
@@ -94,4 +94,24 @@ RSpec.configure do |config|
|
|
94
94
|
# test failures related to randomization by passing the same `--seed` value
|
95
95
|
# as the one that triggered the failure.
|
96
96
|
Kernel.srand config.seed
|
97
|
+
|
98
|
+
# Configure Capybara
|
99
|
+
Capybara.javascript_driver = :cuprite
|
100
|
+
Capybara.register_driver(:cuprite) do |app|
|
101
|
+
Capybara::Cuprite::Driver.new(app,
|
102
|
+
window_size: [1200, 800],
|
103
|
+
browser_options: { 'no-sandbox': nil },
|
104
|
+
inspector: ENV['INSPECTOR'],
|
105
|
+
headless: !ENV['NO_HEADLESS'],
|
106
|
+
timeout: 20,
|
107
|
+
url_blacklist: [],
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
Capybara.register_server :puma do |app, port, host|
|
112
|
+
require 'rack/handler/puma'
|
113
|
+
Rack::Handler::Puma.run(app, Host: host, Port: port, Threads: "0:4", Silent: true)
|
114
|
+
end
|
115
|
+
|
116
|
+
Capybara.default_max_wait_time = 5
|
97
117
|
end
|
data/spec/support/capybara.rb
CHANGED
@@ -1,14 +1,5 @@
|
|
1
1
|
require 'capybara/rspec'
|
2
|
-
require 'capybara/
|
3
|
-
|
4
|
-
Capybara.javascript_driver = :apparition
|
5
|
-
|
6
|
-
Capybara.register_server :puma do |app, port, host|
|
7
|
-
require 'rack/handler/puma'
|
8
|
-
Rack::Handler::Puma.run(app, Host: host, Port: port, Threads: "0:4", Silent: true)
|
9
|
-
end
|
10
|
-
|
11
|
-
Capybara.default_max_wait_time = 5
|
2
|
+
require 'capybara/cuprite'
|
12
3
|
|
13
4
|
module OpalHelper
|
14
5
|
def compile_opal(code)
|
@@ -12,6 +12,11 @@ puts 'hello from a script tag!'
|
|
12
12
|
</script>
|
13
13
|
HTML
|
14
14
|
|
15
|
+
HAML = <<~HAML
|
16
|
+
:opal
|
17
|
+
$haml_filter = :working
|
18
|
+
HAML
|
19
|
+
|
15
20
|
WITH_ASSIGNMENTS = File.read "#{__dir__}/assets/javascripts/with_assignments.js.rb"
|
16
21
|
|
17
22
|
require_relative '../../app/helpers/opal_helper'
|
@@ -23,6 +28,7 @@ class ApplicationController < ActionController::Base
|
|
23
28
|
self.view_paths = [ActionView::FixtureResolver.new(
|
24
29
|
'layouts/application.html.erb' => LAYOUT,
|
25
30
|
'application/index.html.erb' => INDEX,
|
31
|
+
'application/haml_filter.html.haml' => HAML,
|
26
32
|
'application/with_assignments.js.opal' => WITH_ASSIGNMENTS,
|
27
33
|
)]
|
28
34
|
|
@@ -43,6 +49,9 @@ class ApplicationController < ActionController::Base
|
|
43
49
|
|
44
50
|
render type: :js, locals: { local_var: 'i am local' }
|
45
51
|
end
|
52
|
+
|
53
|
+
def haml_filter
|
54
|
+
end
|
46
55
|
end
|
47
56
|
|
48
57
|
Rails.logger = Logger.new(STDOUT) if $DEBUG
|
data/test_apps/rails.rb
CHANGED
@@ -5,6 +5,7 @@ require 'rails/all'
|
|
5
5
|
require 'action_view/testing/resolvers'
|
6
6
|
|
7
7
|
require 'opal-rails' # our gem
|
8
|
+
require 'opal/rails/haml_filter'
|
8
9
|
|
9
10
|
module RailsApp
|
10
11
|
class Application < Rails::Application
|
@@ -30,10 +31,11 @@ module RailsApp
|
|
30
31
|
routes.append do
|
31
32
|
get '/' => 'application#index'
|
32
33
|
get '/application/with_assignments' => 'application#with_assignments'
|
34
|
+
get '/application/haml_filter' => 'application#haml_filter'
|
33
35
|
|
34
36
|
# just to reduce noise
|
35
|
-
get '/apple-touch-icon-precomposed.png' =>
|
36
|
-
get '/favicon.ico' =>
|
37
|
+
get '/apple-touch-icon-precomposed.png' => proc { [404,{},[]] }
|
38
|
+
get '/favicon.ico' => proc { [404,{},[]] }
|
37
39
|
end
|
38
40
|
|
39
41
|
config.assets.debug = true
|
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: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elia Schito
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '1.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: haml
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: execjs
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,7 +129,7 @@ dependencies:
|
|
115
129
|
- !ruby/object:Gem::Version
|
116
130
|
version: '3.25'
|
117
131
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
132
|
+
name: cuprite
|
119
133
|
requirement: !ruby/object:Gem::Requirement
|
120
134
|
requirements:
|
121
135
|
- - ">="
|
@@ -214,14 +228,14 @@ files:
|
|
214
228
|
- gemfiles/rails_6_0_opal_1_0.gemfile
|
215
229
|
- gemfiles/rails_6_0_opal_1_1.gemfile
|
216
230
|
- gemfiles/rails_6_0_opal_1_3.gemfile
|
217
|
-
- gemfiles/
|
231
|
+
- gemfiles/rails_6_0_opal_1_7.gemfile
|
218
232
|
- gemfiles/rails_6_1_opal_1_0.gemfile
|
219
233
|
- gemfiles/rails_6_1_opal_1_1.gemfile
|
220
234
|
- gemfiles/rails_6_1_opal_1_3.gemfile
|
221
|
-
- gemfiles/
|
235
|
+
- gemfiles/rails_6_1_opal_1_7.gemfile
|
222
236
|
- gemfiles/rails_7_0_opal_1_0.gemfile
|
223
237
|
- gemfiles/rails_7_0_opal_1_3.gemfile
|
224
|
-
- gemfiles/
|
238
|
+
- gemfiles/rails_7_0_opal_1_7.gemfile
|
225
239
|
- lib/assets/javascripts/opal_ujs.js.rb
|
226
240
|
- lib/generators/opal/assets/assets_generator.rb
|
227
241
|
- lib/generators/opal/assets/templates/javascript.js.rb
|
@@ -232,6 +246,8 @@ files:
|
|
232
246
|
- lib/opal-rails.rb
|
233
247
|
- lib/opal/rails.rb
|
234
248
|
- lib/opal/rails/engine.rb
|
249
|
+
- lib/opal/rails/haml5_filter.rb
|
250
|
+
- lib/opal/rails/haml6_filter.rb
|
235
251
|
- lib/opal/rails/haml_filter.rb
|
236
252
|
- lib/opal/rails/slim_filter.rb
|
237
253
|
- lib/opal/rails/template_handler.rb
|
@@ -239,6 +255,7 @@ files:
|
|
239
255
|
- opal-rails.gemspec
|
240
256
|
- spec/helpers/opal_helper_spec.rb
|
241
257
|
- spec/integration/assigns_spec.rb
|
258
|
+
- spec/integration/haml_filter_spec.rb
|
242
259
|
- spec/integration/js_spec.rb
|
243
260
|
- spec/integration/source_map_spec.rb
|
244
261
|
- spec/spec_helper.rb
|
@@ -276,13 +293,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
276
293
|
- !ruby/object:Gem::Version
|
277
294
|
version: '0'
|
278
295
|
requirements: []
|
279
|
-
rubygems_version: 3.
|
296
|
+
rubygems_version: 3.4.10
|
280
297
|
signing_key:
|
281
298
|
specification_version: 4
|
282
299
|
summary: Rails bindings for opal JS engine
|
283
300
|
test_files:
|
284
301
|
- spec/helpers/opal_helper_spec.rb
|
285
302
|
- spec/integration/assigns_spec.rb
|
303
|
+
- spec/integration/haml_filter_spec.rb
|
286
304
|
- spec/integration/js_spec.rb
|
287
305
|
- spec/integration/source_map_spec.rb
|
288
306
|
- spec/spec_helper.rb
|