js-routes 1.4.1 → 2.1.0

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.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/.eslintrc.js +15 -0
  3. data/.gitignore +5 -0
  4. data/.nvmrc +1 -0
  5. data/.travis.yml +37 -30
  6. data/Appraisals +16 -13
  7. data/CHANGELOG.md +95 -0
  8. data/Rakefile +6 -2
  9. data/Readme.md +220 -88
  10. data/VERSION_2_UPGRADE.md +66 -0
  11. data/app/assets/javascripts/js-routes.js.erb +1 -1
  12. data/gemfiles/{rails40.gemfile → rails40_sprockets_2.gemfile} +1 -1
  13. data/gemfiles/{rails40_sprockets3.gemfile → rails40_sprockets_3.gemfile} +0 -0
  14. data/gemfiles/{rails41.gemfile → rails41_sprockets_2.gemfile} +1 -1
  15. data/gemfiles/{rails41_sprockets3.gemfile → rails41_sprockets_3.gemfile} +0 -0
  16. data/gemfiles/{rails32.gemfile → rails42_sprockets_2.gemfile} +2 -2
  17. data/gemfiles/{rails42_sprockets3.gemfile → rails42_sprockets_3.gemfile} +1 -1
  18. data/gemfiles/{rails50_sprockets3.gemfile → rails50_sprockets_3.gemfile} +1 -1
  19. data/gemfiles/rails51_sprockets_3.gemfile +8 -0
  20. data/gemfiles/rails52_sprockets_3.gemfile +8 -0
  21. data/js-routes.gemspec +9 -6
  22. data/lib/js_routes/engine.rb +6 -18
  23. data/lib/js_routes/version.rb +1 -1
  24. data/lib/js_routes.rb +329 -171
  25. data/lib/routes.d.ts +79 -0
  26. data/lib/routes.js +499 -485
  27. data/lib/routes.ts +732 -0
  28. data/lib/tasks/js_routes.rake +8 -2
  29. data/package.json +37 -0
  30. data/spec/dummy/app/assets/config/manifest.js +2 -0
  31. data/spec/js_routes/default_serializer_spec.rb +19 -3
  32. data/spec/js_routes/{amd_compatibility_spec.rb → module_types/amd_spec.rb} +1 -9
  33. data/spec/js_routes/module_types/cjs_spec.rb +15 -0
  34. data/spec/js_routes/module_types/dts/routes.spec.d.ts +114 -0
  35. data/spec/js_routes/module_types/dts/test.spec.ts +56 -0
  36. data/spec/js_routes/module_types/dts_spec.rb +111 -0
  37. data/spec/js_routes/module_types/esm_spec.rb +45 -0
  38. data/spec/js_routes/{generated_javascript_spec.rb → module_types/umd_spec.rb} +33 -27
  39. data/spec/js_routes/options_spec.rb +92 -50
  40. data/spec/js_routes/rails_routes_compatibility_spec.rb +107 -45
  41. data/spec/js_routes/zzz_last_post_rails_init_spec.rb +19 -8
  42. data/spec/spec_helper.rb +45 -42
  43. data/spec/support/routes.rb +19 -14
  44. data/spec/tsconfig.json +4 -0
  45. data/tsconfig.json +28 -0
  46. data/yarn.lock +2145 -0
  47. metadata +47 -34
  48. data/gemfiles/rails42.gemfile +0 -8
  49. data/gemfiles/rails50.gemfile +0 -8
  50. data/lib/routes.js.coffee +0 -386
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.4.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-05 00:00:00.000000000 Z
11
+ date: 2021-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: '4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.2'
26
+ version: '4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sprockets-rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :runtime
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 3.0.0
47
+ version: 3.10.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.0
54
+ version: 3.10.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,33 +67,33 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.1.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: coffee-script
70
+ name: appraisal
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.5.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.5.2
83
83
  - !ruby/object:Gem::Dependency
