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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82dc4e938c01969d6fa291afba76adbdc12106ce
4
- data.tar.gz: ccab6107d6e2a86ab1529a2fa4ce06e4af50c820
3
+ metadata.gz: c68aed8760da61aa1ff4977b8d69f09cfc609f18
4
+ data.tar.gz: f4362dcdb29332048b5a19d3ed40dce4717b6bd9
5
5
  SHA512:
6
- metadata.gz: 027362db5b8c3f3848cdea09fa9095364a3307e9f492ca5d871d9174e676e05492d5149818f76df989b53e15499465287c93644fa19b0b55117da8b1ed0db0b8
7
- data.tar.gz: bbe7ac6a521322201322a01dcb847dcee803f8524dd1f190c17e5c99fe24fb5a6b57d27dd66644ff0b5be4c4fbc733dc69853d619cda8c975e7269f182daddcb
6
+ metadata.gz: cd44c50605191eda0663671b1d7bf46bcffa7e4e13705e8ca9177fc3c8ac332ea1abac89448a7dfc27e4e9eee5d98ad340f602fea6b082c0af144449e5e46c31
7
+ data.tar.gz: bc598e7e2a6c51477162b6e76d4d423e4e6bd6454247305593d343934abd04ae20a829301695e7707ed86bc38c8da7ce00a3c224f3b9e3e5e3b3e35e8ce2320c
data/.gitignore CHANGED
@@ -53,4 +53,8 @@ pkg
53
53
  Gemfile.lock
54
54
  gemfiles/*.lock
55
55
 
56
- .DS_Store
56
+ .DS_Store
57
+
58
+ /spec/dummy/app/assets/javascripts/routes.js
59
+ /spec/dummy/logs
60
+ /spec/dummy/tmp
data/.travis.yml CHANGED
@@ -15,6 +15,9 @@ gemfile:
15
15
  - gemfiles/rails40.gemfile
16
16
  - gemfiles/rails41.gemfile
17
17
  - gemfiles/rails42.gemfile
18
+ - gemfiles/rails40_sprockets3.gemfile
19
+ - gemfiles/rails41_sprockets3.gemfile
20
+ - gemfiles/rails42_sprockets3.gemfile
18
21
 
19
22
  sudo: false
20
23
 
data/Appraisals CHANGED
@@ -3,14 +3,14 @@ appraise "rails32" do
3
3
  gem 'tzinfo'
4
4
  end
5
5
 
6
- appraise "rails40" do
7
- gem "railties", "~> 4.0.5"
8
- end
9
-
10
- appraise "rails41" do
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 "rails42" do
15
- gem "railties", "~> 4.2.0"
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)
@@ -3,5 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "railties", "~> 4.0.5"
6
+ gem "sprockets", "< 3"
6
7
 
7
8
  gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "railties", "~> 4.0.5"
6
+ gem "sprockets", "~> 3.0"
7
+
8
+ gemspec :path => "../"
@@ -3,5 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "railties", "~> 4.1.1"
6
+ gem "sprockets", "< 3"
6
7
 
7
8
  gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "railties", "~> 4.1.1"
6
+ gem "sprockets", "~> 3.0"
7
+
8
+ gemspec :path => "../"
@@ -3,5 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "railties", "~> 4.2.0"
6
+ gem "sprockets", "< 3"
6
7
 
7
8
  gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "railties", "~> 4.2.0"
6
+ gem "sprockets", "~> 3.0"
7
+
8
+ gemspec :path => "../"
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| [parent_route.try(:name), route.name].compact.join('_') =~ regex}
162
+ matchers.any? {|regex| full_route =~ regex}
161
163
  end
162
164
 
163
165
  def build_js(route, parent_route)
@@ -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
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
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) { "#{File.dirname(__FILE__)}/../routes.js" }
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 = "#{File.dirname(__FILE__)}/../routes.js"
9
+ NAME = Rails.root.join('app', 'assets', 'javascripts', 'routes.js').to_s
10
10
 
11
- before(:all) do
12
- FileUtils.rm_f(NAME)
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
- after(:all) do
19
- FileUtils.rm_f(NAME)
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
- expect(js_pps.map(&:name)).to include('Sprockets::Processor (js-routes_dependent_on_routes)')
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
- expect(ctx).to receive(:depend_on).with(Rails.root.join('config','routes.rb'))
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
- Sprockets::Context.new(Rails.application.assets,
50
- 'js-routes.js',
51
- Pathname.new('js-routes.js'))
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(ctx.evaluate('js-routes.js')).to match(/root\.Routes/)
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 { ctx.evaluate('js-routes.js') }.to raise_error(/Cannot precompile/)
96
+ expect { evaluate(ctx, 'js-routes.js') }.to raise_error(/Cannot precompile/)
73
97
  else
74
- expect(ctx.evaluate('js-routes.js')).to match(/root\.Routes/)
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 = Sprockets::Context.new(Rails.application.assets,
87
- 'test.js',
88
- TEST_ASSET_PATH)
110
+ ctx = sprockets_context(Rails.application.assets,
111
+ 'test.js',
112
+ TEST_ASSET_PATH)
89
113
  expect(ctx).not_to receive(:depend_on)
90
- ctx.evaluate('test.js')
114
+ evaluate(ctx, 'test.js')
91
115
  end
92
116
  end
93
117
  end
data/spec/spec_helper.rb CHANGED
@@ -62,6 +62,8 @@ class App < Rails::Application
62
62
  else
63
63
  config.paths['config/routes.rb'] << 'spec/config/routes.rb'
64
64
  end
65
+
66
+ config.root = File.expand_path('../dummy', __FILE__)
65
67
  end
66
68
 
67
69
  def draw_routes
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.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: 2014-12-31 00:00:00.000000000 Z
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/config/routes.rb
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.2.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