js-routes 1.2.5 → 1.2.6

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: 7eea4ced1f8ac4696d7203ac13d2037055a1283d
4
- data.tar.gz: bbe6a004e246ca056ac0f0ec1a48562a6c20f5cb
3
+ metadata.gz: 547d8dc7d5bb050616b71bb10d414aeddb9fcb6a
4
+ data.tar.gz: 35c567ffb95027338b01162db20daa8e312adc32
5
5
  SHA512:
6
- metadata.gz: aaead3fa492158178fc38c904142129862c698e4f58547915e8ed139d398971ad396ba5bdf4b609a267dd7498062ea7abcc714a80046cdfadd879780a26abd44
7
- data.tar.gz: ff5e478c5a8c4791fd4f967b790698799d04cbaf424886c40d923ee94a742d98266480c8e9df1902d7b84c921d4e5306fb19c56d65bfbb4327e7962a00753560
6
+ metadata.gz: bece2fc2356916ecf50103bdbd4fcff15d2dbaa024d7bfdc24e4f521f6ca513eb47a1c4938370dd04bdcbe4563b80fe0b3ff5506f2b7507ce6a83688557ad03c
7
+ data.tar.gz: a89e298a614595691c1a5a0f9e91fed8ee6a934645a6e7a26f6785ba970499dd1de5be8a140a4b90b1dcf3dc3e231614379da4e7e4b5483e0f76a713c0c7ec52
data/.travis.yml CHANGED
@@ -6,6 +6,7 @@ rvm:
6
6
  - 2.0
7
7
  - 2.1
8
8
  - 2.2
9
+ - 2.3.1
9
10
  - jruby-19mode
10
11
  - ruby-head
11
12
  - jruby-head
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## master
2
2
 
3
+ ## v1.2.6
4
+
5
+ * Use default prefix from `Rails.application.config.relative_url_root` #186
6
+ * Bugfix route globbing with optional fragments bug #191
7
+
3
8
  ## v1.2.5
4
9
 
5
10
  * Bugfix subdomain default parameter in routes #184
data/Readme.md CHANGED
@@ -58,7 +58,7 @@ Available options:
58
58
  * Default: `Routes`
59
59
  * `prefix` - String representing a url path to prepend to all paths.
60
60
  * Example: `http://yourdomain.com`. This will cause route helpers to generate full path only.
61
- * Default: blank
61
+ * Default: Rails.application.config.relative_url_root
62
62
  * `camel_case` (version >= 0.8.8) - Generate camel case route names.
63
63
  * Default: false
64
64
  * `url_links` (version >= 0.8.9) - Generate `*_url` helpers (in addition to the default `*_path` helpers).
