js-routes 1.2.0 → 1.2.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: e61c1a78d1a68a39e174a3459048f939ac1a5491
4
- data.tar.gz: 2690497a175312cb4fd282626eae3adf87718cbb
3
+ metadata.gz: fdc29ff3518fbfff23264671cc315d039bb101a6
4
+ data.tar.gz: 2769ad304c13cf6ea12301e6d1cf5dd3e7c7f8af
5
5
  SHA512:
6
- metadata.gz: 1698494469561e6a34ae36c1f38ae74da0b2a94ecb6e6a4531e25725021772e852f9d1d55f3be7eb9b373c00ad63d57ef67f909c6bbe4ed4dc843096bbc53250
7
- data.tar.gz: 04cc89d4715e92eb63c32ff6bd0498c1164d271cab2c976de65a3da3731a6f565691d169f3f1a8dfbf2c336ab6534ce4bdd60bf94cb848753a4082198ede0609
6
+ metadata.gz: 063dc04137909b02008460ae82ff1098485b1607a6c3d25222b9fd870b6391fae334dc42610dd591956ba5e97131637692eac2c4088cb1f784e9c7d964c18111
7
+ data.tar.gz: 432a56cb935312ab939dfe7840e4b4e174efd2135f330c25ca9e3e0c64e762a27e1eb3b5adf31cff928347480dec4b6b6ab89913125bf54f469d31e5d7d7c7da
data/.travis.yml CHANGED
@@ -30,12 +30,7 @@ branches:
30
30
  - master
31
31
 
32
32
  matrix:
33
- include:
34
- - gemfile: gemfiles/rails_edge.gemfile
35
- rvm: 2.2
36
33
  allow_failures:
37
34
  - rvm: jruby-19mode
38
35
  - rvm: ruby-head
39
36
  - rvm: jruby-head
40
- - gemfile: gemfiles/rails_edge.gemfile
41
- rvm: 2.2
data/Appraisals CHANGED
@@ -13,9 +13,4 @@ end
13
13
  gem "railties", "~> #{version}"
14
14
  gem "sprockets", "~> 3.0"
15
15
  end
16
- end
17
-
18
- appraise "rails-edge" do
19
- gem "railties", github: 'rails/rails'
20
- gem "sprockets", "~> 3.0"
21
16
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## master
2
2
 
3
+ ## v1.2.1
4
+
5
+ * Fixes for Rails 5
6
+
3
7
  ## v1.2.0
4
8
 
5
9
  * Support host, port and protocol inline parameters
data/Readme.md CHANGED
@@ -11,7 +11,7 @@ Your Rails Gemfile:
11
11
  gem "js-routes"
12
12
  ```
13
13
 
14
- ### Basic Setup (Asset Pipeline)
14
+ ### Basic Setup
15
15
 
16
16
  Require js routes file in `application.js` or other bundle
17
17
 
@@ -192,8 +192,9 @@ This should just work.
192
192
  There are some alternatives available. Most of them has only basic feature and don't reach the level of quality I accept.
193
193
  Advantages of this one are:
194
194
 
195
- * Rails3 & Rails4 support
195
+ * Rails 3-5 support
196
196
  * Rich options set
197
+ * Full rails compatibility
197
198
  * Support Rails `#to_param` convention for seo optimized paths
198
199
  * Well tested
199
200
 
data/js-routes.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.summary = %q{Brings Rails named routes to javascript}
22
22
 
23
23
  s.add_runtime_dependency(%q<railties>, [">= 3.2"])
24
- s.add_runtime_dependency(%q<sprockets-rails>)
24
+ s.add_runtime_dependency(%q<sprockets-rails>, ["< 3"])
25
25
  s.add_development_dependency(%q<rspec>, [">= 3.0.0"])
26
26
  s.add_development_dependency(%q<bundler>, [">= 1.1.0"])
27
27
  s.add_development_dependency(%q<guard>, [">= 0"])
data/lib/js_routes.rb CHANGED
@@ -59,7 +59,7 @@ class JsRoutes
59
59
 
60
60
  def generate(opts = {})
61
61
  # Ensure routes are loaded. If they're not, load them.
62
- if Rails.application.routes.named_routes.routes.keys.empty?
62
+ if Rails.application.routes.named_routes.to_a.empty?
63
63
  Rails.application.reload_routes!
64
64
  end
65
65
 
@@ -98,15 +98,18 @@ class JsRoutes
98
98
  end
99
99
 
100
100
  def generate
101
- js = File.read(File.dirname(__FILE__) + "/routes.js")
102
- js.gsub!("GEM_VERSION", JsRoutes::VERSION)
103
- js.gsub!("APP_CLASS", Rails.application.class.to_s)
104
- js.gsub!("NAMESPACE", @options[:namespace])
105
- js.gsub!("DEFAULT_URL_OPTIONS", json(@options[:default_url_options].merge(deprecated_default_format)))
106
- js.gsub!("PREFIX", @options[:prefix] || "")
107
- js.gsub!("NODE_TYPES", json(NODE_TYPES))
108
- js.gsub!("SERIALIZER", @options[:serializer] || "null")
109
- js.gsub!("ROUTES", js_routes)
101
+ {
102
+ "GEM_VERSION" => JsRoutes::VERSION,
103
+ "APP_CLASS" => Rails.application.class.to_s,
104
+ "NAMESPACE" => @options[:namespace],
105
+ "DEFAULT_URL_OPTIONS" => json(@options[:default_url_options].merge(deprecated_default_format)),
106
+ "PREFIX" => @options[:prefix] || "",
107
+ "NODE_TYPES" => json(NODE_TYPES),
108
+ "SERIALIZER" => @options[:serializer] || "null",
109
+ "ROUTES" => js_routes,
110
+ }.inject(File.read(File.dirname(__FILE__) + "/routes.js")) do |js, (key, value)|
111
+ js.gsub!(key, value)
112
+ end
110
113
  end
