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 +4 -4
- data/.github/workflows/test.yml +2 -2
- data/CHANGELOG.md +12 -1
- data/README.md +1 -1
- data/lib/js_rails_routes/generator.rb +5 -1
- data/lib/js_rails_routes/language/javascript.rb +8 -2
- data/lib/js_rails_routes/language/typescript.rb +9 -3
- data/lib/js_rails_routes/version.rb +1 -1
- data/spec/js_rails_routes/language/javascript_spec.rb +8 -2
- data/spec/js_rails_routes/language/typescript_spec.rb +9 -3
- data/spec/js_rails_routes_spec.rb +4 -0
- metadata +7 -7
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,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.
|
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 (
|
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 =
|
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 (
|
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
|
-
for (var param in params) if (
|
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;
|
@@ -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 (
|
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
|
-
for (var param in params) if (
|
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;
|
@@ -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.
|
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:
|
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.
|
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: []
|