@@ -109,6 +109,15 @@ JsRoutes.generate!("#{path}/adm_routes.js", :namespace => "AdmRoutes", :include
109
109
  JsRoutes.generate!("#{path}/api_routes.js", :namespace => "ApiRoutes", :include => /^api_/, :default_url_options => {:format => "json"})
110
110
  ```
111
111
 
112
+ ### Rails relative URL root
113
+
114
+ If you've installed your application in a sub-path or sub-URI of your server instead of at the root, you need to set the `RAILS_RELATIVE_URL_ROOT` environment variable to the correct path prefix for your application when you precompile assets. Eg., if your application's base URL is "https://appl.example.com/Application1", the command to precompile assets would be:
115
+ ```
116
+ RAILS_RELATIVE_URL_ROOT=/Application1 RAILS_ENV=production bundle exec rake assets:precompile
117
+ ```
118
+ The environment variable is only needed for precompilation of assets, at any other time (eg. when assets are compiled on-the-fly as in the development environment) Rails will set the relative URL root correctly on it's own.
119
+
120
+
112
121
  ## Usage
113
122
 
114
123
  Configuration above will create a nice javascript file with `Routes` object that has all the rails routes available:
data/js-routes.gemspec CHANGED
@@ -24,8 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency(%q<sprockets-rails>)
25
25
  s.add_development_dependency(%q<rspec>, [">= 3.0.0"])
26
26
  s.add_development_dependency(%q<bundler>, [">= 1.1.0"])
27
- s.add_development_dependency(%q<guard>, [">= 0"])
28
- s.add_development_dependency(%q<guard-coffeescript>, [">= 0"])
27
+ s.add_development_dependency(%q<coffee-script>, [">= 0"])
29
28
  s.add_development_dependency(%q<appraisal>, [">= 0.5.2"])
30
29
  if defined?(JRUBY_VERSION)
31
30
  s.add_development_dependency(%q<therubyrhino>, [">= 2.0.4"])
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "1.2.5"
2
+ VERSION = "1.2.6"
3
3
  end
data/lib/js_routes.rb CHANGED
@@ -104,7 +104,7 @@ class JsRoutes
104
104
  "APP_CLASS" => Rails.application.class.to_s,
105
105
  "NAMESPACE" => @options[:namespace],
106
106
  "DEFAULT_URL_OPTIONS" => json(@options[:default_url_options].merge(deprecate_url_options)),
107
- "PREFIX" => @options[:prefix] || "",
107
+ "PREFIX" => @options[:prefix] || Rails.application.config.relative_url_root || "",
108
108
  "NODE_TYPES" => json(NODE_TYPES),
109
109
  "SERIALIZER" => @options[:serializer] || "null",
110
110
  "ROUTES" => js_routes,
data/lib/routes.js CHANGED
@@ -193,7 +193,7 @@ Based on Rails routes of APP_CLASS
193
193
  options = this.normalize_options(default_parts, required_parameters, optional_parts, args);
194
194
  parameters = options['url_parameters'];
195
195
  result = "" + (this.get_prefix()) + (this.visit(route, parameters));
196
- url = Utils.clean_path("" + result);
196
+ url = Utils.clean_path(result);
197
197
  if (options['trailing_slash'] === true) {
198
198
  url = url.replace(/(.*?)[\/]?$/, "$1/");
199
199
  }
@@ -224,7 +224,7 @@ Based on Rails routes of APP_CLASS
224
224
  case NodeTypes.CAT:
225
225
  left_part = this.visit(left, parameters, optional);
226
226
  right_part = this.visit(right, parameters, optional);
227
- if (optional && (((left[0] === NodeTypes.SYMBOL || left[0] === NodeTypes.CAT) && !left_part) || ((right[0] === NodeTypes.SYMBOL || right[0] === NodeTypes.CAT) && !right_part))) {
227
+ if (optional && ((this.is_optional_node(left[0]) && !left_part) || ((this.is_optional_node(right[0])) && !right_part))) {
228
228
  return "";
229
229
  }
230
230
  return "" + left_part + right_part;
@@ -244,6 +244,9 @@ Based on Rails routes of APP_CLASS
244
244
  throw new Error("Unknown Rails node type");
245
245
  }
246
246
  },
247
+ is_optional_node: function(node) {
248
+ return node === NodeTypes.STAR || node === NodeTypes.SYMBOL || node === NodeTypes.CAT;
249
+ },
247
250
  build_path_spec: function(route, wildcard) {
248
251
  var left, right, type;
249
252
  if (wildcard == null) {
data/lib/routes.js.coffee CHANGED
@@ -126,7 +126,7 @@ Utils =
126
126
 
127
127
  # path
128
128
  result = "#{@get_prefix()}#{@visit(route, parameters)}"
129
- url = Utils.clean_path("#{result}")
129
+ url = Utils.clean_path(result)
130
130
  # set trailing_slash
131
131
  url = url.replace(/(.*?)[\/]?$/, "$1/") if options['trailing_slash'] is true
132
132
  # set additional url params
@@ -161,8 +161,9 @@ Utils =
161
161
  when NodeTypes.CAT
162
162
  left_part = @visit(left, parameters, optional)
163
163
  right_part = @visit(right, parameters, optional)
164
- return "" if optional and (((left[0] == NodeTypes.SYMBOL or left[0] == NodeTypes.CAT) and not left_part) or
165
- ((right[0] == NodeTypes.SYMBOL or right[0] == NodeTypes.CAT) and not right_part))
164
+ if optional and ((@is_optional_node(left[0]) and not left_part) or
165
+ ((@is_optional_node(right[0])) and not right_part))
166
+ return ""
166
167
  "#{left_part}#{right_part}"
167
168
  when NodeTypes.SYMBOL
168
169
  value = parameters[left]
@@ -181,6 +182,10 @@ Utils =
181
182
  else
182
183
  throw new Error("Unknown Rails node type")
183
184
 
185
+
186
+ is_optional_node: (node) ->
187
+ node == NodeTypes.STAR or node == NodeTypes.SYMBOL or node == NodeTypes.CAT
188
+
184
189
  #
185
190
  # This method build spec for route
186
191
  #
@@ -186,9 +186,18 @@ describe JsRoutes, "options" do
186
186
 
187
187
  describe "default_url_options" do
188
188
  context "with optional route parts" do
189
- let(:_options) { {:default_url_options => {:optional_id => "12", :format => "json"}}}
190
- it "should use this opions to fill optional parameters" do
191
- expect(evaljs("Routes.things_path()")).to eq(routes.things_path(:optional_id => 12, :format => "json"))
189
+ context "provided" do
190
+ let(:_options) { { :default_url_options => { :optional_id => "12", :format => "json" } } }
191
+ it "should use this opions to fill optional parameters" do
192
+ expect(evaljs("Routes.things_path()")).to eq(routes.things_path(:optional_id => 12, :format => "json"))
193
+ end
194
+ end
195
+
196
+ context "not provided" do
197
+ let(:_options) { { :default_url_options => { :format => "json" } } }
198
+ it "breaks" do
199
+ expect(evaljs("Routes.foo_all_path()")).to eq(routes.foo_all_path(:format => "json"))
200
+ end
192
201
  end
193
202
  end
194
203
 
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ $:.unshift(File.dirname(__FILE__))
5
5
  require 'rspec'
6
6
  require 'rails/all'
7
7
  require 'js-routes'
8
- require "active_support/core_ext/hash/slice"
8
+ require 'active_support/core_ext/hash/slice'
9
9
  require 'coffee-script'
10
10
  # fix ends_with? error for rails 3.2
11
11
  require 'active_support/core_ext/string/starts_ends_with' if 3 == Rails::VERSION::MAJOR
@@ -104,6 +104,7 @@ def draw_routes
104
104
  get "/:controller(/:action(/:id))" => "classic#classic", :as => :classic
105
105
 
106
106
  get "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
107
+ get '/other_optional(/*optional_id)' => 'foo#foo', :as => :foo_all
107
108
 
108
109
  get 'books/*section/:title' => 'books#show', :as => :book
109
110
  get 'books/:title/*section' => 'books#show', :as => :book_title
@@ -167,11 +168,16 @@ RSpec.configure do |config|
167
168
 
168
169
  def inspectify(value)
169
170
  case value
171
+ when V8::Array
172
+ value.map do |v|
173
+ inspectify(v)
174
+ end
170
175
  when V8::Object
176
+ require 'byebug'; byebug
171
177
  value.to_h.map do |k,v|
172
178
  [k, inspectify(v)]
173
179
  end.to_h
174
- when String, nil
180
+ when String, nil, Fixnum, FalseClass, TrueClass
175
181
  value
176
182
  else
177
183
  raise "wtf #{value.class}?"
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.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -67,21 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.1.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: guard
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: guard-coffeescript
70
+ name: coffee-script
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ">="
@@ -151,7 +137,6 @@ files:
151
137
  - Appraisals
152
138
  - CHANGELOG.md
153
139
  - Gemfile
154
- - Guardfile
155
140
  - LICENSE.txt
156
141
  - Rakefile
157
142
  - Readme.md
@@ -180,7 +165,6 @@ files:
180
165
  - spec/js_routes/rails_routes_compatibility_spec.rb
181
166
  - spec/js_routes/zzz_last_post_rails_init_spec.rb
182
167
  - spec/spec_helper.rb
183
- - temp
184
168
  homepage: http://github.com/railsware/js-routes
185
169
  licenses:
186
170
  - MIT
@@ -201,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
185
  version: '0'
202
186
  requirements: []
203
187
  rubyforge_project:
204
- rubygems_version: 2.4.7
188
+ rubygems_version: 2.5.1
205
189
  signing_key:
206
190
  specification_version: 4
207
191
  summary: Brings Rails named routes to javascript
data/Guardfile DELETED
@@ -1,3 +0,0 @@
1
- guard 'coffeescript', :output => 'lib', :all_on_start => true do
2
- watch(%r{^lib/(.+\.coffee)$})
3
- end
data/temp DELETED
@@ -1,2 +0,0 @@
1
- #<ActionDispatch::Journey::Route:0x007f8c4bdba798 @name="blog_app", @app=BlogEngine::Engine, @path=#<ActionDispatch::Journey::Path::Pattern:0x007f8c4bdbb120 @anchored=false, @spec=/blog, @requirements={}, @separators="/.?", @names=[], @optional_names=[], @required_names=[], @re=nil, @offsets=nil>, @dispatcher=false, @constraints={:required_defaults=>[]}, @defaults={}, @required_defaults=nil, @required_parts=[], @parts=[], @decorated_ast=nil, @precedence=61>
2
- #<ActionDispatch::Journey::Route:0x007f8c4a861658 @name="support", @app=BlogEngine::Engine, @path=#<ActionDispatch::Journey::Path::Pattern:0x007f8c4a85c838 @anchored=true, @spec=/support(/page/:page)(.:format), @requirements={}, @separators="/.?", @names=["page", "format"], @optional_names=["page", "format"], @required_names=[], @re=nil, @offsets=nil>, @dispatcher=false, @constraints={:required_defaults=>[], :request_method=>/^GET$/}, @defaults={}, @required_defaults=nil, @required_parts=[], @parts=[:page, :format], @decorated_ast=nil, @precedence=0>