84
- name: appraisal
84
+ name: bump
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 0.5.2
89
+ version: 0.10.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 0.5.2
96
+ version: 0.10.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: byebug
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -123,19 +123,19 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: therubyracer
126
+ name: mini_racer
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 0.12.3
131
+ version: 0.4.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 0.12.3
138
+ version: 0.4.0
139
139
  description: Generates javascript file that defines all Rails named routes as javascript
140
140
  helpers
141
141
  email: agresso@gmail.com
@@ -145,7 +145,9 @@ extra_rdoc_files:
145
145
  - LICENSE.txt
146
146
  files:
147
147
  - ".document"
148
+ - ".eslintrc.js"
148
149
  - ".gitignore"
150
+ - ".nvmrc"
149
151
  - ".rspec"
150
152
  - ".travis.yml"
151
153
  - Appraisals
@@ -154,39 +156,51 @@ files:
154
156
  - LICENSE.txt
155
157
  - Rakefile
156
158
  - Readme.md
159
+ - VERSION_2_UPGRADE.md
157
160
  - app/assets/javascripts/js-routes.js.erb
158
- - gemfiles/rails32.gemfile
159
- - gemfiles/rails40.gemfile
160
- - gemfiles/rails40_sprockets3.gemfile
161
- - gemfiles/rails41.gemfile
162
- - gemfiles/rails41_sprockets3.gemfile
163
- - gemfiles/rails42.gemfile
164
- - gemfiles/rails42_sprockets3.gemfile
165
- - gemfiles/rails50.gemfile
166
- - gemfiles/rails50_sprockets3.gemfile
161
+ - gemfiles/rails40_sprockets_2.gemfile
162
+ - gemfiles/rails40_sprockets_3.gemfile
163
+ - gemfiles/rails41_sprockets_2.gemfile
164
+ - gemfiles/rails41_sprockets_3.gemfile
165
+ - gemfiles/rails42_sprockets_2.gemfile
166
+ - gemfiles/rails42_sprockets_3.gemfile
167
+ - gemfiles/rails50_sprockets_3.gemfile
168
+ - gemfiles/rails51_sprockets_3.gemfile
169
+ - gemfiles/rails52_sprockets_3.gemfile
167
170
  - js-routes.gemspec
168
171
  - lib/js-routes.rb
169
172
  - lib/js_routes.rb
170
173
  - lib/js_routes/engine.rb
171
174
  - lib/js_routes/version.rb
175
+ - lib/routes.d.ts
172
176
  - lib/routes.js
173
- - lib/routes.js.coffee
177
+ - lib/routes.ts
174
178
  - lib/tasks/js_routes.rake
179
+ - package.json
180
+ - spec/dummy/app/assets/config/manifest.js
175
181
  - spec/dummy/app/assets/javascripts/.gitkeep
176
182
  - spec/dummy/config/routes.rb
177
- - spec/js_routes/amd_compatibility_spec.rb
178
183
  - spec/js_routes/default_serializer_spec.rb
179
- - spec/js_routes/generated_javascript_spec.rb
184
+ - spec/js_routes/module_types/amd_spec.rb
185
+ - spec/js_routes/module_types/cjs_spec.rb
186
+ - spec/js_routes/module_types/dts/routes.spec.d.ts
187
+ - spec/js_routes/module_types/dts/test.spec.ts
188
+ - spec/js_routes/module_types/dts_spec.rb
189
+ - spec/js_routes/module_types/esm_spec.rb
190
+ - spec/js_routes/module_types/umd_spec.rb
180
191
  - spec/js_routes/options_spec.rb
181
192
  - spec/js_routes/rails_routes_compatibility_spec.rb
182
193
  - spec/js_routes/zzz_last_post_rails_init_spec.rb
183
194
  - spec/spec_helper.rb
184
195
  - spec/support/routes.rb
