js-routes 1.3.1 → 1.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea60a5a1b545228955e4b886562999449511cd91
4
- data.tar.gz: 72c3ef411752b3ae5f674a82df98ee09879f8ab9
3
+ metadata.gz: f8070be8c5b23bf6559f75032ac0512e19ab5cd1
4
+ data.tar.gz: 2264e1657fcc5601ecd1eaa57fa71a2854b8e6e3
5
5
  SHA512:
6
- metadata.gz: 7a8a4432e8eaf2dd39aaa4276adbba282b1d982f72646dd5693bfa1627f03c753d1c1b920489f7c42f5ff431957f3509fbefe3626e877a1779586ba611514e3b
7
- data.tar.gz: a31e1fb5b3e7b66f1ed4f1f2712dc3f9e583db041bd60813090de72a909eb881bc2df425ae435c9bebb232208b674f0f86000ac099b670e6281b106f0338d2e2
6
+ metadata.gz: 59dab9d9c8c9bbadf9f5611ecc59b573db0443c7cff3691c17d52806da3586ecb1d0716b8d71ddd912d4f3e195b4f000d19338cc3a994ce0675e65fb7b781e0b
7
+ data.tar.gz: 67059a57046c2430ee4b4ae1a8aa6657e0172db5fca0214067fb8130016b09424d51a291dc9c38990050515d8102d1f3713a76e7f558dc1e9502bc9b4abbacea
data/Readme.md CHANGED
@@ -56,7 +56,7 @@ Available options:
56
56
  * Default: `Routes`
57
57
  * `prefix` - String representing a url path to prepend to all paths.
58
58
  * Example: `http://yourdomain.com`. This will cause route helpers to generate full path only.
59
- * Default: Rails.application.config.relative_url_root
59
+ * Default: `Rails.application.config.relative_url_root`
60
60
  * `camel_case` (version >= 0.8.8) - Generate camel case route names.
61
61
  * Default: false
62
62
  * `url_links` (version >= 0.8.9) - Generate `*_url` helpers (in addition to the default `*_path` helpers).
@@ -72,8 +72,11 @@ Available options:
72
72
  * Example: `MyApp.custom_serialize` - use completely custom serializer of your application.
73
73
 
74
74
  * `special_options_key` - a special key that helps js-routes to destinguish serialized model from options hash
75
- * This options is required because JS doesn't provide a difference between an object and a hash
75
+ * This option is required because JS doesn't provide a difference between an object and a hash
76
76
  * Default: `_options`
77
+ * `application` - a key to specify which rails engine you want to generate routes too.
78
+ * This option allows to only generate routes for a specific rails engine, that is mounted into routes instead of all Rails app routes
79
+ * Default: `Rails.application`
77
80
 
78
81
  ### Very Advanced Setup
79
82
 
@@ -184,6 +187,7 @@ Sometimes the destinction between JS Hash and Object can not be found by js-rout
184
187
  In this case you would need to pass a special key to help:
185
188
 
186
189
  ``` js
190
+ Routes.company_project_path({company_id: 1, id: 2}) // => Not Enough parameters
187
191
  Routes.company_project_path({company_id: 1, id: 2, _options: true}) // => "/companies/1/projects/2"
188
192
  ```
189
193
 
data/lib/js_routes.rb CHANGED
@@ -61,11 +61,6 @@ class JsRoutes
61
61
  end
62
62
 
63
63
  def generate(opts = {})
64
- # Ensure routes are loaded. If they're not, load them.
65
- if Rails.application.routes.named_routes.to_a.empty?
66
- Rails.application.reload_routes!
67
- end
68
-
69
64
  new(opts).generate
70
65
  end
71
66
 
@@ -101,9 +96,14 @@ class JsRoutes
101
96
  end
102
97
 
103
98
  def generate
99
+ # Ensure routes are loaded. If they're not, load them.
100
+ if named_routes.to_a.empty? && application.respond_to?(:reload_routes!)
101
+ application.reload_routes!
102
+ end
103
+
104
104
  {
105
105
  "GEM_VERSION" => JsRoutes::VERSION,
106
- "APP_CLASS" => Rails.application.class.to_s,
106
+ "APP_CLASS" => application.class.to_s,
107
107
  "NAMESPACE" => @options[:namespace],
108
108
  "DEFAULT_URL_OPTIONS" => json(@options[:default_url_options].merge(deprecate_url_options)),
109
109
  "PREFIX" => @options[:prefix] || Rails.application.config.relative_url_root || "",
@@ -152,8 +152,16 @@ class JsRoutes
152
152
 
153
153
  protected
154
154
 
155
+ def application
156
+ @options[:application] || Rails.application
157
+ end
158
+
159
+ def named_routes
160
+ application.routes.named_routes.to_a
161
+ end
162
+
155
163
  def js_routes
156
- js_routes = Rails.application.routes.named_routes.to_a.sort_by(&:first).flat_map do |_, route|
164
+ js_routes = named_routes.sort_by(&:first).flat_map do |_, route|
157
165
  [build_route_if_match(route)] + mounted_app_routes(route)
158
166
  end.compact
159
167
  "{\n" + js_routes.join(",\n") + "}\n"
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
@@ -486,4 +486,12 @@ describe JsRoutes, "options" do
486
486
  expect(evaljs("Routes.inbox_message_path({inbox_id: 1, id: 2, __options__: true})")).to eq(routes.inbox_message_path(inbox_id: 1, id: 2))
487
487
  end
488
488
  end
489
+
490
+ describe "when application is specified" do
491
+ let(:_options) { {:application => BlogEngine::Engine} }
492
+
493
+ it "should include specified engine route" do
494
+ expect(evaljs("Routes.posts_path()")).not_to be_nil
495
+ end
496
+ end
489
497
  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.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-28 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties