js-routes 0.9.2 → 0.9.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be32b22dcc7600a2141329061740f8fe7e9ff6e5
4
+ data.tar.gz: 64d3981fdf7cb0889ae9005c15821a6ff13b3997
5
+ SHA512:
6
+ metadata.gz: 50da4f85cb59aaadc6e76cecbee608617a899d22b996c4d99590c2cac89e16981087282cfc56c727939ae40018afb9b3e8eb24baad57c09f915d89ff4a2a07fe
7
+ data.tar.gz: a503183633ad8570afbaa81124d3337ebc51420313b1d16d6a9d064a592882c1d413b42aa5fc5d13c113ada16a983d554a579efa5e882f2ed23a9d25428fd99d
data/.gitignore CHANGED
@@ -48,5 +48,6 @@ pkg
48
48
  # For rubinius:
49
49
  #*.rbc
50
50
  .rvmrc
51
+ .ruby-version
51
52
 
52
53
  Gemfile.lock
data/.travis.yml CHANGED
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
3
  - 1.9.3
6
4
  - 2.0.0
5
+ - jruby-19mode
7
6
  - ruby-head
7
+ - jruby-head
8
8
  notifications:
9
9
  email:
10
10
  - agresso@gmail.com
@@ -14,3 +14,4 @@ branches:
14
14
  matrix:
15
15
  allow_failures:
16
16
  - rvm: ruby-head
17
+ - rvm: jruby-head
data/js-routes.gemspec CHANGED
@@ -23,14 +23,15 @@ Gem::Specification.new do |s|
23
23
  s.summary = %q{Brings Rails named routes to javascript}
24
24
 
25
25
  s.add_runtime_dependency(%q<rails>, [">= 3.2"])
26
- s.add_development_dependency(%q<therubyracer>, [">= 0"])
27
26
  s.add_development_dependency(%q<rspec>, ["~> 2.10.0"])
28
27
  s.add_development_dependency(%q<bundler>, [">= 1.1.0"])
29
28
  s.add_development_dependency(%q<guard>, [">= 0"])
30
- s.add_development_dependency(%q<rb-fsevent>, [">= 0"])
31
29
  s.add_development_dependency(%q<guard-coffeescript>, [">= 0"])
32
- if RUBY_VERSION >= "1.9"
30
+ if defined?(JRUBY_VERSION)
31
+ s.add_development_dependency(%q<therubyrhino>, [">= 0"])
32
+ else
33
33
  s.add_development_dependency(%q<debugger>, [">= 0"])
34
+ s.add_development_dependency(%q<therubyracer>, [">= 0"])
34
35
  end
35
36
  end
