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