111
114
 
112
115
  def deprecated_default_format
@@ -133,7 +136,7 @@ class JsRoutes
133
136
  protected
134
137
 
135
138
  def js_routes
136
- js_routes = Rails.application.routes.named_routes.routes.sort_by(&:to_s).flat_map do |_, route|
139
+ js_routes = Rails.application.routes.named_routes.to_a.sort_by(&:to_s).flat_map do |_, route|
137
140
  rails_engine_app = get_app_from_route(route)
138
141
  if rails_engine_app.respond_to?(:superclass) && rails_engine_app.superclass == Rails::Engine && !route.path.anchored
139
142
  rails_engine_app.routes.named_routes.map do |_, engine_route|
@@ -185,9 +188,11 @@ class JsRoutes
185
188
  end
186
189
 
187
190
  def route_js_arguments(route, parent_spec)
188
- required_parts, optional_parts = route.required_parts.clone, (route.parts-route.required_parts)
189
- optional_parts.push(required_parts.delete :format) if required_parts.include?(:format)
190
- [json(required_parts), json(optional_parts), json(serialize(route.path.spec, parent_spec))].join(", ")
191
+ required_parts = route.required_parts.clone
192
+ optional_parts = route.parts - required_parts
193
+ [required_parts, optional_parts, serialize(route.path.spec, parent_spec)].map do |argument|
194
+ json(argument)
195
+ end.join(", ")
191
196
  end
192
197
 
193
198
  def generate_url_link(name, route_name, route_arguments, route)
@@ -201,7 +206,7 @@ class JsRoutes
201
206
  def deprecated_base_url
202
207
  ActiveSupport::Deprecation.warn('js-routes url_links config value must be a boolean. Use default_url_options for specifying a default host.')
203
208
 
204
-
209
+
205
210
  raise "invalid URL format in url_links (ex: http[s]://example.com)" if @options[:url_links].match(URI::Parser.new.make_regexp(%w(http https))).nil?
206
211
  uri = URI.parse(@options[:url_links])
207
212
  default_port = uri.scheme == "https" ? 443 : 80
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -54,6 +54,13 @@ describe JsRoutes, "compatibility with Rails" do
54
54
  expect(evaljs("Routes.inbox_path(1, {expanded: true, anchor: 'hello'})")).to eq(routes.inbox_path(1, :expanded => true, :anchor => "hello"))
55
55
  end
56
56
 
57
+ it "should use irregular ActiveSupport pluralizations" do
58
+ expect(evaljs("Routes.budgies_path()")).to eq(routes.budgies_path)
59
+ expect(evaljs("Routes.budgie_path(1)")).to eq(routes.budgie_path(1))
60
+ expect(evaljs("Routes.budgy_path")).to eq(nil)
61
+ expect(evaljs("Routes.budgie_descendents_path(1)")).to eq(routes.budgie_descendents_path(1))
62
+ end
63
+
57
64
  context "with rails engines" do
58
65
  it "should support simple route" do
59
66
  expect(evaljs("Routes.blog_app_posts_path()")).to eq(blog_routes.posts_path())
@@ -284,7 +291,7 @@ describe JsRoutes, "compatibility with Rails" do
284
291
  end
285
292
  end
286
293
 
287
- context "when params" do
294
+ describe "required_params" do
288
295
  it "should show inbox spec" do
289
296
  expect(evaljs("Routes.inbox_path.required_params").to_a).to eq(["id"])
290
297
  end
@@ -293,4 +300,6 @@ describe JsRoutes, "compatibility with Rails" do
293
300
  expect(evaljs("Routes.inbox_message_path.required_params").to_a).to eq(["inbox_id", "id"])
294
301
  end
295
302
  end
303
+
304
+
296
305
  end
data/spec/spec_helper.rb CHANGED
@@ -42,6 +42,10 @@ def blog_routes
42
42
  BlogEngine::Engine.routes.url_helpers
43
43
  end
44
44
 
45
+ ActiveSupport::Inflector.inflections do |inflect|
46
+ inflect.irregular "budgie", "budgies"
47
+ end
48
+
45
49
 
46
50
  module BlogEngine
47
51
  class Engine < Rails::Engine
@@ -118,6 +122,11 @@ def draw_routes
118
122
  get '/' => 'sso#login', host: 'sso.example.com', as: :sso
119
123
 
120
124
  resources :portals, :port => 8080
125
+
126
+ resources :budgies do
127
+ get "descendents"
128
+ end
129
+
121
130
  end
122
131
 
123
132
  end
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.2.0
4
+ version: 1.2.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: 2015-12-22 00:00:00.000000000 Z
11
+ date: 2015-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: sprockets-rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "<"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -163,7 +163,6 @@ files:
163
163
  - gemfiles/rails41_sprockets3.gemfile
164
164
  - gemfiles/rails42.gemfile
165
165
  - gemfiles/rails42_sprockets3.gemfile
166
- - gemfiles/rails_edge.gemfile
167
166
  - js-routes.gemspec
168
167
  - lib/js-routes.rb
169
168
  - lib/js_routes.rb
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "railties", :github => "rails/rails"
6
- gem "sprockets", "~> 3.0"
7
-
8
- gemspec :path => "../"