js-routes 2.2.3 → 2.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b706c51040d12aaa69182dad9d25304ba947fe1e80cc5171775864a27d6f4ed8
4
- data.tar.gz: 1a105e8a4dbc9cfde5a787a0714b6e0bf0758b6291f6945f0a16ca9c1e7a47a9
3
+ metadata.gz: 66ff94f5c78d966f76e2a9f47d1c838c757c3e243c37f03599b24c286b15b9b7
4
+ data.tar.gz: c5803e4a35b99923769970149f07a6893a84c6343f10f76c8a89645974dce959
5
5
  SHA512:
6
- metadata.gz: f053d1f48cb8a4f9f7ac7f1e68d37f4816d09e42e0a91660fb84c1e9f4ad36d439019f6f402f1e2fce30467e6b0d5b799fd08bbe70bfc2aa8423c63f053f0bdb
7
- data.tar.gz: bdcf72700542350da423e9cf62b4abcc0ba326400c4077c70c5f6174edb75a7e61b6b6a765a0454b4cd1a2fc5ddbf91f3a16294ce995d9ab31d9984153c29b4c
6
+ metadata.gz: a34c75f950a02a6634687889e4072f7d88f37520a6dc2ba5bfd2ccbbb71962159a70170bf7ac55b22db45de2727f7c573dfce8c80debc33f34abbd9cb1132c1f
7
+ data.tar.gz: 779b340c9dac721c8b427a16011ed961a05dde4d15594838649fb0860bac42e60344a682718a0b94f35f785350126ca59c7f739dac43cb47e0a7b84e45fa468a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## master
2
2
 
