opal-rails 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +10 -2
- data/lib/opal/rails/engine.rb +8 -0
- data/lib/opal/rails/template_handler.rb +12 -5
- data/lib/opal/rails/version.rb +1 -1
- data/spec/integration/assigns_spec.rb +58 -2
- metadata +2 -4
- data/spec/integration/template_spec.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9689895c742592771f0b6486befa7cbca683f1cde5a61ae52ec7091ca39c0411
|
4
|
+
data.tar.gz: d48912a6dcd903b1465a045ded9084307b53930558a6b9dfbe4c3622e7c5ae42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8621d6d34f9cf5b9901c7912a8a2f16b9b265f82f4ea7a6e87aef4f10206406d4bedb20e6bacb5545218fb70d05c8b41838912f5c8ed1250037d56e39caa1bcf
|
7
|
+
data.tar.gz: 1b858592dd83f05228e75d49c03bc4c33893e2657c396602734c6fc78fb27fc623e5bb6fce17026997f9dc76fcd81175059e663f53d6310a39519a98cb952517
|
data/CHANGELOG.md
CHANGED
@@ -21,6 +21,21 @@ Whitespace conventions:
|
|
21
21
|
|
22
22
|
|
23
23
|
|
24
|
+
## [1.1.0](https://github.com/opal/opal-rails/compare/v1.0.1...v1.1.0) - 2019-09-14
|
25
|
+
|
26
|
+
|
27
|
+
### Added
|
28
|
+
|
29
|
+
- 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`.
|
30
|
+
|
31
|
+
|
32
|
+
### Changed
|
33
|
+
|
34
|
+
- 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
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
24
39
|
## [1.0.1](https://github.com/opal/opal-rails/compare/v1.0.0...v1.0.1) - 2019-09-07
|
25
40
|
|
26
41
|
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
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
|
-
[![
|
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)
|
@@ -40,9 +40,17 @@ Rails.application.config.opal.optimized_operators = true
|
|
40
40
|
Rails.application.config.opal.arity_check = !Rails.env.production?
|
41
41
|
Rails.application.config.opal.const_missing = true
|
42
42
|
Rails.application.config.opal.dynamic_require_severity = :ignore
|
43
|
+
|
44
|
+
# Other options
|
45
|
+
|
46
|
+
# Send local and instance variables down to the view after converting
|
47
|
+
# thier value with `.to_json`
|
48
|
+
Rails.application.config.opal.assigns_in_templates = true
|
49
|
+
Rails.application.config.opal.assigns_in_templates = :locals # only locals
|
50
|
+
Rails.application.config.opal.assigns_in_templates = :ivars # only instance variables
|
43
51
|
```
|
44
52
|
|
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).
|
53
|
+
For a full list of the available configuration options for the compiler please refer to: [lib/opal/config.rb](https://github.com/opal/opal/blob/master/lib/opal/config.rb).
|
46
54
|
|
47
55
|
|
48
56
|
|
data/lib/opal/rails/engine.rb
CHANGED
@@ -12,6 +12,14 @@ module Opal
|
|
12
12
|
config.opal.dynamic_require_severity = :ignore
|
13
13
|
config.opal.assigns_in_templates = true
|
14
14
|
|
15
|
+
def (config.opal).assign_locals_in_templates?
|
16
|
+
assigns_in_templates == true || assigns_in_templates == :locals
|
17
|
+
end
|
18
|
+
|
19
|
+
def (config.opal).assign_instance_variables_in_templates?
|
20
|
+
assigns_in_templates == true || assigns_in_templates == :ivars
|
21
|
+
end
|
22
|
+
|
15
23
|
# Cache eager_load_paths now, otherwise the assets dir is added
|
16
24
|
# and its .rb files are eagerly loaded.
|
17
25
|
config.eager_load_paths
|
@@ -2,21 +2,28 @@ module Opal
|
|
2
2
|
module Rails
|
3
3
|
class TemplateHandler
|
4
4
|
|
5
|
-
def self.call(template)
|
6
|
-
new.call(template)
|
5
|
+
def self.call(template, source = template.source)
|
6
|
+
new.call(template, source)
|
7
7
|
end
|
8
8
|
|
9
|
-
def call(template)
|
10
|
-
escaped =
|
9
|
+
def call(template, source = template.source)
|
10
|
+
escaped = source.gsub(':', '\:')
|
11
11
|
string = '%q:' + escaped + ':'
|
12
12
|
|
13
13
|
<<-RUBY
|
14
|
+
config = ::Rails.application.config.opal
|
15
|
+
|
14
16
|
code = []
|
15
17
|
code << 'Object.new.instance_eval {'
|
16
|
-
|
18
|
+
|
19
|
+
if config.assign_locals_in_templates?
|
17
20
|
code << JSON.parse(local_assigns.to_json).map { |key, val| "\#{key} = \#{val.inspect};" }.join
|
21
|
+
end
|
22
|
+
|
23
|
+
if config.assign_instance_variables_in_templates?
|
18
24
|
code << JSON.parse(@_assigns.to_json).map { |key, val| "@\#{key} = \#{val.inspect};" }.join
|
19
25
|
end
|
26
|
+
|
20
27
|
code << #{string}
|
21
28
|
code << '}'
|
22
29
|
Opal.compile(code.join("\n"))
|
data/lib/opal/rails/version.rb
CHANGED
@@ -7,7 +7,7 @@ describe 'controller assignments' do
|
|
7
7
|
Rails.application.config.opal.assigns_in_templates = true
|
8
8
|
end
|
9
9
|
|
10
|
-
it '
|
10
|
+
it 'has them in the template' do
|
11
11
|
source = get_source_of '/application/with_assignments.js'
|
12
12
|
assignments = opal_eval(source)
|
13
13
|
|
@@ -29,7 +29,7 @@ describe 'controller assignments' do
|
|
29
29
|
Rails.application.config.opal.assigns_in_templates = false
|
30
30
|
end
|
31
31
|
|
32
|
-
it '
|
32
|
+
it 'has not them in the template' do
|
33
33
|
source = get_source_of '/application/with_assignments.js'
|
34
34
|
assignments = opal_eval(source)
|
35
35
|
{
|
@@ -45,6 +45,62 @@ describe 'controller assignments' do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
context 'when :locals' do
|
49
|
+
before do
|
50
|
+
Rails.application.config.opal.assigns_in_templates = :locals
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'has only locals in the template' do
|
54
|
+
source = get_source_of '/application/with_assignments.js'
|
55
|
+
assignments = opal_eval(source)
|
56
|
+
{
|
57
|
+
:number_var => 1234,
|
58
|
+
:string_var => 'hello',
|
59
|
+
:array_var => [1,'a'],
|
60
|
+
:hash_var => {:a => 1, :b => 2},
|
61
|
+
:object_var => {:contents => 'json representation'},
|
62
|
+
}.each_pair do |ivar, assignment|
|
63
|
+
expect(assignments[ivar]).not_to eq(assignment)
|
64
|
+
end
|
65
|
+
{
|
66
|
+
:local_var => 'i am local',
|
67
|
+
}.each_pair do |ivar, assignment|
|
68
|
+
expect(assignments[ivar]).to eq(assignment)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when :ivars' do
|
74
|
+
before do
|
75
|
+
Rails.application.config.opal.assigns_in_templates = :ivars
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'has only ivars in the template' do
|
79
|
+
source = get_source_of '/application/with_assignments.js'
|
80
|
+
assignments = opal_eval(source)
|
81
|
+
{
|
82
|
+
:number_var => 1234,
|
83
|
+
:string_var => 'hello',
|
84
|
+
:array_var => [1,'a'],
|
85
|
+
:hash_var => {:a => 1, :b => 2},
|
86
|
+
:object_var => {:contents => 'json representation'},
|
87
|
+
}.each_pair do |ivar, assignment|
|
88
|
+
expect(assignments[ivar]).to eq(assignment)
|
89
|
+
end
|
90
|
+
{
|
91
|
+
:local_var => 'i am local',
|
92
|
+
}.each_pair do |ivar, assignment|
|
93
|
+
expect(assignments[ivar]).not_to eq(assignment)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'has the correct content type' do
|
99
|
+
get '/application/with_assignments.js'
|
100
|
+
expect(response).to be_successful
|
101
|
+
expect(response.headers['Content-Type']).to eq('text/javascript; charset=utf-8')
|
102
|
+
end
|
103
|
+
|
48
104
|
def get_source_of path
|
49
105
|
get path
|
50
106
|
response.should be_successful
|
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
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elia Schito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -271,7 +271,6 @@ files:
|
|
271
271
|
- spec/integration/assigns_spec.rb
|
272
272
|
- spec/integration/js_spec.rb
|
273
273
|
- spec/integration/source_map_spec.rb
|
274
|
-
- spec/integration/template_spec.rb
|
275
274
|
- spec/spec_helper.rb
|
276
275
|
- spec/support/capybara.rb
|
277
276
|
- spec/support/reset_assets_cache.rb
|
@@ -313,7 +312,6 @@ test_files:
|
|
313
312
|
- spec/integration/assigns_spec.rb
|
314
313
|
- spec/integration/js_spec.rb
|
315
314
|
- spec/integration/source_map_spec.rb
|
316
|
-
- spec/integration/template_spec.rb
|
317
315
|
- spec/spec_helper.rb
|
318
316
|
- spec/support/capybara.rb
|
319
317
|
- spec/support/reset_assets_cache.rb
|
@@ -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
|