js_rails_routes 1.0.0 → 1.2.0

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: cd2383225d89dcc53076b7dd12b2600c09659dae5ddee39e7da9dd2f7d8d09dd
4
- data.tar.gz: a9162a939abd31bd7fe552255846caf6a4ffbcf1ba80737e058bfe868ca2b4c0
3
+ metadata.gz: e50948437613107c257fb18c1207d97578746364aec3cb07ca8a93b8bcab3102
4
+ data.tar.gz: 845917a81764d9f13531fb4a8498d4c8c71fee5b432c326b1fa31f5767c9d1ce
5
5
  SHA512:
6
- metadata.gz: 1c900ddad4563c435937edba1c072a299438a80290b6cd77b48f2a00493c37919a987606ed7c8a7784480dcbfd2a85c52f9ce50f59b5896914165ea6bd5d1255
7
- data.tar.gz: c27c9ce37e7d8de9031cdc13ff2c412c4ecc627f54183f67a478dd99d5dde4dde7e6c444320c7794a2e03156af22bb3c0a82b7293a359c37b33e50e4c9bd1e14
6
+ metadata.gz: d38cfab4a3d127c3423345a1c4c56b72d24b198909b4f294b0b83055ce73a7175a7ce66767eb22187beab6300a5909e554c9e1609cdcd8fcf9a2ec5f77c8d12e
7
+ data.tar.gz: 8fd42be0a4fbb917cef7719de28a9fc5013cbd4cd1022399194d42fa40cbae9e59236944af31b6b6d64dcdec064e51f9fe30f26e892a0214619498acde6e3ad9
@@ -15,7 +15,7 @@ jobs:
15
15
  strategy:
16
16
  fail-fast: false
17
17
  matrix:
18
- os: ['ubuntu-18.04', 'ubuntu-latest', 'macos-latest']
18
+ os: ['ubuntu-20.04', 'ubuntu-latest', 'macos-latest']
19
19
  ruby: [2.6, 2.7, 3.0, 3.1]
20
20
  experimental: [false]
21
21
  include:
@@ -27,7 +27,7 @@ jobs:
27
27
  steps:
28
28
  - name: Get branch names
29
29
  id: branch-name
30
- uses: tj-actions/branch-names@v4.9
30
+ uses: tj-actions/branch-names@v7.0.7
31
31
  - uses: actions/checkout@v2
32
32
  - uses: ruby/setup-ruby@v1
33
33
  with:
data/CHANGELOG.md CHANGED
@@ -6,6 +6,15 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.0] - 2024-04-19
10
+ ### Added
11
+ - Add support for parameters as Array
12
+
13
+ ## [1.1.0] - 2024-02-09
14
+ ### Changed
15
+ - Add eslint-disable comment not to affect eslint format
16
+ - Update generated scripts to adopt eslint rule
17
+
9
18
  ## [1.0.0] - 2022-05-13
10
19
 
11
20
  ### Changed
@@ -89,7 +98,9 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
89
98
  ### Added
90
99
  - Implement "js:rails:routes" task
91
100
 
92
- [Unreleased]: https://github.com/increments/js_rails_routes/compare/v1.0.0...HEAD
101
+ [Unreleased]: https://github.com/increments/js_rails_routes/compare/v1.2.0...HEAD
102
+ [1.2.0]: https://github.com/increments/js_rails_routes/compare/v1.1.0...v1.2.0
103
+ [1.1.0]: https://github.com/increments/js_rails_routes/compare/v1.0.0...v1.1.0
93
104
  [1.0.0]: https://github.com/increments/js_rails_routes/compare/v0.10.1...v1.0.0
94
105
  [0.10.1]: https://github.com/increments/js_rails_routes/compare/v0.10.0...v0.10.1
95
106
  [0.10.0]: https://github.com/increments/js_rails_routes/compare/v0.9.0...v0.10.0
data/README.md CHANGED
@@ -38,7 +38,7 @@ then `rake js:routes` generates "app/assets/javascripts/rails-routes.js" as:
38
38
  // Don't edit manually. `rake js:routes` generates this file.
