js-routes 1.2.5 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/Readme.md +10 -1
- data/js-routes.gemspec +1 -2
- data/lib/js_routes/version.rb +1 -1
- data/lib/js_routes.rb +1 -1
- data/lib/routes.js +5 -2
- data/lib/routes.js.coffee +8 -3
- data/spec/js_routes/options_spec.rb +12 -3
- data/spec/spec_helper.rb +8 -2
- metadata +4 -20
- data/Guardfile +0 -3
- data/temp +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 547d8dc7d5bb050616b71bb10d414aeddb9fcb6a
|
4
|
+
data.tar.gz: 35c567ffb95027338b01162db20daa8e312adc32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bece2fc2356916ecf50103bdbd4fcff15d2dbaa024d7bfdc24e4f521f6ca513eb47a1c4938370dd04bdcbe4563b80fe0b3ff5506f2b7507ce6a83688557ad03c
|
7
|
+
data.tar.gz: a89e298a614595691c1a5a0f9e91fed8ee6a934645a6e7a26f6785ba970499dd1de5be8a140a4b90b1dcf3dc3e231614379da4e7e4b5483e0f76a713c0c7ec52
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
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:
|
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<
|
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"])
|
data/lib/js_routes/version.rb
CHANGED
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(
|
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]
|
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(
|
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
|
-
|
165
|
-
|
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
|
-
|
190
|
-
|
191
|
-
|
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
|
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.
|
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-
|
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:
|
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.
|
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
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>
|