js_rails_routes 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +7 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +9 -1
- data/Gemfile +0 -2
- data/README.md +21 -14
- data/js_rails_routes.gemspec +3 -1
- data/lib/js_rails_routes/generator.rb +10 -6
- data/lib/js_rails_routes/version.rb +1 -1
- data/lib/tasks/js_rails_routes.rake +4 -2
- data/spec/js_rails_routes/generator_spec.rb +50 -10
- data/spec/spec_helper.rb +7 -8
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca0f6f4f31f67057a1ae5f4d839b98564d323dfa
|
4
|
+
data.tar.gz: 9966df2ec91cc5f7ec03dd6ca082a01a3c73f4d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08885b9714f50b48795aab6d79f5ce0e8e32de2ce1c245865a158c14011be5b38024a4d99f7024574b0c431f11907aee16fb5cfc73c34499cc9c845a939ed322
|
7
|
+
data.tar.gz: 2143f80a2c1090ce16b4493ccb196a62d0c889930ff1ec5e6fe2ad6fb149b2491e7d4a716f3843f3b5e93285d2cf779a48843f56dc75fbbaeb7441722c48bc6b
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,14 @@ 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
|
-
## [0.
|
7
|
+
## [0.4.0] - 2017-04-05
|
8
|
+
### Added
|
9
|
+
- Add `include_names` and `exclude_names` option
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
- Rename `includes` and `excludes` as `include_paths` and `exclude_paths` respectively
|
13
|
+
|
14
|
+
## [0.3.0] - 2016-06-25
|
8
15
|
### Added
|
9
16
|
- Enable to configure through Ruby interface
|
10
17
|
|
@@ -24,6 +31,7 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
|
|
24
31
|
### Added
|
25
32
|
- Implement "js:rails:routes" task
|
26
33
|
|
34
|
+
[0.4.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.3.0...v0.4.0
|
27
35
|
[0.3.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.2.1...v0.3.0
|
28
36
|
[0.2.1]: https://github.com/yuku-t/js_rails_routes/compare/v0.2.0...v0.2.1
|
29
37
|
[0.2.0]: https://github.com/yuku-t/js_rails_routes/compare/v0.1.0...v0.2.0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
# rake js:routes
|
2
2
|
|
3
|
-
[![Gem](https://img.shields.io/gem/v/js_rails_routes.svg?maxAge=2592000)](https://rubygems.org/gems/js_rails_routes)
|
3
|
+
[![Gem](https://img.shields.io/gem/v/js_rails_routes.svg?maxAge=2592000)](https://rubygems.org/gems/js_rails_routes)
|
4
|
+
[![Build Status](https://travis-ci.org/yuku-t/js_rails_routes.svg?branch=master)](https://travis-ci.org/yuku-t/js_rails_routes)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/yuku-t/js_rails_routes/badges/gpa.svg)](https://codeclimate.com/github/yuku-t/js_rails_routes)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/yuku-t/js_rails_routes/badges/coverage.svg)](https://codeclimate.com/github/yuku-t/js_rails_routes/coverage)
|
7
|
+
[![license](https://img.shields.io/github/license/yuku-t/js_rails_routes.svg?maxAge=2592000)](https://github.com/yuku-t/js_rails_routes/blob/master/LICENSE)
|
8
|
+
[![Analytics](https://ga-beacon.appspot.com/UA-4932407-14/js_rails_routes/readme)](https://github.com/igrigorik/ga-beacon)
|
4
9
|
|
5
10
|
Generate a ES6 module that contains Rails routes.
|
6
11
|
|
7
12
|
## Description
|
8
13
|
|
9
14
|
This gem provides "js:routes" rake task.
|
10
|
-
It generates a ES6 requirable module
|
15
|
+
It generates a ES6 requirable module which exports url helper functions defined in your Rails application.
|
11
16
|
|
12
|
-
Suppose
|
17
|
+
Suppose the app has following routes:
|
13
18
|
|
14
19
|
```rb
|
15
20
|
# == Route Map
|
@@ -28,7 +33,7 @@ Rails.application.routes.draw do
|
|
28
33
|
end
|
29
34
|
```
|
30
35
|
|
31
|
-
|
36
|
+
then `rake js:routes` generates "app/assets/javascripts/rails-routes.js" as:
|
32
37
|
|
33
38
|
```js
|
34
39
|
// Don't edit manually. `rake js:routes` generates this file.
|
@@ -60,19 +65,21 @@ rake js:routes
|
|
60
65
|
|
61
66
|
JSRailsRoutes supports several parameters:
|
62
67
|
|
63
|
-
Name
|
64
|
-
|
65
|
-
`
|
66
|
-
`
|
67
|
-
`
|
68
|
+
Name | Type | Description | Default
|
69
|
+
----------------|----------|-----------------------------------------|----------------------------------------
|
70
|
+
`include_paths` | `Regexp` | paths match to the regexp are included | `/.*/`
|
71
|
+
`exclude_paths` | `Regexp` | paths match to the regexp are excluded | `/^$/`
|
72
|
+
`include_names` | `Regexp` | names match to the regexp are included | `/.*/`
|
73
|
+
`exclude_names` | `Regexp` | names match to the regexp are excluded | `/^$/`
|
74
|
+
`path` | `String` | JS file path | `Rails.root.join("app", "assets", "javascripts", "rails-routes.js")`
|
68
75
|
|
69
76
|
You can configure via `JSRailsRoutes.configure`.
|
70
77
|
|
71
78
|
```rb
|
72
79
|
# Rakefile
|
73
|
-
JSRailsRoutes.configure |c|
|
74
|
-
c.
|
75
|
-
c.path = 'path
|
80
|
+
JSRailsRoutes.configure do |c|
|
81
|
+
c.exclude_paths = %r{^/(rails|sidekiq)}
|
82
|
+
c.path = Rails.root.join('path', 'to', 'rails-routes.js')
|
76
83
|
end
|
77
84
|
```
|
78
85
|
|
@@ -83,7 +90,7 @@ Now `rake js:routes` ignores paths starting with "/rails" or "/sidekiq".
|
|
83
90
|
You can override the coniguration via command line parameters:
|
84
91
|
|
85
92
|
```bash
|
86
|
-
rake js:routes
|
93
|
+
rake js:routes exclude_paths='^/rails'
|
87
94
|
```
|
88
95
|
|
89
96
|
The command still ignores "/rails" but includes "/sidekiq".
|
@@ -98,7 +105,7 @@ gem 'js_rails_routes', group: :development
|
|
98
105
|
|
99
106
|
## License
|
100
107
|
|
101
|
-
[MIT](https://github.com/yuku-t/js_rails_routes/blob/master/
|
108
|
+
[MIT](https://github.com/yuku-t/js_rails_routes/blob/master/LICENSE)
|
102
109
|
|
103
110
|
## Author
|
104
111
|
|
data/js_rails_routes.gemspec
CHANGED
@@ -14,7 +14,9 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.require_paths = ['lib']
|
15
15
|
spec.add_dependency 'rails', '>= 3.2'
|
16
16
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
17
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
|
17
18
|
spec.add_development_dependency 'rake', '~> 10.0'
|
18
19
|
spec.add_development_dependency 'rspec', '~> 3.4.0'
|
19
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
20
|
+
spec.add_development_dependency 'rubocop', '~> 0.48.1'
|
21
|
+
spec.add_development_dependency 'simplecov', '~> 0.14'
|
20
22
|
end
|
@@ -6,11 +6,13 @@ module JSRailsRoutes
|
|
6
6
|
|
7
7
|
include Singleton
|
8
8
|
|
9
|
-
attr_accessor :
|
9
|
+
attr_accessor :include_paths, :exclude_paths, :include_names, :exclude_names, :path
|
10
10
|
|
11
11
|
def initialize
|
12
|
-
self.
|
13
|
-
self.
|
12
|
+
self.include_paths = /.*/
|
13
|
+
self.exclude_paths = /^$/
|
14
|
+
self.include_names = /.*/
|
15
|
+
self.exclude_names = /^$/
|
14
16
|
self.path = Rails.root.join('app', 'assets', 'javascripts', 'rails-routes.js')
|
15
17
|
Rails.application.reload_routes!
|
16
18
|
end
|
@@ -26,9 +28,11 @@ module JSRailsRoutes
|
|
26
28
|
|
27
29
|
private
|
28
30
|
|
29
|
-
def match?(
|
30
|
-
return false if
|
31
|
-
return false if
|
31
|
+
def match?(route_name, route_path)
|
32
|
+
return false if include_paths !~ route_path
|
33
|
+
return false if exclude_paths =~ route_path
|
34
|
+
return false if include_names !~ route_name
|
35
|
+
return false if exclude_names =~ route_name
|
32
36
|
true
|
33
37
|
end
|
34
38
|
|
@@ -2,8 +2,10 @@ desc 'Generate a ES6 module that contains Rails routes'
|
|
2
2
|
namespace :js do
|
3
3
|
task routes: :environment do |task|
|
4
4
|
generator = JSRailsRoutes::Generator.instance
|
5
|
-
generator.
|
6
|
-
generator.
|
5
|
+
generator.include_paths = Regexp.new(ENV['include_paths']) if ENV['include_paths']
|
6
|
+
generator.exclude_paths = Regexp.new(ENV['exclude_paths']) if ENV['exclude_paths']
|
7
|
+
generator.include_names = Regexp.new(ENV['include_names']) if ENV['include_names']
|
8
|
+
generator.exclude_names = Regexp.new(ENV['exclude_names']) if ENV['exclude_names']
|
7
9
|
generator.path = ENV['path'] if ENV['path']
|
8
10
|
generator.generate(task)
|
9
11
|
puts "Routes saved to #{generator.path}."
|
@@ -19,32 +19,32 @@ RSpec.describe JSRailsRoutes::Generator do
|
|
19
19
|
subject
|
20
20
|
end
|
21
21
|
|
22
|
-
context 'when
|
22
|
+
context 'when include_paths is given' do
|
23
23
|
before do
|
24
|
-
generator.
|
24
|
+
generator.include_paths = include_paths
|
25
25
|
end
|
26
26
|
|
27
|
-
let(:
|
28
|
-
|
27
|
+
let(:include_paths) do
|
28
|
+
%r{/new}
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'writes paths matching with the parameter' do
|
32
32
|
expect(generator).to receive(:write).with(a_kind_of(String)) do |arg|
|
33
33
|
paths = arg.split("\n")[1..-1]
|
34
34
|
expect(paths).not_to be_empty
|
35
|
-
expect(paths).to all(
|
35
|
+
expect(paths).to all(match(include_paths))
|
36
36
|
end
|
37
37
|
subject
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
context 'when
|
41
|
+
context 'when exclude_paths is given' do
|
42
42
|
before do
|
43
|
-
generator.
|
43
|
+
generator.exclude_paths = exclude_paths
|
44
44
|
end
|
45
45
|
|
46
|
-
let(:
|
47
|
-
|
46
|
+
let(:exclude_paths) do
|
47
|
+
%r{/new}
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'writes paths not matching with the parameter' do
|
@@ -52,7 +52,47 @@ RSpec.describe JSRailsRoutes::Generator do
|
|
52
52
|
paths = arg.split("\n")[1..-1]
|
53
53
|
expect(paths).not_to be_empty
|
54
54
|
paths.each do |path|
|
55
|
-
expect(path).to_not
|
55
|
+
expect(path).to_not match(exclude_paths)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
subject
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when include_names is given' do
|
63
|
+
before do
|
64
|
+
generator.include_names = include_names
|
65
|
+
end
|
66
|
+
|
67
|
+
let(:include_names) do
|
68
|
+
/user/
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'writes paths matching with the parameter' do
|
72
|
+
expect(generator).to receive(:write).with(a_kind_of(String)) do |arg|
|
73
|
+
paths = arg.split("\n")[1..-1]
|
74
|
+
expect(paths).not_to be_empty
|
75
|
+
expect(paths).to all(match(include_names))
|
76
|
+
end
|
77
|
+
subject
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when exclude_names is given' do
|
82
|
+
before do
|
83
|
+
generator.exclude_names = exclude_names
|
84
|
+
end
|
85
|
+
|
86
|
+
let(:exclude_names) do
|
87
|
+
/user/
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'writes paths not matching with the parameter' do
|
91
|
+
expect(generator).to receive(:write).with(a_kind_of(String)) do |arg|
|
92
|
+
paths = arg.split("\n")[1..-1]
|
93
|
+
expect(paths).not_to be_empty
|
94
|
+
paths.each do |path|
|
95
|
+
expect(path).to_not match(exclude_names)
|
56
96
|
end
|
57
97
|
end
|
58
98
|
subject
|
data/spec/spec_helper.rb
CHANGED
@@ -1,22 +1,21 @@
|
|
1
1
|
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
5
|
|
6
6
|
require 'rails/all'
|
7
7
|
require 'js_rails_routes'
|
8
8
|
|
9
9
|
class TestApp < Rails::Application
|
10
10
|
config.root = File.expand_path('../test_app', __FILE__)
|
11
|
-
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
resources :apps
|
17
|
-
end
|
12
|
+
routes.draw do
|
13
|
+
resources :blogs
|
14
|
+
resources :users
|
18
15
|
end
|
16
|
+
end
|
19
17
|
|
18
|
+
RSpec.configure do |config|
|
20
19
|
config.expect_with :rspec do |expectations|
|
21
20
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
22
21
|
end
|
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.4.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:
|
11
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codeclimate-test-reporter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +86,28 @@ dependencies:
|
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
89
|
+
version: 0.48.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.48.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.14'
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
110
|
+
version: '0.14'
|
83
111
|
description:
|
84
112
|
email:
|
85
113
|
- taka84u9@gmail.com
|