js-routes 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -5
- data/Appraisals +0 -5
- data/CHANGELOG.md +4 -0
- data/Readme.md +3 -2
- data/js-routes.gemspec +1 -1
- data/lib/js_routes.rb +20 -15
- data/lib/js_routes/version.rb +1 -1
- data/spec/js_routes/rails_routes_compatibility_spec.rb +10 -1
- data/spec/spec_helper.rb +9 -0
- metadata +6 -7
- data/gemfiles/rails_edge.gemfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdc29ff3518fbfff23264671cc315d039bb101a6
|
4
|
+
data.tar.gz: 2769ad304c13cf6ea12301e6d1cf5dd3e7c7f8af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 063dc04137909b02008460ae82ff1098485b1607a6c3d25222b9fd870b6391fae334dc42610dd591956ba5e97131637692eac2c4088cb1f784e9c7d964c18111
|
7
|
+
data.tar.gz: 432a56cb935312ab939dfe7840e4b4e174efd2135f330c25ca9e3e0c64e762a27e1eb3b5adf31cff928347480dec4b6b6ab89913125bf54f469d31e5d7d7c7da
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
data/Readme.md
CHANGED
@@ -11,7 +11,7 @@ Your Rails Gemfile:
|
|
11
11
|
gem "js-routes"
|
12
12
|
```
|
13
13
|
|
14
|
-
### Basic Setup
|
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
|
-
*
|
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.
|
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
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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.
|
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
|
189
|
-
optional_parts.
|
190
|
-
[
|
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
|
data/lib/js_routes/version.rb
CHANGED
@@ -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
|
-
|
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.
|
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-
|
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: '
|
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: '
|
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
|