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.
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
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 + (this.extract_anchor(parameters)));
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}#{@extract_anchor(parameters)}")
91
- url += "?#{url_params}" if (url_params = @serialize(parameters)).length
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
- match "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
70
+ get "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
71
71
 
72
- match 'books/*section/:title' => 'books#show', :as => :book
73
- match 'books/:title/*section' => 'books#show', :as => :book_title
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.1
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: 3670636352927995574
188
+ hash: 3484352808511578031
189
189
  required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  none: false
191
191
  requirements: