js-routes 1.4.5 → 1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -4
- data/Appraisals +2 -1
- data/CHANGELOG.md +4 -0
- data/gemfiles/rails52_sprockets_3.gemfile +8 -0
- data/js-routes.gemspec +1 -1
- data/lib/js_routes/version.rb +1 -1
- data/lib/routes.js +9 -2
- data/lib/routes.js.coffee +4 -2
- data/spec/js_routes/rails_routes_compatibility_spec.rb +17 -10
- data/spec/spec_helper.rb +14 -21
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e210567d580be40825a39c8fd5e13b15509f304f46e22909d6462e5fc1a1b817
|
4
|
+
data.tar.gz: 8c63da6abc92f0bc0478b3dba504151c42322253edf32c264137633d6469ccce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1515a6cd44bebc46459df4b404e4e839724aa5c5b8b4ded487f74a794592cef776666ed496dafdf4444c6cf9c672060efe44ed40c718952683dc748fd72c903
|
7
|
+
data.tar.gz: bd9e6b90de5410d71b1a98c490237962f25de377680994afdbfa0c27c19ce36ac049fc9d4a250a71a279517edb5b90a27fb75e3f4b0618ca5a42773612f17c3f
|
data/.travis.yml
CHANGED
@@ -9,9 +9,8 @@ rvm:
|
|
9
9
|
- 2.4.1
|
10
10
|
- 2.5.3
|
11
11
|
- 2.6.0
|
12
|
-
- jruby-19mode
|
13
12
|
- ruby-head
|
14
|
-
- jruby
|
13
|
+
- jruby
|
15
14
|
|
16
15
|
gemfile:
|
17
16
|
- gemfiles/rails40_sprockets_2.gemfile
|
@@ -22,8 +21,10 @@ gemfile:
|
|
22
21
|
- gemfiles/rails42_sprockets_3.gemfile
|
23
22
|
- gemfiles/rails50_sprockets_3.gemfile
|
24
23
|
- gemfiles/rails51_sprockets_3.gemfile
|
24
|
+
- gemfiles/rails52_sprockets_3.gemfile
|
25
25
|
|
26
26
|
sudo: false
|
27
|
+
dist: xenial
|
27
28
|
|
28
29
|
notifications:
|
29
30
|
email:
|
@@ -34,10 +35,10 @@ branches:
|
|
34
35
|
- master
|
35
36
|
|
36
37
|
matrix:
|
38
|
+
fast_finish: true
|
37
39
|
allow_failures:
|
38
|
-
- rvm: jruby-19mode
|
39
40
|
- rvm: ruby-head
|
40
|
-
- rvm: jruby
|
41
|
+
- rvm: jruby
|
41
42
|
exclude:
|
42
43
|
- rvm: 2.6.0
|
43
44
|
gemfile: gemfiles/rails40_sprockets_2.gemfile # Segmentation fault
|
data/Appraisals
CHANGED
@@ -12,7 +12,8 @@ end
|
|
12
12
|
[:rails41, '4.1.16', [2, 3]],
|
13
13
|
[:rails42, '4.2.9', [2, 3]],
|
14
14
|
[:rails50, '5.0.5', [3]],
|
15
|
-
[:rails51, '5.1.3', [3]]
|
15
|
+
[:rails51, '5.1.3', [3]],
|
16
|
+
[:rails52, '5.2.3', [3]]
|
16
17
|
].each do |name, version, sprockets|
|
17
18
|
define_appraisal(name, version, sprockets)
|
18
19
|
end
|
data/CHANGELOG.md
CHANGED
data/js-routes.gemspec
CHANGED
@@ -31,6 +31,6 @@ Gem::Specification.new do |s|
|
|
31
31
|
else
|
32
32
|
s.add_development_dependency(%q<byebug>)
|
33
33
|
s.add_development_dependency(%q<pry-byebug>)
|
34
|
-
s.add_development_dependency(%q<
|
34
|
+
s.add_development_dependency(%q<mini_racer>, [">= 0.2.4"])
|
35
35
|
end
|
36
36
|
end
|
data/lib/js_routes/version.rb
CHANGED
data/lib/routes.js
CHANGED
@@ -4,7 +4,7 @@ Based on Rails RAILS_VERSION routes of APP_CLASS
|
|
4
4
|
*/
|
5
5
|
|
6
6
|
(function() {
|
7
|
-
var DeprecatedGlobbingBehavior, NodeTypes, ParameterMissing, ReservedOptions, SpecialOptionsKey, Utils, root,
|
7
|
+
var DeprecatedGlobbingBehavior, NodeTypes, ParameterMissing, ReservedOptions, SpecialOptionsKey, UriEncoderSegmentRegex, Utils, root,
|
8
8
|
hasProp = {}.hasOwnProperty,
|
9
9
|
slice = [].slice;
|
10
10
|
|
@@ -45,6 +45,8 @@ Based on Rails RAILS_VERSION routes of APP_CLASS
|
|
45
45
|
|
46
46
|
SpecialOptionsKey = SPECIAL_OPTIONS_KEY;
|
47
47
|
|
48
|
+
UriEncoderSegmentRegex = /[^a-zA-Z0-9\-\._~!\$&'\(\)\*\+,;=:@]/g;
|
49
|
+
|
48
50
|
ReservedOptions = ['anchor', 'trailing_slash', 'subdomain', 'host', 'port', 'protocol'];
|
49
51
|
|
50
52
|
Utils = {
|
@@ -283,7 +285,7 @@ Based on Rails RAILS_VERSION routes of APP_CLASS
|
|
283
285
|
value = parameters[left];
|
284
286
|
delete parameters[left];
|
285
287
|
if (value != null) {
|
286
|
-
return
|
288
|
+
return this.encode_segment(this.path_identifier(value));
|
287
289
|
}
|
288
290
|
if (optional) {
|
289
291
|
return "";
|
@@ -295,6 +297,11 @@ Based on Rails RAILS_VERSION routes of APP_CLASS
|
|
295
297
|
throw new Error("Unknown Rails node type");
|
296
298
|
}
|
297
299
|
},
|
300
|
+
encode_segment: function(segment) {
|
301
|
+
return segment.replace(UriEncoderSegmentRegex, function(str) {
|
302
|
+
return encodeURIComponent(str);
|
303
|
+
});
|
304
|
+
},
|
298
305
|
is_optional_node: function(node) {
|
299
306
|
return this.indexOf([NodeTypes.STAR, NodeTypes.SYMBOL, NodeTypes.CAT], node) >= 0;
|
300
307
|
},
|
data/lib/routes.js.coffee
CHANGED
@@ -29,6 +29,7 @@ else
|
|
29
29
|
NodeTypes = NODE_TYPES
|
30
30
|
DeprecatedGlobbingBehavior = DEPRECATED_GLOBBING_BEHAVIOR
|
31
31
|
SpecialOptionsKey = SPECIAL_OPTIONS_KEY
|
32
|
+
UriEncoderSegmentRegex = /[^a-zA-Z0-9\-\._~!\$&'\(\)\*\+,;=:@]/g # this is ActionDispatch::Journey::Router::Utils::UriEncoder::SEGMENT
|
32
33
|
|
33
34
|
ReservedOptions = [
|
34
35
|
'anchor'
|
@@ -212,7 +213,7 @@ Utils =
|
|
212
213
|
value = parameters[left]
|
213
214
|
delete parameters[left]
|
214
215
|
if value?
|
215
|
-
return
|
216
|
+
return @encode_segment(@path_identifier(value))
|
216
217
|
if optional
|
217
218
|
"" # missing parameter
|
218
219
|
else
|
@@ -225,6 +226,7 @@ Utils =
|
|
225
226
|
else
|
226
227
|
throw new Error("Unknown Rails node type")
|
227
228
|
|
229
|
+
encode_segment: (segment) -> segment.replace(UriEncoderSegmentRegex, (str) -> encodeURIComponent(str))
|
228
230
|
|
229
231
|
is_optional_node: (node) -> @indexOf([NodeTypes.STAR, NodeTypes.SYMBOL, NodeTypes.CAT], node) >= 0
|
230
232
|
|
@@ -401,7 +403,7 @@ Utils =
|
|
401
403
|
routes.default_serializer = (object, prefix) ->
|
402
404
|
Utils.default_serializer(object, prefix)
|
403
405
|
Utils.namespace(root, NAMESPACE, routes)
|
404
|
-
|
406
|
+
|
405
407
|
# Set up Routes appropriately for the environment.
|
406
408
|
if typeof define is "function" and define.amd
|
407
409
|
# AMD
|
@@ -14,15 +14,15 @@ describe JsRoutes, "compatibility with Rails" do
|
|
14
14
|
expect(evaljs("Routes.inbox_path(1)")).to eq(test_routes.inbox_path(1))
|
15
15
|
end
|
16
16
|
|
17
|
-
it "should raise error if required argument is not passed" do
|
17
|
+
it "should raise error if required argument is not passed", :aggregate_failures do
|
18
18
|
expect { evaljs("Routes.thing_path()") }
|
19
|
-
.to raise_error(
|
19
|
+
.to raise_error(/Route parameter missing: id/)
|
20
20
|
expect { evaljs("Routes.search_path()") }
|
21
|
-
.to raise_error(
|
21
|
+
.to raise_error(/Route parameter missing: q/)
|
22
22
|
expect { evaljs("Routes.book_path()") }
|
23
|
-
.to raise_error(
|
23
|
+
.to raise_error(/Route parameter missing: title/)
|
24
24
|
expect { evaljs("Routes.book_title_path()") }
|
25
|
-
.to raise_error(
|
25
|
+
.to raise_error(/Route parameter missing: title/)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should produce error stacktraces including function names" do
|
@@ -81,6 +81,16 @@ describe JsRoutes, "compatibility with Rails" do
|
|
81
81
|
expect(evaljs("Routes.budgie_descendents_path(1)")).to eq(test_routes.budgie_descendents_path(1))
|
82
82
|
end
|
83
83
|
|
84
|
+
it "should support route with parameters containing symbols that need URI-encoding", :aggregate_failures do
|
85
|
+
expect(evaljs("Routes.inbox_path('#hello')")).to eq(test_routes.inbox_path('#hello'))
|
86
|
+
expect(evaljs("Routes.inbox_path('some param')")).to eq(test_routes.inbox_path('some param'))
|
87
|
+
expect(evaljs("Routes.inbox_path('some param with more & more encode symbols')")).to eq(test_routes.inbox_path('some param with more & more encode symbols'))
|
88
|
+
end
|
89
|
+
it "should support route with parameters containing symbols not need URI-encoding", :aggregate_failures do
|
90
|
+
expect(evaljs("Routes.inbox_path(':some_id')")).to eq(test_routes.inbox_path(':some_id'))
|
91
|
+
expect(evaljs("Routes.inbox_path('.+')")).to eq(test_routes.inbox_path('.+'))
|
92
|
+
end
|
93
|
+
|
84
94
|
describe "when route has defaults" do
|
85
95
|
it "should support route default format" do
|
86
96
|
expect(evaljs("Routes.api_purchases_path()")).to eq(test_routes.api_purchases_path)
|
@@ -115,9 +125,6 @@ describe JsRoutes, "compatibility with Rails" do
|
|
115
125
|
it "should support route with parameters" do
|
116
126
|
expect(evaljs("Routes.blog_app_post_path(1)")).to eq(blog_routes.post_path(1))
|
117
127
|
end
|
118
|
-
it "should support route with parameters containing symbols that need URI-encoding" do
|
119
|
-
expect(evaljs("Routes.blog_app_post_path('#hello')")).to eq(blog_routes.post_path('#hello'))
|
120
|
-
end
|
121
128
|
it "should support root path" do
|
122
129
|
expect(evaljs("Routes.blog_app_root_path()")).to eq(blog_routes.root_path)
|
123
130
|
end
|
@@ -228,7 +235,7 @@ describe JsRoutes, "compatibility with Rails" do
|
|
228
235
|
|
229
236
|
it "should raise error when passing non-full list of arguments and some query params" do
|
230
237
|
expect { evaljs("Routes.thing_path(5, {q: 'hello'})") }
|
231
|
-
.to raise_error(
|
238
|
+
.to raise_error(/Route parameter missing: id/)
|
232
239
|
end
|
233
240
|
|
234
241
|
it "should treat null as non-given optional part" do
|
@@ -246,7 +253,7 @@ describe JsRoutes, "compatibility with Rails" do
|
|
246
253
|
|
247
254
|
context "and including them" do
|
248
255
|
it "should fail when insufficient arguments are given" do
|
249
|
-
expect { evaljs("Routes.thing_deep_path(2)") }.to raise_error(
|
256
|
+
expect { evaljs("Routes.thing_deep_path(2)") }.to raise_error(/Route parameter missing: third_required/)
|
250
257
|
end
|
251
258
|
|
252
259
|
it "should include the optional parts" do
|
data/spec/spec_helper.rb
CHANGED
@@ -12,8 +12,8 @@ if defined?(JRUBY_VERSION)
|
|
12
12
|
require 'rhino'
|
13
13
|
JS_LIB_CLASS = Rhino
|
14
14
|
else
|
15
|
-
require '
|
16
|
-
JS_LIB_CLASS =
|
15
|
+
require 'mini_racer'
|
16
|
+
JS_LIB_CLASS = MiniRacer
|
17
17
|
end
|
18
18
|
|
19
19
|
def jscontext(force = false)
|
@@ -25,7 +25,11 @@ def jscontext(force = false)
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def js_error_class
|
28
|
-
|
28
|
+
if defined?(JRUBY_VERSION)
|
29
|
+
JS_LIB_CLASS::JSError
|
30
|
+
else
|
31
|
+
JS_LIB_CLASS::Error
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def evaljs(string, force = false)
|
@@ -89,25 +93,14 @@ RSpec.configure do |config|
|
|
89
93
|
config.before :each do
|
90
94
|
evaljs("var window = this;", true)
|
91
95
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
value.map do |v|
|
96
|
-
inspectify(v)
|
97
|
-
end
|
98
|
-
when V8::Object
|
99
|
-
value.to_h.map do |k,v|
|
100
|
-
[k, inspectify(v)]
|
101
|
-
end.to_h
|
102
|
-
when String, nil, Integer, FalseClass, TrueClass
|
103
|
-
value
|
104
|
-
else
|
105
|
-
raise "wtf #{value.class}?"
|
96
|
+
if defined?(JRUBY_VERSION)
|
97
|
+
jscontext[:log] = lambda do |context, value|
|
98
|
+
puts value
|
106
99
|
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
100
|
+
else
|
101
|
+
jscontext.attach("log", proc do |value|
|
102
|
+
puts value
|
103
|
+
end)
|
111
104
|
end
|
112
105
|
end
|
113
106
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -123,19 +123,19 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: mini_racer
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.
|
131
|
+
version: 0.2.4
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.
|
138
|
+
version: 0.2.4
|
139
139
|
description: Generates javascript file that defines all Rails named routes as javascript
|
140
140
|
helpers
|
141
141
|
email: agresso@gmail.com
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- gemfiles/rails42_sprockets_3.gemfile
|
164
164
|
- gemfiles/rails50_sprockets_3.gemfile
|
165
165
|
- gemfiles/rails51_sprockets_3.gemfile
|
166
|
+
- gemfiles/rails52_sprockets_3.gemfile
|
166
167
|
- js-routes.gemspec
|
167
168
|
- lib/js-routes.rb
|
168
169
|
- lib/js_routes.rb
|