196
+ - spec/tsconfig.json
197
+ - tsconfig.json
198
+ - yarn.lock
185
199
  homepage: http://github.com/railsware/js-routes
186
200
  licenses:
187
201
  - MIT
188
202
  metadata: {}
189
- post_install_message:
203
+ post_install_message:
190
204
  rdoc_options: []
191
205
  require_paths:
192
206
  - lib
@@ -194,16 +208,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
208
  requirements:
195
209
  - - ">="
196
210
  - !ruby/object:Gem::Version
197
- version: '0'
211
+ version: 2.4.0
198
212
  required_rubygems_version: !ruby/object:Gem::Requirement
199
213
  requirements:
200
214
  - - ">="
201
215
  - !ruby/object:Gem::Version
202
216
  version: '0'
203
217
  requirements: []
204
- rubyforge_project:
205
- rubygems_version: 2.6.11
206
- signing_key:
218
+ rubygems_version: 3.2.0
219
+ signing_key:
207
220
  specification_version: 4
208
221
  summary: Brings Rails named routes to javascript
209
222
  test_files: []
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "railties", "~> 4.2.8"
6
- gem "sprockets", "< 3"
7
-
8
- gemspec :path => "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "railties", "~> 5.0.2"
6
- gem "sprockets", "< 3"
7
-
8
- gemspec :path => "../"
data/lib/routes.js.coffee DELETED
@@ -1,386 +0,0 @@
1
- ###
2
- File generated by js-routes GEM_VERSION
3
- Based on Rails routes of APP_CLASS
4
- ###
5
- # root is this
6
- root = (exports ? this)
7
-
8
- ParameterMissing = (@message) -> #
9
- ParameterMissing:: = new Error()
10
-
11
- NodeTypes = NODE_TYPES
12
- SpecialOptionsKey = SPECIAL_OPTIONS_KEY
13
- DeprecatedBehavior = DEPRECATED_BEHAVIOR
14
-
15
- ReservedOptions = [
16
- 'anchor'
17
- 'trailing_slash'
18
- 'host'
19
- 'port'
20
- 'protocol'
21
- ]
22
-
23
- Utils =
24
-
25
- configuration:
26
- prefix: PREFIX
27
- default_url_options: DEFAULT_URL_OPTIONS
28
- special_options_key: SPECIAL_OPTIONS_KEY
29
- serializer: SERIALIZER
30
-
31
-
32
- default_serializer: (object, prefix = null) ->
33
- return "" unless object?
34
- if !prefix and !(@get_object_type(object) is "object")
35
- throw new Error("Url parameters should be a javascript hash")
36
-
37
- s = []
38
- switch @get_object_type(object)
39
- when "array"
40
- for element, i in object
41
- s.push @default_serializer(element, prefix + "[]")
42
- when "object"
43
- for own key, prop of object
44
- if !prop? and prefix?
45
- prop = ""
46
-
47
- if prop?
48
- key = "#{prefix}[#{key}]" if prefix?
49
- s.push @default_serializer(prop, key)
50
- else
51
- if object?
52
- s.push "#{encodeURIComponent(prefix.toString())}=#{encodeURIComponent(object.toString())}"
53
-
54
- return "" unless s.length
55
- s.join("&")
56
-
57
- serialize: (object) ->
58
- custom_serializer = @configuration.serializer
59
- if custom_serializer? and @get_object_type(custom_serializer) is "function"
60
- custom_serializer(object)
61
- else
62
- @default_serializer(object)
63
-
64
- clean_path: (path) ->
65
- path = path.split("://")
66
- last_index = path.length - 1
67
- path[last_index] = path[last_index].replace(/\/+/g, "/")
68
- path.join "://"
69
-
70
- extract_options: (number_of_params, args) ->
71
- last_el = args[args.length - 1]
72
- if (args.length > number_of_params and last_el == undefined) or (last_el? and "object" is @get_object_type(last_el) and !@looks_like_serialized_model(last_el))
73
- options = args.pop() || {}
74
- delete options[@configuration.special_options_key]
75
- options
76
- else
77
- {}
78
-
79
- looks_like_serialized_model: (object) ->
80
- !object[@configuration.special_options_key] and ("id" of object or "to_param" of object)
81
-
82
-
83
- path_identifier: (object) ->
84
- return "0" if object is 0
85
- # null, undefined, false or ''
86
- return "" unless object
87
- property = object
88
- if @get_object_type(object) is "object"
89
- if "to_param" of object
90
- throw new ParameterMissing("Route parameter missing: to_param") unless object.to_param?
91
- property = object.to_param
92
- else if "id" of object
93
- throw new ParameterMissing("Route parameter missing: id") unless object.id?
94
- property = object.id
95
- else
96
- property = object
97
-
98
- property = property.call(object) if @get_object_type(property) is "function"
99
- property.toString()
100
-
101
- clone: (obj) ->
102
- return obj if !obj? or "object" isnt @get_object_type(obj)
103
- copy = obj.constructor()
104
- copy[key] = attr for own key, attr of obj
105
- copy
106
-
107
- merge: (xs...) ->
108
- tap = (o, fn) -> fn(o); o
109
- if xs?.length > 0
110
- tap {}, (m) -> m[k] = v for k, v of x for x in xs
111
-
112
- normalize_options: (parts, required_parts, default_options, actual_parameters) ->
113
- options = @extract_options(parts.length, actual_parameters)
114
-
115
- if actual_parameters.length > parts.length
116
- throw new Error("Too many parameters provided for path")
117
-
118
- use_all_parts = DeprecatedBehavior or actual_parameters.length > required_parts.length
119
- parts_options = {}
120
-
121
- for own key of options
122
- use_all_parts = true
123
- if @indexOf(parts, key) >= 0
124
- parts_options[key] = value
125
-
126
- options = @merge(@configuration.default_url_options, default_options, options)
127
- result = {}
128
- url_parameters = {}
129
- result['url_parameters'] = url_parameters
130
- for own key, value of options
131
- if @indexOf(ReservedOptions, key) >= 0
132
- result[key] = value
133
- else
134
- url_parameters[key] = value
135
-
136
- route_parts = if use_all_parts then parts else required_parts
137
- i = 0
138
- for part in route_parts when i < actual_parameters.length
139
- unless parts_options.hasOwnProperty(part)
140
- url_parameters[part] = actual_parameters[i]
141
- ++i
142
-
143
- result
144
-
145
- build_route: (parts, required_parts, default_options, route, full_url, args) ->
146
- args = Array::slice.call(args)
147
-
148
- options = @normalize_options(parts, required_parts, default_options, args)
149
- parameters = options['url_parameters']
150
-
151
- # path
152
- result = "#{@get_prefix()}#{@visit(route, parameters)}"
153
- url = Utils.clean_path(result)
154
- # set trailing_slash
155
- url = url.replace(/(.*?)[\/]?$/, "$1/") if options['trailing_slash'] is true
156
- # set additional url params
157
- if (url_params = @serialize(parameters)).length
158
- url += "?#{url_params}"
159
- # set anchor
160
- url += if options.anchor then "##{options.anchor}" else ""
161
- if full_url
162
- url = @route_url(options) + url
163
- url
164
-
165
- #
166
- # This function is JavaScript impelementation of the
167
- # Journey::Visitors::Formatter that builds route by given parameters
168
- # from route binary tree.
169
- # Binary tree is serialized in the following way:
170
- # [node type, left node, right node ]
171
- #
172
- # @param {Boolean} optional Marks the currently visited branch as optional.
173
- # If set to `true`, this method will not throw when encountering
174
- # a missing parameter (used in recursive calls).
175
- #
176
- visit: (route, parameters, optional = false) ->
177
- [type, left, right] = route
178
- switch type
179
- when NodeTypes.GROUP
180
- @visit left, parameters, true
181
- when NodeTypes.STAR
182
- @visit_globbing left, parameters, true
183
- when NodeTypes.LITERAL, NodeTypes.SLASH, NodeTypes.DOT
184
- left
185
- when NodeTypes.CAT
186
- left_part = @visit(left, parameters, optional)
187
- right_part = @visit(right, parameters, optional)
188
- if optional and ((@is_optional_node(left[0]) and not left_part) or
189
- ((@is_optional_node(right[0])) and not right_part))
190
- return ""
191
- "#{left_part}#{right_part}"
192
- when NodeTypes.SYMBOL
193
- value = parameters[left]
194
- if value?
195
- delete parameters[left]
196
- return @path_identifier(value)
197
- if optional
198
- "" # missing parameter
199
- else
200
- throw new ParameterMissing("Route parameter missing: #{left}")
201
- #
202
- # I don't know what is this node type
203
- # Please send your PR if you do
204
- #
205
- # when NodeTypes.OR:
206
- else
207
- throw new Error("Unknown Rails node type")
208
-
209
-
210
- is_optional_node: (node) -> @indexOf([NodeTypes.STAR, NodeTypes.SYMBOL, NodeTypes.CAT], node) >= 0
211
-
212
- #
213
- # This method build spec for route
214
- #
215
- build_path_spec: (route, wildcard=false) ->
216
- [type, left, right] = route
217
- switch type
218
- when NodeTypes.GROUP
219
- "(#{@build_path_spec(left)})"
220
- when NodeTypes.CAT
221
- "#{@build_path_spec(left)}#{@build_path_spec(right)}"
222
- when NodeTypes.STAR
223
- @build_path_spec(left, true)
224
- when NodeTypes.SYMBOL
225
- if wildcard is true
226
- "#{if left[0] is '*' then '' else '*'}#{left}"
227
- else
228
- ":#{left}"
229
- when NodeTypes.SLASH, NodeTypes.DOT, NodeTypes.LITERAL
230
- left
231
- # Not sure about this one
232
- # when NodeTypes.OR
233
- else throw new Error("Unknown Rails node type")
234
-
235
- #
236
- # This method convert value for globbing in right value for rails route
237
- #
238
- visit_globbing: (route, parameters, optional) ->
239
- [type, left, right] = route
240
- # fix for rails 4 globbing
241
- route[1] = left = left.replace(/^\*/i, "") if left.replace(/^\*/i, "") isnt left
242
- value = parameters[left]
243
- return @visit(route, parameters, optional) unless value?
244
- parameters[left] = switch @get_object_type(value)
245
- when "array"
246
- value.join("/")
247
- else
248
- value
249
- @visit route, parameters, optional
250
-
251
- #
252
- # This method check and return prefix from options
253
- #
254
- get_prefix: ->
255
- prefix = @configuration.prefix
256
- prefix = (if prefix.match("/$") then prefix else "#{prefix}/") if prefix isnt ""
257
- prefix
258
-
259
- #
260
- # route function: create route path function and add spec to it
261
- #
262
- route: (parts_table, default_options, route_spec, full_url) ->
263
- required_parts = []
264
- parts = []
265
- for [part, required] in parts_table
266
- parts.push(part)
267
- required_parts.push(part) if required
268
-
269
- path_fn = -> Utils.build_route(
270
- parts, required_parts, default_options, route_spec, full_url, arguments
271
- )
272
- path_fn.required_params = required_parts
273
- path_fn.toString = -> Utils.build_path_spec(route_spec)
274
- path_fn
275
-
276
-
277
- route_url: (route_defaults) ->
278
- return route_defaults if typeof route_defaults == 'string'
279
-
280
- hostname = route_defaults.host || Utils.current_host()
281
-
282
- return '' unless hostname
283
-
284
- protocol = route_defaults.protocol || Utils.current_protocol()
285
- port = route_defaults.port || (Utils.current_port() unless route_defaults.host)
286
- port = if port then ":#{port}" else ''
287
-
288
- protocol + "://" + hostname + port
289
-
290
- has_location: -> window?.location?
291
-
292
- current_host: ->
293
- if @has_location() then window.location.hostname else null
294
-
295
- current_protocol: () ->
296
- if @has_location() && window.location.protocol != ''
297
- # location.protocol includes the colon character
298
- window.location.protocol.replace(/:$/, '')
299
- else
300
- 'http'
301
-
302
- current_port: () ->
303
- if @has_location() && window.location.port != ''
304
- window.location.port
305
- else
306
- ''
307
-
308
- #
309
- # This is helper method to define object type.
310
- # The typeof operator is probably the biggest design flaw of JavaScript, simply because it's basically completely broken.
311
- #
312
- # Value Class Type
313
- # -------------------------------------
314
- # "foo" String string
315
- # new String("foo") String object
316
- # 1.2 Number number
317
- # new Number(1.2) Number object
318
- # true Boolean boolean
319
- # new Boolean(true) Boolean object
320
- # new Date() Date object
321
- # new Error() Error object
322
- # [1,2,3] Array object
323
- # new Array(1, 2, 3) Array object
324
- # new Function("") Function function
325
- # /abc/g RegExp object
326
- # new RegExp("meow") RegExp object
327
- # {} Object object
328
- # new Object() Object object
329
- #
330
- # What is why I use Object.prototype.toString() to know better type of variable. Or use jQuery.type, if it available.
331
- # _classToTypeCache used for perfomance cache of types map (underscore at the beginning mean private method - of course it doesn't realy private).
332
- #
333
- _classToTypeCache: null
334
- _classToType: ->
335
- return @_classToTypeCache if @_classToTypeCache?
336
- @_classToTypeCache = {}
337
- for name in "Boolean Number String Function Array Date RegExp Object Error".split(" ")
338
- @_classToTypeCache["[object #{name}]"] = name.toLowerCase()
339
- @_classToTypeCache
340
- get_object_type: (obj) ->
341
- return root.jQuery.type(obj) if root.jQuery and root.jQuery.type?
342
- return "#{obj}" unless obj?
343
- (if typeof obj is "object" or typeof obj is "function" then @_classToType()[Object::toString.call(obj)] or "object" else typeof obj)
344
-
345
- # indexOf helper
346
- indexOf: (array, element) -> if Array::indexOf then array.indexOf(element) else @indexOfImplementation(array, element)
347
- indexOfImplementation: (array, element) ->
348
- result = -1
349
- (result = i for el, i in array when el is element)
350
- result
351
-
352
- namespace: (root, namespace, routes) ->
353
- parts = namespace.split(".")
354
- return routes if parts.length == 0
355
- for part, index in parts
356
- if index < parts.length - 1
357
- root = (root[part] or= {})
358
- else
359
- return root[part] = routes
360
-
361
- configure: (new_config) ->
362
- @configuration = @merge(@configuration, new_config)
363
-
364
- config: ->
365
- @clone(@configuration)
366
-
367
- make: ->
368
- routes = ROUTES
369
- routes.configure = (config) -> Utils.configure(config)
370
- routes.config = -> Utils.config()
371
- Object.defineProperty routes, 'defaults',
372
- get: ->
373
- throw new Error("#{NAMESPACE}.defaults is removed. Use #{NAMESPACE}.configure() instead.")
374
- set: (value) ->
375
-
376
- routes.default_serializer = (object, prefix) ->
377
- Utils.default_serializer(object, prefix)
378
- Utils.namespace(root, NAMESPACE, routes)
379
-
380
- # Set up Routes appropriately for the environment.
381
- if typeof define is "function" and define.amd
382
- # AMD
383
- define [], -> Utils.make()
384
- else
385
- # Browser globals
386
- Utils.make()