36
37
 
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
data/lib/routes.js CHANGED
@@ -18,7 +18,6 @@
18
18
  Utils = {
19
19
  serialize: function(object, prefix) {
20
20
  var element, i, key, prop, result, s, _i, _len;
21
-
22
21
  if (prefix == null) {
23
22
  prefix = null;
24
23
  }
@@ -65,7 +64,6 @@
65
64
  },
66
65
  clean_path: function(path) {
67
66
  var last_index;
68
-
69
67
  path = path.split("://");
70
68
  last_index = path.length - 1;
71
69
  path[last_index] = path[last_index].replace(/\/+/g, "/").replace(/.\/$/m, "");
@@ -73,7 +71,6 @@
73
71
  },
74
72
  set_default_url_options: function(optional_parts, options) {
75
73
  var i, part, _i, _len, _results;
76
-
77
74
  _results = [];
78
75
  for (i = _i = 0, _len = optional_parts.length; _i < _len; i = ++_i) {
79
76
  part = optional_parts[i];
@@ -87,7 +84,6 @@
87
84
  },
88
85
  extract_anchor: function(options) {
89
86
  var anchor;
90
-
91
87
  anchor = "";
92
88
  if (options.hasOwnProperty("anchor")) {
93
89
  anchor = "#" + options.anchor;
@@ -97,7 +93,6 @@
97
93
  },
98
94
  extract_options: function(number_of_params, args) {
99
95
  var ret_value;
100
-
101
96
  ret_value = {};
102
97
  if (args.length > number_of_params) {
103
98
  ret_value = args.pop();
@@ -106,7 +101,6 @@
106
101
  },
107
102
  path_identifier: function(object) {
108
103
  var property;
109
-
110
104
  if (object === 0) {
111
105
  return "0";
112
106
  }
@@ -124,7 +118,6 @@
124
118
  },
125
119
  clone: function(obj) {
126
120
  var attr, copy, key;
127
-
128
121
  if ((obj == null) || "object" !== this.get_object_type(obj)) {
129
122
  return obj;
130
123
  }
@@ -138,7 +131,6 @@
138
131
  },
139
132
  prepare_parameters: function(required_parameters, actual_parameters, options) {
140
133
  var i, result, val, _i, _len;
141
-
142
134
  result = this.clone(options) || {};
143
135
  for (i = _i = 0, _len = required_parameters.length; _i < _len; i = ++_i) {
144
136
  val = required_parameters[i];
@@ -148,7 +140,6 @@
148
140
  },
149
141
  build_path: function(required_parameters, optional_parts, route, args) {
150
142
  var anchor, opts, parameters, result, url, url_params;
151
-
152
143
  args = Array.prototype.slice.call(args);
153
144
  opts = this.extract_options(required_parameters.length, args);
154
145
  if (args.length > required_parameters.length) {
@@ -167,7 +158,6 @@
167
158
  },
168
159
  visit: function(route, parameters, optional) {
169
160
  var left, left_part, right, right_part, type, value;
170
-
171
161
  if (optional == null) {
172
162
  optional = false;
173
163
  }
@@ -206,8 +196,10 @@
206
196
  },
207
197
  visit_globbing: function(route, parameters, optional) {
208
198
  var left, right, type, value;
209
-
210
199
  type = route[0], left = route[1], right = route[2];
200
+ if (left.replace(/^\*/i, "") !== left) {
201
+ route[1] = left = left.replace(/^\*/i, "");
202
+ }
211
203
  value = parameters[left];
212
204
  if (value == null) {
213
205
  return this.visit(route, parameters, optional);
@@ -224,7 +216,6 @@
224
216
  },
225
217
  get_prefix: function() {
226
218
  var prefix;
227
-
228
219
  prefix = defaults.prefix;
229
220
  if (prefix !== "") {
230
221
  prefix = (prefix.match("/$") ? prefix : "" + prefix + "/");
@@ -234,7 +225,6 @@
234
225
  _classToTypeCache: null,
235
226
  _classToType: function() {
236
227
  var name, _i, _len, _ref;
237
-
238
228
  if (this._classToTypeCache != null) {
239
229
  return this._classToTypeCache;
240
230
  }
@@ -248,7 +238,6 @@
248
238
  },
249
239
  get_object_type: function(obj) {
250
240
  var strType;
251
-
252
241
  if (window.jQuery && (window.jQuery.type != null)) {
253
242
  return window.jQuery.type(obj);
254
243
  }
@@ -257,7 +246,6 @@
257
246
  },
258
247
  namespace: function(root, namespaceString) {
259
248
  var current, parts;
260
-
261
249
  parts = (namespaceString ? namespaceString.split(".") : []);
262
250
  if (!parts.length) {
263
251
  return;
data/lib/routes.js.coffee CHANGED
@@ -141,6 +141,8 @@ Utils =
141
141
  #
142
142
  visit_globbing: (route, parameters, optional) ->
143
143
  [type, left, right] = route
144
+ # fix for rails 4 globbing
145
+ route[1] = left = left.replace(/^\*/i, "") if left.replace(/^\*/i, "") isnt left
144
146
  value = parameters[left]
145
147
  return @visit(route, parameters, optional) unless value?
146
148
  parameters[left] = switch @get_object_type(value)
@@ -15,7 +15,7 @@ describe JsRoutes do
15
15
  it "should have correct function with arguments signature" do
16
16
  should include("inbox_message_path: function(_inbox_id, _id, options)")
17
17
  end
18
- it "should have correct function signature with Ruby 1.8.7 and unordered hash" do
18
+ it "should have correct function signature with unordered hash" do
19
19
  should include("inbox_message_attachment_path: function(_inbox_id, _message_id, _id, options)")
20
20
  end
21
21
 
@@ -40,7 +40,7 @@ describe JsRoutes, "compatibility with Rails" do
40
40
  end
41
41
 
42
42
  it "should support nested get parameters" do
43
- evaljs("Routes.inbox_path(1, {format: 'json', env: 'test', search: { category_ids: [2,5], q: 'hello'}})").should ==
43
+ evaljs("Routes.inbox_path(1, {format: 'json', env: 'test', search: { category_ids: [2,5], q: 'hello'}})").should ==
44
44
  routes.inbox_path(1, :env => 'test', :search => {:category_ids => [2,5], :q => "hello"}, :format => "json")
45
45
  end
46
46
 
@@ -181,18 +181,18 @@ describe JsRoutes, "compatibility with Rails" do
181
181
  it "should throw Exception if not enough parameters" do
182
182
  lambda {
183
183
  evaljs("Routes.inbox_path()")
184
- }.should raise_error(V8::JSError)
184
+ }.should raise_error(js_error_class)
185
185
  end
186
186
  it "should throw Exception if required parameter is not defined" do
187
187
  lambda {
188
188
  evaljs("Routes.inbox_path(null)")
189
- }.should raise_error(V8::JSError)
189
+ }.should raise_error(js_error_class)
190
190
  end
191
191
 
192
192
  it "should throw Exceptions if when there is too many parameters" do
193
193
  lambda {
194
194
  evaljs("Routes.inbox_path(1,2)")
195
- }.should raise_error(V8::JSError)
195
+ }.should raise_error(js_error_class)
196
196
  end
197
197
  end
198
198
 
data/spec/spec_helper.rb CHANGED
@@ -5,13 +5,22 @@ $:.unshift(File.dirname(__FILE__))
5
5
  require 'rspec'
6
6
  require 'rails/all'
7
7
  require 'js-routes'
8
- require "v8"
9
- require "cgi"
10
8
  require "active_support/core_ext/hash/slice"
11
9
  require 'coffee-script'
10
+ if defined?(JRUBY_VERSION)
11
+ require 'rhino'
12
+ JS_LIB_CLASS = Rhino
13
+ else
14
+ require "v8"
15
+ JS_LIB_CLASS = V8
16
+ end
12
17
 
13
18
  def jscontext
14
- @context ||= V8::Context.new
19
+ @context ||= JS_LIB_CLASS::Context.new
20
+ end
21
+
22
+ def js_error_class
23
+ JS_LIB_CLASS::JSError
15
24
  end
16
25
 
17
26
  def evaljs(string)
@@ -38,6 +47,8 @@ end
38
47
  class App < Rails::Application
39
48
  # Enable the asset pipeline
40
49
  config.assets.enabled = true
50
+ # initialize_on_precompile
51
+ config.assets.initialize_on_precompile = true
41
52
  end
42
53
 
43
54
  def draw_routes
@@ -52,7 +63,7 @@ def draw_routes
52
63
  end
53
64
  end
54
65
 
55
- root :to => "inboxes#index"
66
+ root :to => "inboxes#index"
56
67
 
57
68
  namespace :admin do
58
69
  resources :users
@@ -94,9 +105,6 @@ RSpec.configure do |config|
94
105
 
95
106
  config.before(:each) do
96
107
  evaljs("var window = this;")
97
- # No need to replace native V8 functions for now
98
- #jscontext[:cgi] = CGI
99
- #evaljs("function encodeURIComponent(string) {return cgi.escape(string);}")
100
108
  jscontext[:log] = lambda {|context, value| puts value.inspect}
101
109
  end
102
110
  config.before(:all) do
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js-routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
5
- prerelease:
4
+ version: 0.9.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Bogdan Gusiev
@@ -14,39 +13,20 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.2'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '3.2'
30
- - !ruby/object:Gem::Dependency
31
- name: therubyracer
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
27
  - !ruby/object:Gem::Dependency
47
28
  name: rspec
48
29
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
30
  requirements:
51
31
  - - ~>
52
32
  - !ruby/object:Gem::Version
@@ -54,7 +34,6 @@ dependencies:
54
34
  type: :development
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
37
  requirements:
59
38
  - - ~>
60
39
  - !ruby/object:Gem::Version
@@ -62,81 +41,71 @@ dependencies:
62
41
  - !ruby/object:Gem::Dependency
63
42
  name: bundler
64
43
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
44
  requirements:
67
- - - ! '>='
45
+ - - '>='
68
46
  - !ruby/object:Gem::Version
69
47
  version: 1.1.0
70
48
  type: :development
71
49
  prerelease: false
72
50
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
51
  requirements:
75
- - - ! '>='
52
+ - - '>='
76
53
  - !ruby/object:Gem::Version
77
54
  version: 1.1.0
78
55
  - !ruby/object:Gem::Dependency
79
56
  name: guard
80
57
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
58
  requirements:
83
- - - ! '>='
59
+ - - '>='
84
60
  - !ruby/object:Gem::Version
85
61
  version: '0'
86
62
  type: :development
87
63
  prerelease: false
88
64
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
65
  requirements:
91
- - - ! '>='
66
+ - - '>='
92
67
  - !ruby/object:Gem::Version
93
68
  version: '0'
94
69
  - !ruby/object:Gem::Dependency
95
- name: rb-fsevent
70
+ name: guard-coffeescript
96
71
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
72
  requirements:
99
- - - ! '>='
73
+ - - '>='
100
74
  - !ruby/object:Gem::Version
101
75
  version: '0'
102
76
  type: :development
103
77
  prerelease: false
104
78
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
79
  requirements:
107
- - - ! '>='
80
+ - - '>='
108
81
  - !ruby/object:Gem::Version
109
82
  version: '0'
110
83
  - !ruby/object:Gem::Dependency
111
- name: guard-coffeescript
84
+ name: debugger
112
85
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
86
  requirements:
115
- - - ! '>='
87
+ - - '>='
116
88
  - !ruby/object:Gem::Version
117
89
  version: '0'
118
90
  type: :development
119
91
  prerelease: false
120
92
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
93
  requirements:
123
- - - ! '>='
94
+ - - '>='
124
95
  - !ruby/object:Gem::Version
125
96
  version: '0'
126
97
  - !ruby/object:Gem::Dependency
127
- name: debugger
98
+ name: therubyracer
128
99
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
100
  requirements:
131
- - - ! '>='
101
+ - - '>='
132
102
  - !ruby/object:Gem::Version
133
103
  version: '0'
134
104
  type: :development
135
105
  prerelease: false
136
106
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
107
  requirements:
139
- - - ! '>='
108
+ - - '>='
140
109
  - !ruby/object:Gem::Version
141
110
  version: '0'
142
111
  description: Generates javascript file that defines all Rails named routes as javascript
@@ -173,29 +142,25 @@ files:
173
142
  homepage: http://github.com/railsware/js-routes
174
143
  licenses:
175
144
  - MIT
145
+ metadata: {}
176
146
  post_install_message:
177
147
  rdoc_options: []
178
148
  require_paths:
179
149
  - lib
180
150
  required_ruby_version: !ruby/object:Gem::Requirement
181
- none: false
182
151
  requirements:
183
- - - ! '>='
152
+ - - '>='
184
153
  - !ruby/object:Gem::Version
185
154
  version: '0'
186
- segments:
187
- - 0
188
- hash: 3484352808511578031
189
155
  required_rubygems_version: !ruby/object:Gem::Requirement
190
- none: false
191
156
  requirements:
192
- - - ! '>='
157
+ - - '>='
193
158
  - !ruby/object:Gem::Version
194
159
  version: '0'
195
160
  requirements: []
196
161
  rubyforge_project:
197
- rubygems_version: 1.8.25
162
+ rubygems_version: 2.0.0
198
163
  signing_key:
199
- specification_version: 3
164
+ specification_version: 4
200
165
  summary: Brings Rails named routes to javascript
201
166
  test_files: []