3
+ ## v2.2.5
4
+
5
+ * Fix middleware generator [#300](https://github.com/railsware/js-routes/issues/300)
6
+ * Support `params` special parameter
7
+
3
8
  ## v2.2.4
4
9
 
5
10
  * Fix rails engine loading if sprockets is not in Gemfile. Fixes [#294](https://github.com/railsware/js-routes/issues/294)
data/Readme.md CHANGED
@@ -62,7 +62,7 @@ import * as Routes from '../routes';
62
62
  alert(Routes.post_path(1))
63
63
  ```
64
64
 
65
- Upgrade `rake assets:precompile` to update js-routes files:
65
+ Upgrade `rake assets:precompile` to update js-routes files in `Rakefile`:
66
66
 
67
67
  ``` ruby
68
68
  namespace :assets do
@@ -52,7 +52,7 @@ end
52
52
  {},
53
53
  {module_type: 'DTS'}
54
54
  ].map do |config|
55
- File.join('/', JsRoutes.new(config).configuration.output_file) + "\n"
55
+ File.join('/', JsRoutes::Configuration.new(config).output_file) + "\n"
56
56
  end.join
57
57
  end
58
58
  end
@@ -2,7 +2,7 @@ require "js_routes/configuration"
2
2
  require "js_routes/route"
3
3
 
4
4
  module JsRoutes
5
- class Instance
5
+ class Instance # :nodoc:
6
6
 
7
7
  attr_reader :configuration
8
8
  #
@@ -21,12 +21,16 @@ module JsRoutes
21
21
  def update_js_routes
22
22
  new_mtime = routes_mtime
23
23
  unless new_mtime == @mtime
24
- JsRoutes.generate!
25
- JsRoutes.definitions!
24
+ regenerate
26
25
  @mtime = new_mtime
27
26
  end
28
27
  end
29
28
 
29
+ def regenerate
30
+ JsRoutes.generate!
31
+ JsRoutes.definitions!
32
+ end
33
+
30
34
  def routes_mtime
31
35
  File.mtime(@routes_file)
32
36
  rescue Errno::ENOENT
@@ -1,3 +1,3 @@
1
1
  module JsRoutes
2
- VERSION = "2.2.3"
2
+ VERSION = "2.2.4"
3
3
  end
data/lib/routes.d.ts CHANGED
@@ -53,6 +53,7 @@ declare type KeywordUrlOptions = Optional<{
53
53
  port: string | number;
54
54
  anchor: string;
55
55
  trailing_slash: boolean;
56
+ params: RouteParameters;
56
57
  }>;
57
58
  declare type RouteOptions = KeywordUrlOptions & RouteParameters;
58
59
  declare type PartsTable = Record<string, {
data/lib/routes.js CHANGED
@@ -222,12 +222,23 @@ RubyVariables.WRAPPER(() => {
222
222
  ...options,
223
223
  };
224
224
  const keyword_parameters = {};
225
- const query_parameters = {};
225
+ let query_parameters = {};
226
226
  for (const key in options) {
227
227
  if (!hasProp(options, key))
228
228
  continue;
229
229
  const value = options[key];
230
- if (this.is_reserved_option(key)) {
230
+ if (key === "params") {
231
+ if (this.is_object(value)) {
232
+ query_parameters = {
233
+ ...query_parameters,
234
+ ...value,
235
+ };
236
+ }
237
+ else {
238
+ throw new Error("params value should always be an object");
239
+ }
240
+ }
241
+ else if (this.is_reserved_option(key)) {
231
242
  keyword_parameters[key] = value;
232
243
  }
233
244
  else {
data/lib/routes.ts CHANGED
@@ -70,6 +70,7 @@ type KeywordUrlOptions = Optional<{
70
70
  port: string | number;
71
71
  anchor: string;
72
72
  trailing_slash: boolean;
73
+ params: RouteParameters;
73
74
  }>;
74
75
 
75
76
  type RouteOptions = KeywordUrlOptions & RouteParameters;
@@ -365,11 +366,20 @@ RubyVariables.WRAPPER(
365
366
  };
366
367
 
367
368
  const keyword_parameters: KeywordUrlOptions = {};
368
- const query_parameters: RouteParameters = {};
369
+ let query_parameters: RouteParameters = {};
369
370
  for (const key in options) {
370
371
  if (!hasProp(options, key)) continue;
371
372
  const value = options[key];
372
- if (this.is_reserved_option(key)) {
373
+ if (key === "params") {
374
+ if (this.is_object(value)) {
375
+ query_parameters = {
376
+ ...query_parameters,
377
+ ...(value as RouteParameters),
378
+ };
379
+ } else {
380
+ throw new Error("params value should always be an object");
381
+ }
382
+ } else if (this.is_reserved_option(key)) {
373
383
  keyword_parameters[key] = value as any;
374
384
  } else {
375
385
  if (
@@ -7,25 +7,25 @@ describe JsRoutes, "#serialize" do
7
7
  end
8
8
 
9
9
  it "should provide this method" do
10
- expect(evaljs("Routes.serialize({a: 1, b: [2,3], c: {d: 4, e: 5}, f: ''})")).to eq(
10
+ expectjs("Routes.serialize({a: 1, b: [2,3], c: {d: 4, e: 5}, f: ''})").to eq(
11
11
  "a=1&b%5B%5D=2&b%5B%5D=3&c%5Bd%5D=4&c%5Be%5D=5&f="
12
12
  )
13
13
  end
14
14
 
15
15
  it "should provide this method" do
16
- expect(evaljs("Routes.serialize({a: 1, b: [2,3], c: {d: 4, e: 5}, f: ''})")).to eq(
16
+ expectjs("Routes.serialize({a: 1, b: [2,3], c: {d: 4, e: 5}, f: ''})").to eq(
17
17
  "a=1&b%5B%5D=2&b%5B%5D=3&c%5Bd%5D=4&c%5Be%5D=5&f="
18
18
  )
19
19
  end
20
20
 
21
21
  it "works with JS suckiness" do
22
- expect(evaljs(
22
+ expectjs(
23
23
  [
24
24
  "const query = Object.create(null);",
25
25
  "query.a = 1;",
26
26
  "query.b = 2;",
27
27
  "Routes.serialize(query);",
28
28
  ].join("\n")
29
- )).to eq("a=1&b=2")
29
+ ).to eq("a=1&b=2")
30
30
  end
31
31
  end
@@ -29,7 +29,7 @@ EOF
29
29
  end
30
30
 
31
31
  it "should working from require" do
32
- expect(evaljs("require(['js-routes'], function(r){ return r.inboxes_path(); })")).to eq(test_routes.inboxes_path())
32
+ expectjs("require(['js-routes'], function(r){ return r.inboxes_path(); })").to eq(test_routes.inboxes_path())
33
33
  end
34
34
 
35
35
  end
@@ -10,6 +10,6 @@ describe JsRoutes, "compatibility with CJS" do
10
10
  end
11
11
 
12
12
  it "should define module exports" do
13
- expect(evaljs("module.exports.inboxes_path()")).to eq(test_routes.inboxes_path())
13
+ expectjs("module.exports.inboxes_path()").to eq(test_routes.inboxes_path())
14
14
  end
15
15
  end
@@ -53,6 +53,7 @@ declare type KeywordUrlOptions = Optional<{
53
53
  port: string | number;
54
54
  anchor: string;
55
55
  trailing_slash: boolean;
56
+ params: RouteParameters;
56
57
  }>;
57
58
  declare type RouteOptions = KeywordUrlOptions & RouteParameters;
58
59
  declare type PartsTable = Record<string, {
@@ -13,7 +13,7 @@ describe JsRoutes, "compatibility with ESM" do
13
13
  end
14
14
 
15
15
  it "defines route helpers" do
16
- expect(evaljs("inboxes_path()")).to eq(test_routes.inboxes_path())
16
+ expectjs("inboxes_path()").to eq(test_routes.inboxes_path())
17
17
  end
18
18
 
19
19
  it "exports route helpers" do
@@ -33,7 +33,7 @@ DOC
33
33
  end
34
34
 
35
35
  it "defines utility methods" do
36
- expect(evaljs("serialize({a: 1, b: 2})")).to eq({a: 1, b: 2}.to_param)
36
+ expectjs("serialize({a: 1, b: 2})").to eq({a: 1, b: 2}.to_param)
37
37
  end
38
38
 
39
39
  describe "compiled javascript asset" do
@@ -36,7 +36,7 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
36
36
  end
37
37
 
38
38
  it "should be possible" do
39
- expect(evaljs("r.inboxes_path()")).to eq(test_routes.inboxes_path())
39
+ expectjs("r.inboxes_path()").to eq(test_routes.inboxes_path())
40
40
  end
41
41
  end
42
42
 
@@ -50,8 +50,8 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
50
50
  evaljs(generated_js)
51
51
  end
52
52
  it "should use this namespace for routing" do
53
- expect(evaljs("window.Routes")).to be_nil
54
- expect(evaljs("window.PHM.inboxes_path")).not_to be_nil
53
+ expectjs("window.Routes").to be_nil
54
+ expectjs("window.PHM.inboxes_path").not_to be_nil
55
55
  end
56
56
 
57
57
  describe "is nested" do
@@ -60,7 +60,7 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
60
60
  let(:_options) { {namespace: "PHM.Routes"} }
61
61
 
62
62
  it "should use this namespace for routing" do
63
- expect(evaljs("PHM.Routes.inboxes_path")).not_to be_nil
63
+ expectjs("PHM.Routes.inboxes_path").not_to be_nil
64
64
  end
65
65
  end
66
66
 
@@ -68,7 +68,7 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
68
68
  let(:_options) { {namespace: "PHM.Routes"} }
69
69
 
70
70
  it "should initialize namespace" do
71
- expect(evaljs("window.PHM.Routes.inboxes_path")).not_to be_nil
71
+ expectjs("window.PHM.Routes.inboxes_path").not_to be_nil
72
72
  end
73
73
  end
74
74
 
@@ -77,8 +77,8 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
77
77
  let(:_options) { {namespace: "PHM.Routes"} }
78
78
 
79
79
  it "should not overwrite existing parts" do
80
- expect(evaljs("window.PHM.Utils")).not_to be_nil
81
- expect(evaljs("window.PHM.Routes.inboxes_path")).not_to be_nil
80
+ expectjs("window.PHM.Utils").not_to be_nil
81
+ expectjs("window.PHM.Routes.inboxes_path").not_to be_nil
82
82
  end
83
83
  end
84
84
  end