js_rails_routes 1.1.0 → 1.2.0
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/.github/workflows/test.yml +2 -2
- data/CHANGELOG.md +7 -1
- data/lib/js_rails_routes/language/javascript.rb +7 -1
- data/lib/js_rails_routes/language/typescript.rb +8 -2
- data/lib/js_rails_routes/version.rb +1 -1
- data/spec/js_rails_routes/language/javascript_spec.rb +7 -1
- data/spec/js_rails_routes/language/typescript_spec.rb +8 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e50948437613107c257fb18c1207d97578746364aec3cb07ca8a93b8bcab3102
|
4
|
+
data.tar.gz: 845917a81764d9f13531fb4a8498d4c8c71fee5b432c326b1fa31f5767c9d1ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d38cfab4a3d127c3423345a1c4c56b72d24b198909b4f294b0b83055ce73a7175a7ce66767eb22187beab6300a5909e554c9e1609cdcd8fcf9a2ec5f77c8d12e
|
7
|
+
data.tar.gz: 8fd42be0a4fbb917cef7719de28a9fc5013cbd4cd1022399194d42fa40cbae9e59236944af31b6b6d64dcdec064e51f9fe30f26e892a0214619498acde6e3ad9
|
data/.github/workflows/test.yml
CHANGED
@@ -15,7 +15,7 @@ jobs:
|
|
15
15
|
strategy:
|
16
16
|
fail-fast: false
|
17
17
|
matrix:
|
18
|
-
os: ['ubuntu-
|
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@
|
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,10 @@ 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
|
+
|
9
13
|
## [1.1.0] - 2024-02-09
|
10
14
|
### Changed
|
11
15
|
- Add eslint-disable comment not to affect eslint format
|
@@ -94,7 +98,9 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
|
|
94
98
|
### Added
|
95
99
|
- Implement "js:rails:routes" task
|
96
100
|
|
97
|
-
[Unreleased]: https://github.com/increments/js_rails_routes/compare/v1.
|
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
|
98
104
|
[1.0.0]: https://github.com/increments/js_rails_routes/compare/v0.10.1...v1.0.0
|
99
105
|
[0.10.1]: https://github.com/increments/js_rails_routes/compare/v0.10.0...v0.10.1
|
100
106
|
[0.10.0]: https://github.com/increments/js_rails_routes/compare/v0.9.0...v0.10.0
|
@@ -11,7 +11,13 @@ module JSRailsRoutes
|
|
11
11
|
var query = [];
|
12
12
|
for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
|
13
13
|
if (keys.indexOf(param) === -1) {
|
14
|
-
|
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
15
|
for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
|
16
16
|
if (keys.indexOf(param) === -1) {
|
17
|
-
|
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;
|
@@ -14,7 +14,13 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
|
|
14
14
|
var query = [];
|
15
15
|
for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
|
16
16
|
if (keys.indexOf(param) === -1) {
|
17
|
-
|
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
18
|
for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
|
19
19
|
if (keys.indexOf(param) === -1) {
|
20
|
-
|
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;
|
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.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Qiita Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|