js-routes 1.4.2 → 1.4.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/Rakefile +1 -0
- data/Readme.md +1 -1
- data/lib/js_routes.rb +1 -1
- data/lib/js_routes/version.rb +1 -1
- data/lib/routes.js +4 -3
- data/lib/routes.js.coffee +3 -1
- data/spec/js_routes/options_spec.rb +13 -15
- data/spec/spec_helper.rb +1 -1
- data/spec/support/routes.rb +10 -11
- 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: e2c1645c670a1b3417f9bac488213b59772d6e8a
|
4
|
+
data.tar.gz: c24fc47bafda9d30316f217cc056c40a06400b25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fae588fedc1ead98cd02f9bee3157d33044f788486137ae261195121bd020169f765fa82d14aced99db170a97c78b54c918f000a369c20f881b928acece283f5
|
7
|
+
data.tar.gz: e19c02689bb0c08eaa4ce6a47fb480020f2e00d1fb09daef4ff82593ef7a831fecda97999d817443b42bab8397f50985f239fc693822a0721032ec95621f2540
|
data/Rakefile
CHANGED
data/Readme.md
CHANGED
@@ -53,7 +53,7 @@ Available options:
|
|
53
53
|
|
54
54
|
* `default_url_options` - default parameters used when generating URLs
|
55
55
|
* Option is configurable at JS level with `Routes.configure()`
|
56
|
-
* Example: {:format => "json", :trailing\_slash => true, :protocol => "https", :host => "example.com", :port => 3000}
|
56
|
+
* Example: {:format => "json", :trailing\_slash => true, :protocol => "https", :subdomain => "api", :host => "example.com", :port => 3000}
|
57
57
|
* Default: {}
|
58
58
|
* `exclude` - Array of regexps to exclude from js routes.
|
59
59
|
* Default: []
|
data/lib/js_routes.rb
CHANGED
@@ -37,7 +37,7 @@ class JsRoutes
|
|
37
37
|
}
|
38
38
|
|
39
39
|
LAST_OPTIONS_KEY = "options".freeze
|
40
|
-
FILTERED_DEFAULT_PARTS = [:controller, :action
|
40
|
+
FILTERED_DEFAULT_PARTS = [:controller, :action]
|
41
41
|
URL_OPTIONS = [:protocol, :domain, :host, :port, :subdomain]
|
42
42
|
|
43
43
|
class Configuration < Struct.new(*DEFAULTS.keys)
|
data/lib/js_routes/version.rb
CHANGED
data/lib/routes.js
CHANGED
@@ -22,7 +22,7 @@ Based on Rails routes of APP_CLASS
|
|
22
22
|
|
23
23
|
DeprecatedBehavior = DEPRECATED_BEHAVIOR;
|
24
24
|
|
25
|
-
ReservedOptions = ['anchor', 'trailing_slash', 'host', 'port', 'protocol'];
|
25
|
+
ReservedOptions = ['anchor', 'trailing_slash', 'subdomain', 'host', 'port', 'protocol'];
|
26
26
|
|
27
27
|
Utils = {
|
28
28
|
configuration: {
|
@@ -352,7 +352,7 @@ Based on Rails routes of APP_CLASS
|
|
352
352
|
return path_fn;
|
353
353
|
},
|
354
354
|
route_url: function(route_defaults) {
|
355
|
-
var hostname, port, protocol;
|
355
|
+
var hostname, port, protocol, subdomain;
|
356
356
|
if (typeof route_defaults === 'string') {
|
357
357
|
return route_defaults;
|
358
358
|
}
|
@@ -360,10 +360,11 @@ Based on Rails routes of APP_CLASS
|
|
360
360
|
if (!hostname) {
|
361
361
|
return '';
|
362
362
|
}
|
363
|
+
subdomain = route_defaults.subdomain ? route_defaults.subdomain + '.' : '';
|
363
364
|
protocol = route_defaults.protocol || Utils.current_protocol();
|
364
365
|
port = route_defaults.port || (!route_defaults.host ? Utils.current_port() : void 0);
|
365
366
|
port = port ? ":" + port : '';
|
366
|
-
return protocol + "://" + hostname + port;
|
367
|
+
return protocol + "://" + subdomain + hostname + port;
|
367
368
|
},
|
368
369
|
has_location: function() {
|
369
370
|
return (typeof window !== "undefined" && window !== null ? window.location : void 0) != null;
|
data/lib/routes.js.coffee
CHANGED
@@ -15,6 +15,7 @@ DeprecatedBehavior = DEPRECATED_BEHAVIOR
|
|
15
15
|
ReservedOptions = [
|
16
16
|
'anchor'
|
17
17
|
'trailing_slash'
|
18
|
+
'subdomain'
|
18
19
|
'host'
|
19
20
|
'port'
|
20
21
|
'protocol'
|
@@ -281,11 +282,12 @@ Utils =
|
|
281
282
|
|
282
283
|
return '' unless hostname
|
283
284
|
|
285
|
+
subdomain = if route_defaults.subdomain then route_defaults.subdomain + '.' else ''
|
284
286
|
protocol = route_defaults.protocol || Utils.current_protocol()
|
285
287
|
port = route_defaults.port || (Utils.current_port() unless route_defaults.host)
|
286
288
|
port = if port then ":#{port}" else ''
|
287
289
|
|
288
|
-
protocol + "://" + hostname + port
|
290
|
+
protocol + "://" + subdomain + hostname + port
|
289
291
|
|
290
292
|
has_location: -> window?.location?
|
291
293
|
|
@@ -349,8 +349,8 @@ describe JsRoutes, "options" do
|
|
349
349
|
expect(evaljs("Routes.sso_url()")).to eq("http://sso.example.com:3000" + test_routes.sso_path)
|
350
350
|
end
|
351
351
|
|
352
|
-
it "does not override
|
353
|
-
expect(evaljs("Routes.
|
352
|
+
it "does not override parts when specified in route" do
|
353
|
+
expect(evaljs("Routes.secret_root_url()")).to eq(test_routes.secret_root_url)
|
354
354
|
end
|
355
355
|
end
|
356
356
|
|
@@ -358,9 +358,6 @@ describe JsRoutes, "options" do
|
|
358
358
|
let(:_options) { { :camel_case => true, :url_links => true, :default_url_options => {:host => "example.com"} } }
|
359
359
|
it "should generate path and url links" do
|
360
360
|
expect(evaljs("Routes.inboxUrl(1)")).to eq("http://example.com#{test_routes.inbox_path(1)}")
|
361
|
-
expect(evaljs("Routes.newSessionUrl()")).to eq("https://example.com#{test_routes.new_session_path}")
|
362
|
-
expect(evaljs("Routes.ssoUrl()")).to eq(test_routes.sso_url)
|
363
|
-
expect(evaljs("Routes.portalsUrl()")).to eq("http://example.com:8080#{test_routes.portals_path}")
|
364
361
|
end
|
365
362
|
end
|
366
363
|
|
@@ -368,9 +365,6 @@ describe JsRoutes, "options" do
|
|
368
365
|
let(:_options) { { :prefix => "/api", :url_links => true, :default_url_options => {:host => 'example.com'} } }
|
369
366
|
it "should generate path and url links" do
|
370
367
|
expect(evaljs("Routes.inbox_url(1)")).to eq("http://example.com/api#{test_routes.inbox_path(1)}")
|
371
|
-
expect(evaljs("Routes.new_session_url()")).to eq("https://example.com/api#{test_routes.new_session_path}")
|
372
|
-
expect(evaljs("Routes.sso_url()")).to eq("http://sso.example.com/api#{test_routes.sso_path}")
|
373
|
-
expect(evaljs("Routes.portals_url()")).to eq("http://example.com:8080/api#{test_routes.portals_path}")
|
374
368
|
end
|
375
369
|
end
|
376
370
|
|
@@ -378,9 +372,6 @@ describe JsRoutes, "options" do
|
|
378
372
|
let(:_options) { { :compact => true, :url_links => true, :default_url_options => {:host => 'example.com'} } }
|
379
373
|
it "does not affect url helpers" do
|
380
374
|
expect(evaljs("Routes.inbox_url(1)")).to eq("http://example.com#{test_routes.inbox_path(1)}")
|
381
|
-
expect(evaljs("Routes.new_session_url()")).to eq("https://example.com#{test_routes.new_session_path}")
|
382
|
-
expect(evaljs("Routes.sso_url()")).to eq(test_routes.sso_url)
|
383
|
-
expect(evaljs("Routes.portals_url()")).to eq("http://example.com:8080#{test_routes.portals_path}")
|
384
375
|
end
|
385
376
|
end
|
386
377
|
end
|
@@ -408,20 +399,27 @@ describe JsRoutes, "options" do
|
|
408
399
|
expect(evaljs("Routes.inbox_url(1)")).to eq("http://current.example.com#{test_routes.inbox_path(1)}")
|
409
400
|
expect(evaljs("Routes.inbox_url(1, { test_key: \"test_val\" })")).to eq("http://current.example.com#{test_routes.inbox_path(1, :test_key => "test_val")}")
|
410
401
|
expect(evaljs("Routes.new_session_url()")).to eq("https://current.example.com#{test_routes.new_session_path}")
|
411
|
-
expect(evaljs("Routes.sso_url()")).to eq("http://sso.example.com#{test_routes.sso_path}")
|
412
402
|
|
413
403
|
end
|
414
404
|
|
405
|
+
it "doesn't use current when specified in the route" do
|
406
|
+
expect(evaljs("Routes.sso_url()")).to eq(test_routes.sso_url)
|
407
|
+
end
|
408
|
+
|
415
409
|
it "uses host option as an argument" do
|
416
|
-
expect(evaljs("Routes.
|
410
|
+
expect(evaljs("Routes.secret_root_url({host: 'another.com'})")).to eq(test_routes.secret_root_url(host: 'another.com'))
|
417
411
|
end
|
418
412
|
|
419
413
|
it "uses port option as an argument" do
|
420
|
-
expect(evaljs("Routes.
|
414
|
+
expect(evaljs("Routes.secret_root_url({host: 'localhost', port: 8080})")).to eq(test_routes.secret_root_url(host: 'localhost', port: 8080))
|
421
415
|
end
|
422
416
|
|
423
417
|
it "uses protocol option as an argument" do
|
424
|
-
expect(evaljs("Routes.
|
418
|
+
expect(evaljs("Routes.secret_root_url({host: 'localhost', protocol: 'https'})")).to eq(test_routes.secret_root_url(protocol: 'https', host: 'localhost'))
|
419
|
+
end
|
420
|
+
|
421
|
+
it "uses subdomain option as an argument" do
|
422
|
+
expect(evaljs("Routes.secret_root_url({subdomain: 'custom'})")).to eq(test_routes.secret_root_url(subdomain: 'custom'))
|
425
423
|
end
|
426
424
|
end
|
427
425
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/routes.rb
CHANGED
@@ -8,25 +8,24 @@ def draw_routes
|
|
8
8
|
|
9
9
|
get 'support(/page/:page)', to: BlogEngine::Engine, as: 'support'
|
10
10
|
|
11
|
-
resources :inboxes do
|
12
|
-
resources :messages do
|
13
|
-
resources :attachments
|
11
|
+
resources :inboxes, only: [:index, :show] do
|
12
|
+
resources :messages, only: [:index, :show] do
|
13
|
+
resources :attachments, only: [:new, :show]
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
root :to => "inboxes#index"
|
18
18
|
|
19
19
|
namespace :admin do
|
20
|
-
resources :users
|
20
|
+
resources :users, only: [:index]
|
21
21
|
end
|
22
22
|
|
23
23
|
scope "/returns/:return" do
|
24
|
-
resources :objects
|
24
|
+
resources :objects, only: [:show]
|
25
25
|
end
|
26
|
-
resources :returns
|
27
26
|
|
28
27
|
scope "(/optional/:optional_id)" do
|
29
|
-
resources :things
|
28
|
+
resources :things, only: [:show, :index]
|
30
29
|
end
|
31
30
|
|
32
31
|
get "(/sep1/:first_optional)/sep2/:second_required/sep3/:third_required(/:forth_optional)",
|
@@ -51,11 +50,11 @@ def draw_routes
|
|
51
50
|
get '/привет' => "foo#foo", :as => :hello
|
52
51
|
get '(/o/:organization)/search/:q' => "foo#foo", as: :search
|
53
52
|
|
54
|
-
resources :sessions, :only => [:new, :create
|
55
|
-
|
53
|
+
resources :sessions, :only => [:new, :create], :protocol => 'https'
|
56
54
|
get '/' => 'sso#login', host: 'sso.example.com', as: :sso
|
55
|
+
get "/" => "a#b", subdomain: 'www', host: 'example.com', port: 88, as: :secret_root
|
57
56
|
|
58
|
-
resources :portals, :port => 8080
|
57
|
+
resources :portals, :port => 8080, only: [:index]
|
59
58
|
|
60
59
|
get '/with_defaults' => 'foo#foo', defaults: { bar: 'tested', format: :json }, format: :true
|
61
60
|
|
@@ -63,7 +62,7 @@ def draw_routes
|
|
63
62
|
get "/purchases" => "purchases#index"
|
64
63
|
end
|
65
64
|
|
66
|
-
resources :budgies do
|
65
|
+
resources :budgies, only: [:show, :index] do
|
67
66
|
get "descendents"
|
68
67
|
end
|
69
68
|
|
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.3
|
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-12-18 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.14
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: Brings Rails named routes to javascript
|