js_rails_routes 0.6.0 → 0.7.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/.rubocop.yml +3 -0
- data/.travis.yml +10 -4
- data/CHANGELOG.md +19 -0
- data/Gemfile +2 -0
- data/README.md +9 -8
- data/Rakefile +2 -0
- data/js_rails_routes.gemspec +4 -0
- data/lib/js_rails_routes/engine.rb +2 -0
- data/lib/js_rails_routes/generator.rb +18 -2
- data/lib/js_rails_routes/version.rb +3 -1
- data/lib/js_rails_routes.rb +2 -0
- data/lib/tasks/js_rails_routes.rake +3 -0
- data/spec/js_rails_routes/generator_spec.rb +47 -0
- data/spec/js_rails_routes_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a386d5fc5aec380f0c1747daa37cf0f8da385881
|
4
|
+
data.tar.gz: 22e8b29009a14466642bd32795c8aeab3d0a9b0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '087716b33ddff3babd4d84cbf6c70ab39bbc5d2c766bb2ae4af803ac74fcbacb2e22e0fdc035811bce993f1f281193250184d6ec7f0e37b55b302ab2cfc8713e'
|
7
|
+
data.tar.gz: a75bd8bd4df03ff80cf8d5dc39c6275923b539d8805933f3f1ffa0c3111470d474db3408c3f022e72f9475f2d6d99dfcc6744aa2d888939ba15d5736b5bf8835
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
2
3
|
rvm:
|
3
|
-
- 2.3.
|
4
|
+
- 2.3.7
|
5
|
+
- 2.4.4
|
6
|
+
- 2.5.1
|
7
|
+
|
4
8
|
notifications:
|
5
9
|
email: false
|
10
|
+
|
6
11
|
script:
|
7
|
-
- bundle exec rake rubocop
|
8
|
-
- bundle exec rake spec
|
12
|
+
- bundle exec rake rubocop
|
13
|
+
- bundle exec rake spec
|
14
|
+
|
9
15
|
after_success:
|
10
|
-
- bundle exec codeclimate-test-reporter
|
16
|
+
- bundle exec codeclimate-test-reporter
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
|
5
5
|
This change log adheres to [keepachangelog.com](http://keepachangelog.com).
|
6
6
|
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.7.0] - 2018-07-11
|
10
|
+
### Added
|
11
|
+
- Support `camelize` option
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- Drop supporting legacy Ruby versions
|
15
|
+
|
16
|
+
## [0.6.0] - 2018-07-04
|
17
|
+
### Added
|
18
|
+
- Support Rails engine
|
19
|
+
|
20
|
+
### Changed
|
21
|
+
- Replace `path` with `output_dir`
|
22
|
+
|
7
23
|
## [0.5.0] - 2017-04-08
|
8
24
|
### Added
|
9
25
|
- Support additional parameters
|
@@ -35,6 +51,9 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
|
|
35
51
|
### Added
|
36
52
|
- Implement "js:rails:routes" task
|
37
53
|
|
54
|
+
[Unreleased]: https://github.com/yuku-t/js_rails_routes/compare/v0.7.0...HEAD
|
55
|
+
[0.7.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.6.0...v0.7.0
|
56
|
+
[0.6.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.5.0...v0.6.0
|
38
57
|
[0.5.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.4.0...v0.5.0
|
39
58
|
[0.4.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.3.0...v0.4.0
|
40
59
|
[0.3.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.2.1...v0.3.0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -75,14 +75,15 @@ rake js:routes
|
|
75
75
|
|
76
76
|
JSRailsRoutes supports several parameters:
|
77
77
|
|
78
|
-
Name | Type
|
79
|
-
|
80
|
-
`include_paths` | `Regexp`
|
81
|
-
`exclude_paths` | `Regexp`
|
82
|
-
`include_names` | `Regexp`
|
83
|
-
`exclude_names` | `Regexp`
|
84
|
-
`exclude_engines` | `Regexp`
|
85
|
-
`output_dir` | `String`
|
78
|
+
Name | Type | Description | Default
|
79
|
+
------------------|-----------|---------------------------------------------------------------------------------------|----------------------------------------
|
80
|
+
`include_paths` | `Regexp` | Paths match to the regexp are included | `/.*/`
|
81
|
+
`exclude_paths` | `Regexp` | Paths match to the regexp are excluded | `/^$/`
|
82
|
+
`include_names` | `Regexp` | Names match to the regexp are included | `/.*/`
|
83
|
+
`exclude_names` | `Regexp` | Names match to the regexp are excluded | `/^$/`
|
84
|
+
`exclude_engines` | `Regexp` | Rails engines match to the regexp are excluded | `/^$/`
|
85
|
+
`output_dir` | `String` | Output JS file into the specified directory | `Rails.root.join("app", "assets", "javascripts")`
|
86
|
+
`camelize` | `Symbol` | Output JS file with chosen camelcase type it also avaliable for `:lower` and `:upper` | `nil`
|
86
87
|
|
87
88
|
You can configure via `JSRailsRoutes.configure`.
|
88
89
|
|
data/Rakefile
CHANGED
data/js_rails_routes.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
$LOAD_PATH << File.expand_path('lib', __dir__)
|
2
4
|
|
3
5
|
require 'js_rails_routes/version'
|
@@ -12,6 +14,8 @@ Gem::Specification.new do |spec|
|
|
12
14
|
spec.license = 'MIT'
|
13
15
|
spec.files = `git ls-files -z`.split("\x0")
|
14
16
|
spec.require_paths = ['lib']
|
17
|
+
spec.required_ruby_version = '>= 2.3.0'
|
18
|
+
|
15
19
|
spec.add_dependency 'rails', '>= 3.2'
|
16
20
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
17
21
|
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'singleton'
|
2
4
|
|
3
5
|
module JSRailsRoutes
|
@@ -18,7 +20,13 @@ module JSRailsRoutes
|
|
18
20
|
|
19
21
|
include Singleton
|
20
22
|
|
21
|
-
attr_accessor :include_paths,
|
23
|
+
attr_accessor :include_paths,
|
24
|
+
:exclude_paths,
|
25
|
+
:include_names,
|
26
|
+
:exclude_names,
|
27
|
+
:exclude_engines,
|
28
|
+
:output_dir,
|
29
|
+
:camelize
|
22
30
|
|
23
31
|
def initialize
|
24
32
|
self.include_paths = /.*/
|
@@ -26,6 +34,7 @@ module JSRailsRoutes
|
|
26
34
|
self.include_names = /.*/
|
27
35
|
self.exclude_names = /^$/
|
28
36
|
self.exclude_engines = /^$/
|
37
|
+
self.camelize = nil
|
29
38
|
|
30
39
|
self.output_dir = Rails.root.join('app', 'assets', 'javascripts')
|
31
40
|
Rails.application.reload_routes!
|
@@ -59,13 +68,20 @@ module JSRailsRoutes
|
|
59
68
|
keys.push("'#{Regexp.last_match(1)}'")
|
60
69
|
route_path.sub!(COMPARE_REGEXP, "' + params.#{Regexp.last_match(1)} + '#{Regexp.last_match(2)}")
|
61
70
|
end
|
62
|
-
|
71
|
+
|
72
|
+
function_name = make_function_name(route_name)
|
73
|
+
"export function #{function_name}(params) { return process('#{route_path}', params, [#{keys.join(',')}]); }"
|
63
74
|
end
|
64
75
|
|
65
76
|
def routes_with_engines
|
66
77
|
@routes_with_engines ||= [default_routes] + subengine_routes
|
67
78
|
end
|
68
79
|
|
80
|
+
def make_function_name(route_name)
|
81
|
+
url_helper_name = route_name + '_path'
|
82
|
+
camelize.nil? ? url_helper_name : url_helper_name.camelize(camelize)
|
83
|
+
end
|
84
|
+
|
69
85
|
def make_routes(routes)
|
70
86
|
routes
|
71
87
|
.select(&:name)
|
data/lib/js_rails_routes.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
desc 'Generate a ES6 module that contains Rails routes'
|
2
4
|
namespace :js do
|
3
5
|
task routes: :environment do |task|
|
@@ -7,6 +9,7 @@ namespace :js do
|
|
7
9
|
generator.include_names = Regexp.new(ENV['include_names']) if ENV['include_names']
|
8
10
|
generator.exclude_names = Regexp.new(ENV['exclude_names']) if ENV['exclude_names']
|
9
11
|
generator.output_dir = ENV['output_dir'] if ENV['output_dir']
|
12
|
+
generator.camelize = ENV['camelize']&.to_sym if ENV['camelize']
|
10
13
|
generator.generate(task)
|
11
14
|
puts "Routes saved into #{generator.output_dir}."
|
12
15
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe JSRailsRoutes::Generator do
|
2
4
|
let(:generator) do
|
3
5
|
described_class.clone.instance
|
@@ -148,5 +150,50 @@ RSpec.describe JSRailsRoutes::Generator do
|
|
148
150
|
subject
|
149
151
|
end
|
150
152
|
end
|
153
|
+
|
154
|
+
shared_examples_for 'writes paths that matches expected routes' do
|
155
|
+
it do
|
156
|
+
expect(generator).to receive(:write)
|
157
|
+
.with(be_in(['Rails', 'Admin::Engine']), a_kind_of(String))
|
158
|
+
.twice do |_, arg|
|
159
|
+
paths = arg.split("\n")[(2 + described_class::PROCESS_FUNC.split("\n").size)..-1]
|
160
|
+
expect(paths).not_to be_empty
|
161
|
+
expect(paths).to include(match(expected_routes))
|
162
|
+
end
|
163
|
+
subject
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context 'when camelize is nil' do
|
168
|
+
let(:expected_routes) do
|
169
|
+
/blog_path|note_path/
|
170
|
+
end
|
171
|
+
|
172
|
+
it_behaves_like 'writes paths that matches expected routes'
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'when camelize is :lower' do
|
176
|
+
before do
|
177
|
+
generator.camelize = :lower
|
178
|
+
end
|
179
|
+
|
180
|
+
let(:expected_routes) do
|
181
|
+
/blogPath|notePath/
|
182
|
+
end
|
183
|
+
|
184
|
+
it_behaves_like 'writes paths that matches expected routes'
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'when camelize is :upper' do
|
188
|
+
before do
|
189
|
+
generator.camelize = :upper
|
190
|
+
end
|
191
|
+
|
192
|
+
let(:expected_routes) do
|
193
|
+
/BlogPath|NotePath/
|
194
|
+
end
|
195
|
+
|
196
|
+
it_behaves_like 'writes paths that matches expected routes'
|
197
|
+
end
|
151
198
|
end
|
152
199
|
end
|
data/spec/spec_helper.rb
CHANGED
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.7.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-07-
|
11
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
147
|
requirements:
|
148
148
|
- - ">="
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
150
|
+
version: 2.3.0
|
151
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
153
|
- - ">="
|