js_rails_routes 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +15 -0
- data/js_rails_routes.gemspec +3 -3
- data/lib/js_rails_routes/route.rb +3 -2
- data/lib/js_rails_routes/version.rb +1 -1
- data/lib/js_rails_routes.rb +2 -1
- data/spec/js_rails_routes/builder_spec.rb +1 -1
- data/spec/js_rails_routes/language/javascript_spec.rb +8 -8
- data/spec/js_rails_routes/language/typescript_spec.rb +8 -8
- data/spec/js_rails_routes/route_set_spec.rb +3 -3
- data/spec/js_rails_routes/route_spec.rb +8 -0
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb3bb6c9a267324041904e5ba8e8418a61e8d64fac6273caaabb1f5c4c9699f4
|
4
|
+
data.tar.gz: d3e2cf66c91f3b3d063127b5d38969d2533fad8b27eb1c7586b1689403936534
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dbfa99a9a37cac5d3f0e6412f29828bff8b0464c52d0e88e4ca7b6c4161e2f785a67b7831bdaecb9eb6c12894e80c6f3a3eae31f5246dede0088e7b2a86537d
|
7
|
+
data.tar.gz: c07b6a657b44e15d84a792fbd5095cc947cd52501d2f862bb5e818ab20a61b12e91ee44be134169dae1826138dbbb1d68e6d820ea6e15adadf0e9999307089d5
|
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
|
+
## [0.10.0] - 2018-10-29
|
10
|
+
### Added
|
11
|
+
- Enable to change route's name
|
12
|
+
|
9
13
|
## [0.9.0] - 2018-08-24
|
10
14
|
### Added
|
11
15
|
- Improved TypeScript params typing support
|
@@ -70,7 +74,8 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
|
|
70
74
|
### Added
|
71
75
|
- Implement "js:rails:routes" task
|
72
76
|
|
73
|
-
[Unreleased]: https://github.com/yuku-t/js_rails_routes/compare/v0.
|
77
|
+
[Unreleased]: https://github.com/yuku-t/js_rails_routes/compare/v0.10.0...HEAD
|
78
|
+
[0.10.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.9.0...v0.10.0
|
74
79
|
[0.9.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.8.1...v0.9.0
|
75
80
|
[0.8.1]: https://github.com/yuku-t/js_rails_routes/compare/v0.8.0...v0.8.1
|
76
81
|
[0.8.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.7.1...v0.8.0
|
data/README.md
CHANGED
@@ -110,6 +110,21 @@ rake js:routes exclude_paths='^/rails'
|
|
110
110
|
|
111
111
|
The command still ignores "/rails" but includes "/sidekiq".
|
112
112
|
|
113
|
+
### Rename route
|
114
|
+
|
115
|
+
You can rename route in `route_filter`:
|
116
|
+
|
117
|
+
```rb
|
118
|
+
# Rakefile
|
119
|
+
JSRailsRoutes.configure do |c|
|
120
|
+
c.route_filter = -> (route) do
|
121
|
+
# Remove common prefix if route's name starts with it.
|
122
|
+
route.name = route.name[4..-1] if route.name.start_with?('foo_')
|
123
|
+
true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
113
128
|
## Install
|
114
129
|
|
115
130
|
Your Rails Gemfile:
|
data/js_rails_routes.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
21
21
|
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
|
22
22
|
spec.add_development_dependency 'rake', '~> 12.3'
|
23
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
24
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
25
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 1.
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
24
|
+
spec.add_development_dependency 'rubocop', '~> 0.60.0'
|
25
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.30.0'
|
26
26
|
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
27
27
|
end
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module JSRailsRoutes
|
4
4
|
# Encapsulate a single routing rule
|
5
5
|
class Route
|
6
|
-
# @return [String]
|
7
|
-
|
6
|
+
# @return [String] route name. It becomes JavaScript function name.
|
7
|
+
attr_accessor :name
|
8
8
|
|
9
9
|
# @return [String]
|
10
10
|
attr_reader :path
|
@@ -25,6 +25,7 @@ module JSRailsRoutes
|
|
25
25
|
return false if config.exclude_paths =~ path
|
26
26
|
return false if config.include_names !~ name
|
27
27
|
return false if config.exclude_names =~ name
|
28
|
+
|
28
29
|
config.route_filter.call(self)
|
29
30
|
end
|
30
31
|
|
data/lib/js_rails_routes.rb
CHANGED
@@ -8,7 +8,7 @@ require 'js_rails_routes/language/javascript'
|
|
8
8
|
require 'js_rails_routes/language/typescript'
|
9
9
|
|
10
10
|
module JSRailsRoutes
|
11
|
-
PARAM_REGEXP = %r{:(.*?)(/|$)}
|
11
|
+
PARAM_REGEXP = %r{:(.*?)(/|$)}.freeze
|
12
12
|
|
13
13
|
module_function
|
14
14
|
|
@@ -35,6 +35,7 @@ module JSRailsRoutes
|
|
35
35
|
# @yield
|
36
36
|
def sandbox
|
37
37
|
raise 'Already in a sandbox' if @sandbox
|
38
|
+
|
38
39
|
@sandbox = true
|
39
40
|
prev = @config
|
40
41
|
@config = Configuration.new
|
@@ -31,7 +31,7 @@ RSpec.describe JSRailsRoutes::Builder do
|
|
31
31
|
subject { builder.build }
|
32
32
|
|
33
33
|
it 'returns an array of artifacts' do
|
34
|
-
|
34
|
+
expect(subject).to contain_exactly(
|
35
35
|
an_object_having_attributes(engine_name: rails_route_set.name, body: body),
|
36
36
|
an_object_having_attributes(engine_name: engine_route_set.name, body: body)
|
37
37
|
)
|
@@ -9,7 +9,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
|
|
9
9
|
subject { described_class::PROCESS_FUNC }
|
10
10
|
|
11
11
|
it 'returns a javascript function' do
|
12
|
-
|
12
|
+
expect(subject).to eq <<~JAVASCRIPT
|
13
13
|
function process(route, params, keys) {
|
14
14
|
var query = [];
|
15
15
|
for (var param in params) if (params.hasOwnProperty(param)) {
|
@@ -37,7 +37,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
|
|
37
37
|
|
38
38
|
context 'without camelize option' do
|
39
39
|
it 'returns a javascript with snake_case functions' do
|
40
|
-
|
40
|
+
expect(subject).to eq <<~JAVASCRIPT
|
41
41
|
#{described_class::PROCESS_FUNC}
|
42
42
|
export function articles_path(params) { return process('/articles', params, []); }
|
43
43
|
export function new_article_path(params) { return process('/articles/new', params, []); }
|
@@ -55,7 +55,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'returns a javascript with lowerCamelCase functions' do
|
58
|
-
|
58
|
+
expect(subject).to eq <<~JAVASCRIPT
|
59
59
|
#{described_class::PROCESS_FUNC}
|
60
60
|
export function articlesPath(params) { return process('/articles', params, []); }
|
61
61
|
export function newArticlePath(params) { return process('/articles/new', params, []); }
|
@@ -73,7 +73,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'returns a javascript with UpperCamelCase functions' do
|
76
|
-
|
76
|
+
expect(subject).to eq <<~JAVASCRIPT
|
77
77
|
#{described_class::PROCESS_FUNC}
|
78
78
|
export function ArticlesPath(params) { return process('/articles', params, []); }
|
79
79
|
export function NewArticlePath(params) { return process('/articles/new', params, []); }
|
@@ -91,7 +91,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
|
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'returns a javascript matching to the regexp' do
|
94
|
-
|
94
|
+
expect(subject).to eq <<~JAVASCRIPT
|
95
95
|
#{described_class::PROCESS_FUNC}
|
96
96
|
export function new_article_path(params) { return process('/articles/new', params, []); }
|
97
97
|
JAVASCRIPT
|
@@ -106,7 +106,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
|
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'returns a javascript not matching to the regexp' do
|
109
|
-
|
109
|
+
expect(subject).to eq <<~JAVASCRIPT
|
110
110
|
#{described_class::PROCESS_FUNC}
|
111
111
|
export function articles_path(params) { return process('/articles', params, []); }
|
112
112
|
export function edit_article_path(params) { return process('/articles/' + params.id + '/edit', params, ['id']); }
|
@@ -123,7 +123,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
|
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'returns a javascript matching to the regexp' do
|
126
|
-
|
126
|
+
expect(subject).to eq <<~JAVASCRIPT
|
127
127
|
#{described_class::PROCESS_FUNC}
|
128
128
|
export function new_article_path(params) { return process('/articles/new', params, []); }
|
129
129
|
JAVASCRIPT
|
@@ -138,7 +138,7 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
it 'returns a javascript not matching to the regexp' do
|
141
|
-
|
141
|
+
expect(subject).to eq <<~JAVASCRIPT
|
142
142
|
#{described_class::PROCESS_FUNC}
|
143
143
|
export function articles_path(params) { return process('/articles', params, []); }
|
144
144
|
export function edit_article_path(params) { return process('/articles/' + params.id + '/edit', params, ['id']); }
|
@@ -9,7 +9,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
|
|
9
9
|
subject { described_class::PROCESS_FUNC }
|
10
10
|
|
11
11
|
it 'returns a typescript function' do
|
12
|
-
|
12
|
+
expect(subject).to eq <<~TYPESCRIPT
|
13
13
|
type Value = 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 {
|
@@ -40,7 +40,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
|
|
40
40
|
|
41
41
|
context 'without camelize option' do
|
42
42
|
it 'returns a typescript with snake_case functions' do
|
43
|
-
|
43
|
+
expect(subject).to eq <<~TYPESCRIPT
|
44
44
|
#{described_class::PROCESS_FUNC}
|
45
45
|
export function articles_path(params?: Record<string, Value>) { return process('/articles', params, []); }
|
46
46
|
export function new_article_path(params?: Record<string, Value>) { return process('/articles/new', params, []); }
|
@@ -58,7 +58,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'returns a javascript with lowerCamelCase functions' do
|
61
|
-
|
61
|
+
expect(subject).to eq <<~TYPESCRIPT
|
62
62
|
#{described_class::PROCESS_FUNC}
|
63
63
|
export function articlesPath(params?: Record<string, Value>) { return process('/articles', params, []); }
|
64
64
|
export function newArticlePath(params?: Record<string, Value>) { return process('/articles/new', params, []); }
|
@@ -76,7 +76,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'returns a javascript with UpperCamelCase functions' do
|
79
|
-
|
79
|
+
expect(subject).to eq <<~TYPESCRIPT
|
80
80
|
#{described_class::PROCESS_FUNC}
|
81
81
|
export function ArticlesPath(params?: Record<string, Value>) { return process('/articles', params, []); }
|
82
82
|
export function NewArticlePath(params?: Record<string, Value>) { return process('/articles/new', params, []); }
|
@@ -94,7 +94,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'returns a javascript matching to the regexp' do
|
97
|
-
|
97
|
+
expect(subject).to eq <<~TYPESCRIPT
|
98
98
|
#{described_class::PROCESS_FUNC}
|
99
99
|
export function new_article_path(params?: Record<string, Value>) { return process('/articles/new', params, []); }
|
100
100
|
TYPESCRIPT
|
@@ -109,7 +109,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'returns a javascript not matching to the regexp' do
|
112
|
-
|
112
|
+
expect(subject).to eq <<~TYPESCRIPT
|
113
113
|
#{described_class::PROCESS_FUNC}
|
114
114
|
export function articles_path(params?: Record<string, Value>) { return process('/articles', params, []); }
|
115
115
|
export function edit_article_path(params: Params<'id'>) { return process('/articles/' + params.id + '/edit', params, ['id']); }
|
@@ -126,7 +126,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'returns a javascript matching to the regexp' do
|
129
|
-
|
129
|
+
expect(subject).to eq <<~TYPESCRIPT
|
130
130
|
#{described_class::PROCESS_FUNC}
|
131
131
|
export function new_article_path(params?: Record<string, Value>) { return process('/articles/new', params, []); }
|
132
132
|
TYPESCRIPT
|
@@ -141,7 +141,7 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
|
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'returns a javascript not matching to the regexp' do
|
144
|
-
|
144
|
+
expect(subject).to eq <<~TYPESCRIPT
|
145
145
|
#{described_class::PROCESS_FUNC}
|
146
146
|
export function articles_path(params?: Record<string, Value>) { return process('/articles', params, []); }
|
147
147
|
export function edit_article_path(params: Params<'id'>) { return process('/articles/' + params.id + '/edit', params, ['id']); }
|
@@ -20,7 +20,7 @@ RSpec.describe JSRailsRoutes::RouteSet do
|
|
20
20
|
|
21
21
|
it 'returns an array of matching route sets' do
|
22
22
|
# See spec/support/test_app.rb
|
23
|
-
|
23
|
+
expect(subject).to match [
|
24
24
|
be_a(described_class).and(have_attributes(name: 'Rails')).and(be_match),
|
25
25
|
be_a(described_class).and(have_attributes(name: 'Admin::Engine')).and(be_match)
|
26
26
|
]
|
@@ -46,8 +46,8 @@ RSpec.describe JSRailsRoutes::RouteSet do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "doesn't include the excluded route" do
|
49
|
-
|
50
|
-
|
49
|
+
expect(subject).to include be_a(JSRailsRoutes::Route).and(have_attributes(name: /articles/))
|
50
|
+
expect(subject).not_to include be_a(JSRailsRoutes::Route).and(have_attributes(name: /users/))
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -19,6 +19,14 @@ RSpec.describe JSRailsRoutes::Route do
|
|
19
19
|
it { is_expected.to eq 'articles' }
|
20
20
|
end
|
21
21
|
|
22
|
+
describe '#name=' do
|
23
|
+
subject { route.name = value }
|
24
|
+
|
25
|
+
let(:value) { 'foo' }
|
26
|
+
|
27
|
+
it { expect { subject }.to change(route, :name).to(value) }
|
28
|
+
end
|
29
|
+
|
22
30
|
describe '#path' do
|
23
31
|
subject { route.path }
|
24
32
|
|
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: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuku Takahashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -72,42 +72,42 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
75
|
+
version: '3.8'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
82
|
+
version: '3.8'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.60.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.60.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rubocop-rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 1.30.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 1.30.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|