39
39
  function process(route, params, keys) {
40
40
  var query = [];
41
- for (var param in params) if (params.hasOwnProperty(param)) {
41
+ for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
42
42
  if (keys.indexOf(param) === -1) {
43
43
  query.push(param + "=" + encodeURIComponent(params[param]));
44
44
  }
@@ -17,7 +17,11 @@ module JSRailsRoutes
17
17
  def generate(task)
18
18
  builder.build.each do |artifact|
19
19
  file_name = File.join(config.output_dir, artifact.file_name)
20
- file_body = "// Don't edit manually. `rake #{task}` generates this file.\n#{artifact.body}"
20
+ file_body = <<~FILE_BODY.chomp
21
+ /* eslint-disable */
22
+ // Don't edit manually. `rake #{task}` generates this file.
23
+ #{artifact.body}
24
+ FILE_BODY
21
25
  writable.write(file_name, file_body)
22
26
  end
23
27
  end
@@ -9,9 +9,15 @@ module JSRailsRoutes
9
9
  PROCESS_FUNC = <<~JAVASCRIPT
10
10
  function process(route, params, keys) {
11
11
  var query = [];
12
- for (var param in params) if (params.hasOwnProperty(param)) {
12
+ for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
13
13
  if (keys.indexOf(param) === -1) {
14
- query.push(param + "=" + encodeURIComponent(params[param]));
14
+ if (Array.isArray(params[param])) {
15
+ for (var value of params[param]) {
16
+ query.push(param + "[]=" + encodeURIComponent(value));
17
+ }
18
+ } else {
19
+ query.push(param + "=" + encodeURIComponent(params[param]));
20
+ }
15
21
  }
16
22
  }
17
23
  return query.length ? route + "?" + query.join("&") : route;
@@ -7,14 +7,20 @@ module JSRailsRoutes
7
7
  module Language
8
8
  class TypeScript < JavaScript
9
9
  PROCESS_FUNC = <<~TYPESCRIPT
10
- type Value = string | number
10
+ type Value = string | number | (string | number)[];
11
11
  type Params<Keys extends string> = { [key in Keys]: Value } & Record<string, Value>
12
12
  function process(route: string, params: Record<string, Value> | undefined, keys: string[]): string {
13
13
  if (!params) return route
14
14
  var query: string[] = [];
15
- for (var param in params) if (params.hasOwnProperty(param)) {
15
+ for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
16
16
  if (keys.indexOf(param) === -1) {
17
- query.push(param + "=" + encodeURIComponent(params[param].toString()));
17
+ if (Array.isArray(params[param])) {
18
+ for (var value of params[param] as (string | number)[]) {
19
+ query.push(param + "[]=" + encodeURIComponent(value.toString()));
20
+ }
21
+ } else {
22
+ query.push(param + "=" + encodeURIComponent(params[param].toString()));
23
+ }
18
24
  }
19
25
  }
20
26
  return query.length ? route + "?" + query.join("&") : route;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSRailsRoutes
4
- VERSION = '1.0.0'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -12,9 +12,15 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
12
12
  expect(subject).to eq <<~JAVASCRIPT
13
13
  function process(route, params, keys) {
14
14
  var query = [];
15
- for (var param in params) if (params.hasOwnProperty(param)) {
15
+ for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
16
16
  if (keys.indexOf(param) === -1) {
17
- query.push(param + "=" + encodeURIComponent(params[param]));
17
+ if (Array.isArray(params[param])) {
18
+ for (var value of params[param]) {
19
+ query.push(param + "[]=" + encodeURIComponent(value));
20
+ }
21
+ } else {
22
+ query.push(param + "=" + encodeURIComponent(params[param]));
23
+ }
18
24
  }
19
25
  }
20
26
  return query.length ? route + "?" + query.join("&") : route;
@@ -10,14 +10,20 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
10
10
 
11
11
  it 'returns a typescript function' do
12
12
  expect(subject).to eq <<~TYPESCRIPT
13
- type Value = string | number
13
+ type Value = string | number | (string | number)[];
14
14
  type Params<Keys extends string> = { [key in Keys]: Value } & Record<string, Value>
15
15
  function process(route: string, params: Record<string, Value> | undefined, keys: string[]): string {
16
16
  if (!params) return route
17
17
  var query: string[] = [];
18
- for (var param in params) if (params.hasOwnProperty(param)) {
18
+ for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
19
19
  if (keys.indexOf(param) === -1) {
20
- query.push(param + "=" + encodeURIComponent(params[param].toString()));
20
+ if (Array.isArray(params[param])) {
21
+ for (var value of params[param] as (string | number)[]) {
22
+ query.push(param + "[]=" + encodeURIComponent(value.toString()));
23
+ }
24
+ } else {
25
+ query.push(param + "=" + encodeURIComponent(params[param].toString()));
26
+ }
21
27
  }
22
28
  }
23
29
  return query.length ? route + "?" + query.join("&") : route;
@@ -42,6 +42,7 @@ RSpec.describe JSRailsRoutes do
42
42
  subject
43
43
 
44
44
  expect(File.read(app_root.join('app/assets/javascripts/rails-routes.js'))).to eq <<~JAVASCRIPT
45
+ /* eslint-disable */
45
46
  // Don't edit manually. `rake #{task}` generates this file.
46
47
  #{JSRailsRoutes::Language::JavaScript::PROCESS_FUNC}
47
48
  export function blogs_path(params) { return process('/blogs', params, []); }
@@ -55,6 +56,7 @@ RSpec.describe JSRailsRoutes do
55
56
  JAVASCRIPT
56
57
 
57
58
  expect(File.read(app_root.join('app/assets/javascripts/admin-routes.js'))).to eq <<~JAVASCRIPT
59
+ /* eslint-disable */
58
60
  // Don't edit manually. `rake #{task}` generates this file.
59
61
  #{JSRailsRoutes::Language::JavaScript::PROCESS_FUNC}
60
62
  export function notes_path(params) { return process('/notes', params, []); }
@@ -94,6 +96,7 @@ RSpec.describe JSRailsRoutes do
94
96
  subject
95
97
 
96
98
  expect(File.read(app_root.join('app/assets/javascripts/rails-routes.ts'))).to eq <<~TYPESCRIPT
99
+ /* eslint-disable */
97
100
  // Don't edit manually. `rake #{task}` generates this file.
98
101
  #{JSRailsRoutes::Language::TypeScript::PROCESS_FUNC}
99
102
  export function blogs_path(params?: Record<string, Value>) { return process('/blogs', params, []); }
@@ -107,6 +110,7 @@ RSpec.describe JSRailsRoutes do
107
110
  TYPESCRIPT
108
111
 
109
112
  expect(File.read(app_root.join('app/assets/javascripts/admin-routes.ts'))).to eq <<~TYPESCRIPT
113
+ /* eslint-disable */
110
114
  // Don't edit manually. `rake #{task}` generates this file.
111
115
  #{JSRailsRoutes::Language::TypeScript::PROCESS_FUNC}
112
116
  export function notes_path(params?: Record<string, Value>) { return process('/notes', params, []); }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_rails_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qiita Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-13 00:00:00.000000000 Z
11
+ date: 2024-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -170,7 +170,7 @@ dependencies:
170
170
  - - "!="
171
171
  - !ruby/object:Gem::Version
172
172
  version: 0.19.1
173
- description:
173
+ description:
174
174
  email:
175
175
  - engineers@qiita.com
176
176
  executables: []
@@ -219,7 +219,7 @@ licenses:
219
219
  - MIT
220
220
  metadata:
221
221
  rubygems_mfa_required: 'true'
222
- post_install_message:
222
+ post_install_message:
223
223
  rdoc_options: []
224
224
  require_paths:
225
225
  - lib
@@ -234,8 +234,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  - !ruby/object:Gem::Version
235
235
  version: '0'
236
236
  requirements: []
237
- rubygems_version: 3.0.3
238
- signing_key:
237
+ rubygems_version: 3.4.1
238
+ signing_key:
239
239
  specification_version: 4
240
240
  summary: Generate a ES6 module that contains Rails routes.
241
241
  test_files: []