js-routes 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -2
- data/lib/js_routes/version.rb +1 -1
- data/lib/routes.js +5 -2
- data/lib/routes.js.coffee +6 -4
- data/spec/js_routes/options_spec.rb +11 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50875d687cd46f55c34450970c84faddd4ff970c
|
4
|
+
data.tar.gz: cb98a4d6b4feb6a3cb60631c22dc8ac4e7638c10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c49eefb28fc5ad6edb1378b4718397c7996b6f9f7b356a53336c8becfa4d162af71a3dc4606a2fc2a04f958e4b2eec70adbdbcad642e130f662842422edd1357
|
7
|
+
data.tar.gz: 49f4bb3f3988f61e7853d7a392b902212715bd3f537cd9bbf3c51b72f8781ee3c9a9d5d9ded33989be35e2269c948f9274caf0f59bc54bb21f207fce33814a7a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
## master
|
2
2
|
|
3
|
+
## v1.4.1
|
4
|
+
|
5
|
+
* Fixed bug when js-routes is used in envs without window.location #224
|
6
|
+
|
7
|
+
|
8
|
+
## v1.4.0
|
9
|
+
|
3
10
|
* __breaking change!__ Implemented Routes.config() and Routes.configure instead of Routes.defaults
|
4
11
|
|
5
12
|
New methods support 4 options at the moment:
|
@@ -11,7 +18,7 @@ Routes.configuration(); // =>
|
|
11
18
|
prefix: "",
|
12
19
|
default_url_options: {},
|
13
20
|
special_options_key: '_options',
|
14
|
-
|
21
|
+
serializer: function(...) { ... }
|
15
22
|
}
|
16
23
|
*/
|
17
24
|
|
@@ -19,7 +26,7 @@ Routes.configure({
|
|
19
26
|
prefix: '/app',
|
20
27
|
default_url_options: {format: 'json'},
|
21
28
|
special_options_key: '_my_options_key',
|
22
|
-
|
29
|
+
serializer: function(...) { ... }
|
23
30
|
});
|
24
31
|
```
|
25
32
|
|
data/lib/js_routes/version.rb
CHANGED
data/lib/routes.js
CHANGED
@@ -356,14 +356,17 @@ Based on Rails routes of APP_CLASS
|
|
356
356
|
if (typeof route_defaults === 'string') {
|
357
357
|
return route_defaults;
|
358
358
|
}
|
359
|
+
hostname = route_defaults.host || Utils.current_host();
|
360
|
+
if (!hostname) {
|
361
|
+
return '';
|
362
|
+
}
|
359
363
|
protocol = route_defaults.protocol || Utils.current_protocol();
|
360
|
-
hostname = route_defaults.host || window.location.hostname;
|
361
364
|
port = route_defaults.port || (!route_defaults.host ? Utils.current_port() : void 0);
|
362
365
|
port = port ? ":" + port : '';
|
363
366
|
return protocol + "://" + hostname + port;
|
364
367
|
},
|
365
368
|
has_location: function() {
|
366
|
-
return typeof window !==
|
369
|
+
return (typeof window !== "undefined" && window !== null ? window.location : void 0) != null;
|
367
370
|
},
|
368
371
|
current_host: function() {
|
369
372
|
if (this.has_location()) {
|
data/lib/routes.js.coffee
CHANGED
@@ -276,16 +276,18 @@ Utils =
|
|
276
276
|
|
277
277
|
route_url: (route_defaults) ->
|
278
278
|
return route_defaults if typeof route_defaults == 'string'
|
279
|
+
|
280
|
+
hostname = route_defaults.host || Utils.current_host()
|
281
|
+
|
282
|
+
return '' unless hostname
|
283
|
+
|
279
284
|
protocol = route_defaults.protocol || Utils.current_protocol()
|
280
|
-
hostname = route_defaults.host || window.location.hostname
|
281
285
|
port = route_defaults.port || (Utils.current_port() unless route_defaults.host)
|
282
286
|
port = if port then ":#{port}" else ''
|
283
287
|
|
284
288
|
protocol + "://" + hostname + port
|
285
289
|
|
286
|
-
|
287
|
-
has_location: ->
|
288
|
-
typeof window != 'undefined' && typeof window.location != 'undefined'
|
290
|
+
has_location: -> window?.location?
|
289
291
|
|
290
292
|
current_host: ->
|
291
293
|
if @has_location() then window.location.hostname else null
|
@@ -425,6 +425,17 @@ describe JsRoutes, "options" do
|
|
425
425
|
end
|
426
426
|
end
|
427
427
|
end
|
428
|
+
|
429
|
+
context 'when window.location is not present' do
|
430
|
+
context 'without specifying a default host' do
|
431
|
+
let(:_options) { { url_links: true } }
|
432
|
+
|
433
|
+
it 'generates path' do
|
434
|
+
expect(evaljs("Routes.inbox_url(1)")).to eq test_routes.inbox_path(1)
|
435
|
+
expect(evaljs("Routes.new_session_url()")).to eq test_routes.new_session_path
|
436
|
+
end
|
437
|
+
end
|
438
|
+
end
|
428
439
|
end
|
429
440
|
|
430
441
|
describe "when the compact mode is enabled" do
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
version: '0'
|
203
203
|
requirements: []
|
204
204
|
rubyforge_project:
|
205
|
-
rubygems_version: 2.6.
|
205
|
+
rubygems_version: 2.6.11
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: Brings Rails named routes to javascript
|