js-routes 1.0.0 → 1.0.1
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/.gitignore +5 -1
- data/.travis.yml +3 -0
- data/Appraisals +9 -9
- data/CHANGELOG.md +2 -0
- data/gemfiles/rails40.gemfile +1 -0
- data/gemfiles/rails40_sprockets3.gemfile +8 -0
- data/gemfiles/rails41.gemfile +1 -0
- data/gemfiles/rails41_sprockets3.gemfile +8 -0
- data/gemfiles/rails42.gemfile +1 -0
- data/gemfiles/rails42_sprockets3.gemfile +8 -0
- data/lib/js_routes.rb +3 -1
- data/lib/js_routes/engine.rb +7 -1
- data/lib/js_routes/version.rb +1 -1
- data/spec/dummy/app/assets/javascripts/.gitkeep +0 -0
- data/spec/{config → dummy/config}/routes.rb +0 -0
- data/spec/js_routes/generated_javascript_spec.rb +5 -1
- data/spec/js_routes/zzz_last_post_rails_init_spec.rb +45 -21
- data/spec/spec_helper.rb +2 -0
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c68aed8760da61aa1ff4977b8d69f09cfc609f18
|
4
|
+
data.tar.gz: f4362dcdb29332048b5a19d3ed40dce4717b6bd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd44c50605191eda0663671b1d7bf46bcffa7e4e13705e8ca9177fc3c8ac332ea1abac89448a7dfc27e4e9eee5d98ad340f602fea6b082c0af144449e5e46c31
|
7
|
+
data.tar.gz: bc598e7e2a6c51477162b6e76d4d423e4e6bd6454247305593d343934abd04ae20a829301695e7707ed86bc38c8da7ce00a3c224f3b9e3e5e3b3e35e8ce2320c
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
@@ -3,14 +3,14 @@ appraise "rails32" do
|
|
3
3
|
gem 'tzinfo'
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
gem "railties", "~> 4.1.1"
|
12
|
-
end
|
6
|
+
{rails40: '4.0.5', rails41: '4.1.1', rails42: '4.2.0'}.each do |rails, version|
|
7
|
+
appraise "#{rails}" do
|
8
|
+
gem "railties", "~> #{version}"
|
9
|
+
gem "sprockets", "< 3"
|
10
|
+
end
|
13
11
|
|
14
|
-
appraise "
|
15
|
-
|
12
|
+
appraise "#{rails}-sprockets3" do
|
13
|
+
gem "railties", "~> #{version}"
|
14
|
+
gem "sprockets", "~> 3.0"
|
15
|
+
end
|
16
16
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
## master
|
2
2
|
|
3
|
+
## v1.0.0
|
4
|
+
|
3
5
|
* Add the compact mode [#125](https://github.com/railsware/js-routes/pull/125)
|
4
6
|
* Add support for host, protocol, and port configuration [#137](https://github.com/railsware/js-routes/pull/137)
|
5
7
|
* Routes path specs [#135](https://github.com/railsware/js-routes/pull/135)
|
data/gemfiles/rails40.gemfile
CHANGED
data/gemfiles/rails41.gemfile
CHANGED
data/gemfiles/rails42.gemfile
CHANGED
data/lib/js_routes.rb
CHANGED
@@ -156,8 +156,10 @@ class JsRoutes
|
|
156
156
|
end
|
157
157
|
|
158
158
|
def any_match?(route, parent_route, matchers)
|
159
|
+
full_route = [parent_route.try(:name), route.name].compact.join('_')
|
160
|
+
|
159
161
|
matchers = Array(matchers)
|
160
|
-
matchers.any? {|regex|
|
162
|
+
matchers.any? {|regex| full_route =~ regex}
|
161
163
|
end
|
162
164
|
|
163
165
|
def build_js(route, parent_route)
|
data/lib/js_routes/engine.rb
CHANGED
@@ -3,13 +3,19 @@ class JsRoutes
|
|
3
3
|
JS_ROUTES_ASSET = 'js-routes'
|
4
4
|
|
5
5
|
initializer 'js-routes.dependent_on_routes', after: "sprockets.environment" do
|
6
|
+
routes = Rails.root.join('config', 'routes.rb').to_s
|
7
|
+
|
6
8
|
if Rails.application.assets.respond_to?(:register_preprocessor)
|
7
|
-
routes = Rails.root.join('config','routes.rb')
|
8
9
|
Rails.application.assets.register_preprocessor 'application/javascript', :'js-routes_dependent_on_routes' do |ctx,data|
|
9
10
|
ctx.depend_on(routes) if ctx.logical_path == JS_ROUTES_ASSET
|
10
11
|
data
|
11
12
|
end
|
12
13
|
end
|
14
|
+
|
15
|
+
# only sprockets >= 3.0
|
16
|
+
if Rails.application.assets.respond_to?(:depend_on)
|
17
|
+
Rails.application.assets.depend_on "file-digest://#{routes}"
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
data/lib/js_routes/version.rb
CHANGED
File without changes
|
File without changes
|
@@ -36,13 +36,17 @@ describe JsRoutes do
|
|
36
36
|
|
37
37
|
describe ".generate!" do
|
38
38
|
|
39
|
-
let(:name) {
|
39
|
+
let(:name) { Rails.root.join('app', 'assets', 'javascripts', 'routes.js') }
|
40
40
|
|
41
41
|
before(:each) do
|
42
42
|
FileUtils.rm_f(name)
|
43
43
|
JsRoutes.generate!({:file => name})
|
44
44
|
end
|
45
45
|
|
46
|
+
after(:each) do
|
47
|
+
FileUtils.rm_f(name)
|
48
|
+
end
|
49
|
+
|
46
50
|
after(:all) do
|
47
51
|
FileUtils.rm_f("#{File.dirname(__FILE__)}/../routes.js") # let(:name) is not available here
|
48
52
|
end
|
@@ -6,17 +6,37 @@ require 'spec_helper'
|
|
6
6
|
require "fileutils"
|
7
7
|
|
8
8
|
describe "after Rails initialization" do
|
9
|
-
NAME =
|
9
|
+
NAME = Rails.root.join('app', 'assets', 'javascripts', 'routes.js').to_s
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
def sprockets_v3?
|
12
|
+
Sprockets::VERSION.to_i >= 3
|
13
|
+
end
|
14
|
+
|
15
|
+
def sprockets_context(environment, name, filename)
|
16
|
+
if sprockets_v3?
|
17
|
+
Sprockets::Context.new(environment: environment, name: name, filename: filename.to_s, metadata: {})
|
18
|
+
else
|
19
|
+
Sprockets::Context.new(environment, name, filename)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def evaluate(ctx, file)
|
24
|
+
if sprockets_v3?
|
25
|
+
ctx.load(ctx.environment.find_asset(file, pipeline: :default).uri).to_s
|
26
|
+
else
|
27
|
+
ctx.evaluate(file)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
before(:each) do
|
32
|
+
FileUtils.rm_rf Rails.root.join('tmp/cache')
|
33
|
+
FileUtils.rm_f NAME
|
13
34
|
JsRoutes.generate!(NAME)
|
14
|
-
Rails.configuration.eager_load = false
|
15
|
-
Rails.application.initialize!
|
16
35
|
end
|
17
36
|
|
18
|
-
|
19
|
-
|
37
|
+
before(:all) do
|
38
|
+
Rails.configuration.eager_load = false
|
39
|
+
Rails.application.initialize!
|
20
40
|
end
|
21
41
|
|
22
42
|
it "should generate routes file" do
|
@@ -38,21 +58,25 @@ describe "after Rails initialization" do
|
|
38
58
|
it "should have registered a preprocessor" do
|
39
59
|
pps = Rails.application.assets.preprocessors
|
40
60
|
js_pps = pps['application/javascript']
|
41
|
-
|
61
|
+
klass = sprockets_v3? ? 'LegacyProcProcessor' : 'Processor'
|
62
|
+
expect(js_pps.map(&:to_s)).to include("Sprockets::#{klass} (js-routes_dependent_on_routes)")
|
42
63
|
end
|
43
64
|
|
44
65
|
context "the preprocessor" do
|
45
66
|
before(:each) do
|
46
|
-
|
67
|
+
if sprockets_v3?
|
68
|
+
expect_any_instance_of(Sprockets::Context).to receive(:depend_on).with(Rails.root.join('config','routes.rb').to_s)
|
69
|
+
else
|
70
|
+
expect(ctx).to receive(:depend_on).with(Rails.root.join('config','routes.rb').to_s)
|
71
|
+
end
|
47
72
|
end
|
48
73
|
let!(:ctx) do
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
74
|
+
sprockets_context(Rails.application.assets,
|
75
|
+
'js-routes.js',
|
76
|
+
Pathname.new('js-routes.js'))
|
53
77
|
end
|
54
|
-
context "when dealing with js-routes.js" do
|
55
78
|
|
79
|
+
context "when dealing with js-routes.js" do
|
56
80
|
|
57
81
|
context "with Rails" do
|
58
82
|
context "and initialize on precompile" do
|
@@ -60,7 +84,7 @@ describe "after Rails initialization" do
|
|
60
84
|
Rails.application.config.assets.initialize_on_precompile = true
|
61
85
|
end
|
62
86
|
it "should render some javascript" do
|
63
|
-
expect(
|
87
|
+
expect(evaluate(ctx, 'js-routes.js')).to match(/root\.Routes/)
|
64
88
|
end
|
65
89
|
end
|
66
90
|
context "and not initialize on precompile" do
|
@@ -69,9 +93,9 @@ describe "after Rails initialization" do
|
|
69
93
|
end
|
70
94
|
it "should raise an exception if 3 version" do
|
71
95
|
if 3 == Rails::VERSION::MAJOR
|
72
|
-
expect {
|
96
|
+
expect { evaluate(ctx, 'js-routes.js') }.to raise_error(/Cannot precompile/)
|
73
97
|
else
|
74
|
-
expect(
|
98
|
+
expect(evaluate(ctx, 'js-routes.js')).to match(/root\.Routes/)
|
75
99
|
end
|
76
100
|
end
|
77
101
|
end
|
@@ -83,11 +107,11 @@ describe "after Rails initialization" do
|
|
83
107
|
end
|
84
108
|
context "when not dealing with js-routes.js" do
|
85
109
|
it "should not depend on routes.rb" do
|
86
|
-
ctx =
|
87
|
-
|
88
|
-
|
110
|
+
ctx = sprockets_context(Rails.application.assets,
|
111
|
+
'test.js',
|
112
|
+
TEST_ASSET_PATH)
|
89
113
|
expect(ctx).not_to receive(:depend_on)
|
90
|
-
|
114
|
+
evaluate(ctx, 'test.js')
|
91
115
|
end
|
92
116
|
end
|
93
117
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -144,8 +144,11 @@ files:
|
|
144
144
|
- app/assets/javascripts/js-routes.js.erb
|
145
145
|
- gemfiles/rails32.gemfile
|
146
146
|
- gemfiles/rails40.gemfile
|
147
|
+
- gemfiles/rails40_sprockets3.gemfile
|
147
148
|
- gemfiles/rails41.gemfile
|
149
|
+
- gemfiles/rails41_sprockets3.gemfile
|
148
150
|
- gemfiles/rails42.gemfile
|
151
|
+
- gemfiles/rails42_sprockets3.gemfile
|
149
152
|
- js-routes.gemspec
|
150
153
|
- lib/js-routes.rb
|
151
154
|
- lib/js_routes.rb
|
@@ -154,7 +157,8 @@ files:
|
|
154
157
|
- lib/routes.js
|
155
158
|
- lib/routes.js.coffee
|
156
159
|
- lib/tasks/js_routes.rake
|
157
|
-
- spec/
|
160
|
+
- spec/dummy/app/assets/javascripts/.gitkeep
|
161
|
+
- spec/dummy/config/routes.rb
|
158
162
|
- spec/js_routes/amd_compatibility_spec.rb
|
159
163
|
- spec/js_routes/generated_javascript_spec.rb
|
160
164
|
- spec/js_routes/options_spec.rb
|
@@ -182,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
186
|
version: '0'
|
183
187
|
requirements: []
|
184
188
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.
|
189
|
+
rubygems_version: 2.4.5
|
186
190
|
signing_key:
|
187
191
|
specification_version: 4
|
188
192
|
summary: Brings Rails named routes to javascript
|