js-routes 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/js_routes/version.rb +1 -1
- data/lib/routes.js +4 -2
- data/lib/routes.js.coffee +6 -2
- data/spec/js_routes/rails_routes_compatibility_spec.rb +4 -0
- data/spec/spec_helper.rb +3 -3
- metadata +2 -2
data/lib/js_routes/version.rb
CHANGED
data/lib/routes.js
CHANGED
@@ -147,7 +147,7 @@
|
|
147
147
|
return result;
|
148
148
|
},
|
149
149
|
build_path: function(required_parameters, optional_parts, route, args) {
|
150
|
-
var opts, parameters, result, url, url_params;
|
150
|
+
var anchor, opts, parameters, result, url, url_params;
|
151
151
|
|
152
152
|
args = Array.prototype.slice.call(args);
|
153
153
|
opts = this.extract_options(required_parameters.length, args);
|
@@ -156,11 +156,13 @@
|
|
156
156
|
}
|
157
157
|
parameters = this.prepare_parameters(required_parameters, args, opts);
|
158
158
|
this.set_default_url_options(optional_parts, parameters);
|
159
|
+
anchor = this.extract_anchor(parameters);
|
159
160
|
result = "" + (this.get_prefix()) + (this.visit(route, parameters));
|
160
|
-
url = Utils.clean_path("" + result
|
161
|
+
url = Utils.clean_path("" + result);
|
161
162
|
if ((url_params = this.serialize(parameters)).length) {
|
162
163
|
url += "?" + url_params;
|
163
164
|
}
|
165
|
+
url += anchor;
|
164
166
|
return url;
|
165
167
|
},
|
166
168
|
visit: function(route, parameters, optional) {
|
data/lib/routes.js.coffee
CHANGED
@@ -86,10 +86,14 @@ Utils =
|
|
86
86
|
throw new Error("Too many parameters provided for path")
|
87
87
|
parameters = @prepare_parameters(required_parameters, args, opts)
|
88
88
|
@set_default_url_options optional_parts, parameters
|
89
|
+
anchor = @extract_anchor(parameters)
|
89
90
|
result = "#{@get_prefix()}#{@visit(route, parameters)}"
|
90
|
-
url = Utils.clean_path("#{result}
|
91
|
-
|
91
|
+
url = Utils.clean_path("#{result}")
|
92
|
+
if (url_params = @serialize(parameters)).length
|
93
|
+
url += "?#{url_params}"
|
94
|
+
url += anchor
|
92
95
|
url
|
96
|
+
|
93
97
|
#
|
94
98
|
# This function is JavaScript impelementation of the
|
95
99
|
# Journey::Visitors::Formatter that builds route by given parameters
|
@@ -60,6 +60,10 @@ describe JsRoutes, "compatibility with Rails" do
|
|
60
60
|
evaljs("Routes.inbox_path(1, {anchor: 'hello'})").should == routes.inbox_path(1, :anchor => "hello")
|
61
61
|
end
|
62
62
|
|
63
|
+
it "should support url anchor and get parameters" do
|
64
|
+
evaljs("Routes.inbox_path(1, {expanded: true, anchor: 'hello'})").should == routes.inbox_path(1, :expanded => true, :anchor => "hello")
|
65
|
+
end
|
66
|
+
|
63
67
|
it "should support engine routes" do
|
64
68
|
evaljs("Routes.blog_app_posts_path()").should == blog_routes.posts_path()
|
65
69
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -67,10 +67,10 @@ def draw_routes
|
|
67
67
|
resources :things
|
68
68
|
end
|
69
69
|
|
70
|
-
|
70
|
+
get "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
|
71
71
|
|
72
|
-
|
73
|
-
|
72
|
+
get 'books/*section/:title' => 'books#show', :as => :book
|
73
|
+
get 'books/:title/*section' => 'books#show', :as => :book_title
|
74
74
|
|
75
75
|
mount BlogEngine::Engine => "/blog", :as => :blog_app
|
76
76
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
segments:
|
187
187
|
- 0
|
188
|
-
hash:
|
188
|
+
hash: 3484352808511578031
|
189
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
190
|
none: false
|
191
191
|
requirements:
|