js-routes-zigexn 1.3.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 +7 -0
- data/.document +5 -0
- data/.gitignore +60 -0
- data/.rspec +1 -0
- data/.travis.yml +60 -0
- data/Appraisals +16 -0
- data/CHANGELOG.md +112 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/Rakefile +33 -0
- data/Readme.md +234 -0
- data/app/assets/javascripts/js-routes.js.erb +2 -0
- data/gemfiles/rails32.gemfile +8 -0
- data/gemfiles/rails40.gemfile +8 -0
- data/gemfiles/rails40_sprockets3.gemfile +8 -0
- data/gemfiles/rails41.gemfile +8 -0
- data/gemfiles/rails41_sprockets3.gemfile +8 -0
- data/gemfiles/rails42.gemfile +8 -0
- data/gemfiles/rails42_sprockets3.gemfile +8 -0
- data/gemfiles/rails50.gemfile +8 -0
- data/gemfiles/rails50_sprockets3.gemfile +8 -0
- data/js-routes-zigexn.gemspec +36 -0
- data/lib/js-routes.rb +1 -0
- data/lib/js_routes/engine.rb +73 -0
- data/lib/js_routes/version.rb +3 -0
- data/lib/js_routes.rb +293 -0
- data/lib/routes.js +470 -0
- data/lib/routes.js.coffee +368 -0
- data/lib/tasks/js_routes.rake +8 -0
- data/spec/dummy/app/assets/javascripts/.gitkeep +0 -0
- data/spec/dummy/config/routes.rb +55 -0
- data/spec/js_routes/amd_compatibility_spec.rb +42 -0
- data/spec/js_routes/default_serializer_spec.rb +15 -0
- data/spec/js_routes/generated_javascript_spec.rb +83 -0
- data/spec/js_routes/options_spec.rb +450 -0
- data/spec/js_routes/rails_routes_compatibility_spec.rb +414 -0
- data/spec/js_routes/zzz_last_post_rails_init_spec.rb +135 -0
- data/spec/spec_helper.rb +121 -0
- data/spec/support/routes.rb +76 -0
- metadata +209 -0
@@ -0,0 +1,368 @@
|
|
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
|
+
defaults =
|
11
|
+
prefix: PREFIX
|
12
|
+
default_url_options: DEFAULT_URL_OPTIONS
|
13
|
+
|
14
|
+
NodeTypes = NODE_TYPES
|
15
|
+
SpecialOptionsKey = SPECIAL_OPTIONS_KEY
|
16
|
+
DeprecatedBehavior = DEPRECATED_BEHAVIOR
|
17
|
+
|
18
|
+
ReservedOptions = [
|
19
|
+
'anchor'
|
20
|
+
'trailing_slash'
|
21
|
+
'host'
|
22
|
+
'port'
|
23
|
+
'protocol'
|
24
|
+
]
|
25
|
+
|
26
|
+
Utils =
|
27
|
+
|
28
|
+
default_serializer: (object, prefix = null) ->
|
29
|
+
return "" unless object?
|
30
|
+
if !prefix and !(@get_object_type(object) is "object")
|
31
|
+
throw new Error("Url parameters should be a javascript hash")
|
32
|
+
|
33
|
+
s = []
|
34
|
+
switch @get_object_type(object)
|
35
|
+
when "array"
|
36
|
+
for element, i in object
|
37
|
+
s.push @default_serializer(element, prefix + "[]")
|
38
|
+
when "object"
|
39
|
+
for own key, prop of object
|
40
|
+
if !prop? and prefix?
|
41
|
+
prop = ""
|
42
|
+
|
43
|
+
if prop?
|
44
|
+
key = "#{prefix}[#{key}]" if prefix?
|
45
|
+
s.push @default_serializer(prop, key)
|
46
|
+
else
|
47
|
+
if object?
|
48
|
+
s.push "#{encodeURIComponent(prefix.toString())}=#{encodeURIComponent(object.toString())}"
|
49
|
+
|
50
|
+
return "" unless s.length
|
51
|
+
s.join("&")
|
52
|
+
|
53
|
+
custom_serializer: SERIALIZER
|
54
|
+
serialize: (object) ->
|
55
|
+
if @custom_serializer? and @get_object_type(@custom_serializer) is "function"
|
56
|
+
@custom_serializer(object)
|
57
|
+
else
|
58
|
+
@default_serializer(object)
|
59
|
+
|
60
|
+
clean_path: (path) ->
|
61
|
+
path = path.split("://")
|
62
|
+
last_index = path.length - 1
|
63
|
+
path[last_index] = path[last_index].replace(/\/+/g, "/")
|
64
|
+
path.join "://"
|
65
|
+
|
66
|
+
extract_options: (number_of_params, args) ->
|
67
|
+
last_el = args[args.length - 1]
|
68
|
+
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))
|
69
|
+
options = args.pop() || {}
|
70
|
+
delete options[SpecialOptionsKey]
|
71
|
+
options
|
72
|
+
else
|
73
|
+
{}
|
74
|
+
|
75
|
+
looks_like_serialized_model: (object) ->
|
76
|
+
!object[SpecialOptionsKey] and ("id" of object or "to_param" of object)
|
77
|
+
|
78
|
+
|
79
|
+
path_identifier: (object) ->
|
80
|
+
return "0" if object is 0
|
81
|
+
# null, undefined, false or ''
|
82
|
+
return "" unless object
|
83
|
+
property = object
|
84
|
+
if @get_object_type(object) is "object"
|
85
|
+
if "to_param" of object
|
86
|
+
throw new ParameterMissing("Route parameter missing: to_param") unless object.to_param?
|
87
|
+
property = object.to_param
|
88
|
+
else if "id" of object
|
89
|
+
throw new ParameterMissing("Route parameter missing: id") unless object.id?
|
90
|
+
property = object.id
|
91
|
+
else
|
92
|
+
property = object
|
93
|
+
|
94
|
+
property = property.call(object) if @get_object_type(property) is "function"
|
95
|
+
property.toString()
|
96
|
+
|
97
|
+
clone: (obj) ->
|
98
|
+
return obj if !obj? or "object" isnt @get_object_type(obj)
|
99
|
+
copy = obj.constructor()
|
100
|
+
copy[key] = attr for own key, attr of obj
|
101
|
+
copy
|
102
|
+
|
103
|
+
merge: (xs...) ->
|
104
|
+
tap = (o, fn) -> fn(o); o
|
105
|
+
if xs?.length > 0
|
106
|
+
tap {}, (m) -> m[k] = v for k, v of x for x in xs
|
107
|
+
|
108
|
+
normalize_options: (parts, required_parts, default_options, actual_parameters) ->
|
109
|
+
options = @extract_options(parts.length, actual_parameters)
|
110
|
+
|
111
|
+
if actual_parameters.length > parts.length
|
112
|
+
throw new Error("Too many parameters provided for path")
|
113
|
+
|
114
|
+
use_all_parts = DeprecatedBehavior or actual_parameters.length > required_parts.length
|
115
|
+
parts_options = {}
|
116
|
+
|
117
|
+
for own key of options
|
118
|
+
use_all_parts = true
|
119
|
+
if @indexOf(parts, key) >= 0
|
120
|
+
parts_options[key] = value
|
121
|
+
|
122
|
+
options = @merge(defaults.default_url_options, default_options, options)
|
123
|
+
result = {}
|
124
|
+
url_parameters = {}
|
125
|
+
result['url_parameters'] = url_parameters
|
126
|
+
for own key, value of options
|
127
|
+
if @indexOf(ReservedOptions, key) >= 0
|
128
|
+
result[key] = value
|
129
|
+
else
|
130
|
+
url_parameters[key] = value
|
131
|
+
|
132
|
+
route_parts = if use_all_parts then parts else required_parts
|
133
|
+
i = 0
|
134
|
+
for part in route_parts when i < actual_parameters.length
|
135
|
+
unless parts_options.hasOwnProperty(part)
|
136
|
+
url_parameters[part] = actual_parameters[i]
|
137
|
+
++i
|
138
|
+
|
139
|
+
result
|
140
|
+
|
141
|
+
build_route: (parts, required_parts, default_options, route, full_url, args) ->
|
142
|
+
args = Array::slice.call(args)
|
143
|
+
|
144
|
+
options = @normalize_options(parts, required_parts, default_options, args)
|
145
|
+
parameters = options['url_parameters']
|
146
|
+
|
147
|
+
# path
|
148
|
+
result = "#{@get_prefix()}#{@visit(route, parameters)}"
|
149
|
+
url = Utils.clean_path(result)
|
150
|
+
# set trailing_slash
|
151
|
+
url = url.replace(/(.*?)[\/]?$/, "$1/") if options['trailing_slash'] is true
|
152
|
+
# set additional url params
|
153
|
+
if (url_params = @serialize(parameters)).length
|
154
|
+
url += "?#{url_params}"
|
155
|
+
# set anchor
|
156
|
+
url += if options.anchor then "##{options.anchor}" else ""
|
157
|
+
if full_url
|
158
|
+
url = @route_url(options) + url
|
159
|
+
url
|
160
|
+
|
161
|
+
#
|
162
|
+
# This function is JavaScript impelementation of the
|
163
|
+
# Journey::Visitors::Formatter that builds route by given parameters
|
164
|
+
# from route binary tree.
|
165
|
+
# Binary tree is serialized in the following way:
|
166
|
+
# [node type, left node, right node ]
|
167
|
+
#
|
168
|
+
# @param {Boolean} optional Marks the currently visited branch as optional.
|
169
|
+
# If set to `true`, this method will not throw when encountering
|
170
|
+
# a missing parameter (used in recursive calls).
|
171
|
+
#
|
172
|
+
visit: (route, parameters, optional = false) ->
|
173
|
+
[type, left, right] = route
|
174
|
+
switch type
|
175
|
+
when NodeTypes.GROUP
|
176
|
+
@visit left, parameters, true
|
177
|
+
when NodeTypes.STAR
|
178
|
+
@visit_globbing left, parameters, true
|
179
|
+
when NodeTypes.LITERAL, NodeTypes.SLASH, NodeTypes.DOT
|
180
|
+
left
|
181
|
+
when NodeTypes.CAT
|
182
|
+
left_part = @visit(left, parameters, optional)
|
183
|
+
right_part = @visit(right, parameters, optional)
|
184
|
+
if optional and ((@is_optional_node(left[0]) and not left_part) or
|
185
|
+
((@is_optional_node(right[0])) and not right_part))
|
186
|
+
return ""
|
187
|
+
"#{left_part}#{right_part}"
|
188
|
+
when NodeTypes.SYMBOL
|
189
|
+
value = parameters[left]
|
190
|
+
if value?
|
191
|
+
delete parameters[left]
|
192
|
+
return @path_identifier(value)
|
193
|
+
if optional
|
194
|
+
"" # missing parameter
|
195
|
+
else
|
196
|
+
throw new ParameterMissing("Route parameter missing: #{left}")
|
197
|
+
#
|
198
|
+
# I don't know what is this node type
|
199
|
+
# Please send your PR if you do
|
200
|
+
#
|
201
|
+
# when NodeTypes.OR:
|
202
|
+
else
|
203
|
+
throw new Error("Unknown Rails node type")
|
204
|
+
|
205
|
+
|
206
|
+
is_optional_node: (node) -> @indexOf([NodeTypes.STAR, NodeTypes.SYMBOL, NodeTypes.CAT], node) >= 0
|
207
|
+
|
208
|
+
#
|
209
|
+
# This method build spec for route
|
210
|
+
#
|
211
|
+
build_path_spec: (route, wildcard=false) ->
|
212
|
+
[type, left, right] = route
|
213
|
+
switch type
|
214
|
+
when NodeTypes.GROUP
|
215
|
+
"(#{@build_path_spec(left)})"
|
216
|
+
when NodeTypes.CAT
|
217
|
+
"#{@build_path_spec(left)}#{@build_path_spec(right)}"
|
218
|
+
when NodeTypes.STAR
|
219
|
+
@build_path_spec(left, true)
|
220
|
+
when NodeTypes.SYMBOL
|
221
|
+
if wildcard is true
|
222
|
+
"#{if left[0] is '*' then '' else '*'}#{left}"
|
223
|
+
else
|
224
|
+
":#{left}"
|
225
|
+
when NodeTypes.SLASH, NodeTypes.DOT, NodeTypes.LITERAL
|
226
|
+
left
|
227
|
+
# Not sure about this one
|
228
|
+
# when NodeTypes.OR
|
229
|
+
else throw new Error("Unknown Rails node type")
|
230
|
+
|
231
|
+
#
|
232
|
+
# This method convert value for globbing in right value for rails route
|
233
|
+
#
|
234
|
+
visit_globbing: (route, parameters, optional) ->
|
235
|
+
[type, left, right] = route
|
236
|
+
# fix for rails 4 globbing
|
237
|
+
route[1] = left = left.replace(/^\*/i, "") if left.replace(/^\*/i, "") isnt left
|
238
|
+
value = parameters[left]
|
239
|
+
return @visit(route, parameters, optional) unless value?
|
240
|
+
parameters[left] = switch @get_object_type(value)
|
241
|
+
when "array"
|
242
|
+
value.join("/")
|
243
|
+
else
|
244
|
+
value
|
245
|
+
@visit route, parameters, optional
|
246
|
+
|
247
|
+
#
|
248
|
+
# This method check and return prefix from options
|
249
|
+
#
|
250
|
+
get_prefix: ->
|
251
|
+
prefix = defaults.prefix
|
252
|
+
prefix = (if prefix.match("/$") then prefix else "#{prefix}/") if prefix isnt ""
|
253
|
+
prefix
|
254
|
+
|
255
|
+
#
|
256
|
+
# route function: create route path function and add spec to it
|
257
|
+
#
|
258
|
+
route: (parts_table, default_options, route_spec, full_url) ->
|
259
|
+
required_parts = []
|
260
|
+
parts = []
|
261
|
+
for [part, required] in parts_table
|
262
|
+
parts.push(part)
|
263
|
+
required_parts.push(part) if required
|
264
|
+
|
265
|
+
path_fn = -> Utils.build_route(
|
266
|
+
parts, required_parts, default_options, route_spec, full_url, arguments
|
267
|
+
)
|
268
|
+
path_fn.required_params = required_parts
|
269
|
+
path_fn.toString = -> Utils.build_path_spec(route_spec)
|
270
|
+
path_fn
|
271
|
+
|
272
|
+
|
273
|
+
route_url: (route_defaults) ->
|
274
|
+
return route_defaults if typeof route_defaults == 'string'
|
275
|
+
protocol = route_defaults.protocol || Utils.current_protocol()
|
276
|
+
hostname = route_defaults.host || window.location.hostname
|
277
|
+
port = route_defaults.port || (Utils.current_port() unless route_defaults.host)
|
278
|
+
port = if port then ":#{port}" else ''
|
279
|
+
|
280
|
+
protocol + "://" + hostname + port
|
281
|
+
|
282
|
+
|
283
|
+
has_location: ->
|
284
|
+
typeof window != 'undefined' && typeof window.location != 'undefined'
|
285
|
+
|
286
|
+
current_host: ->
|
287
|
+
if @has_location() then window.location.hostname else null
|
288
|
+
|
289
|
+
current_protocol: () ->
|
290
|
+
if @has_location() && window.location.protocol != ''
|
291
|
+
# location.protocol includes the colon character
|
292
|
+
window.location.protocol.replace(/:$/, '')
|
293
|
+
else
|
294
|
+
'http'
|
295
|
+
|
296
|
+
current_port: () ->
|
297
|
+
if @has_location() && window.location.port != ''
|
298
|
+
window.location.port
|
299
|
+
else
|
300
|
+
''
|
301
|
+
|
302
|
+
#
|
303
|
+
# This is helper method to define object type.
|
304
|
+
# The typeof operator is probably the biggest design flaw of JavaScript, simply because it's basically completely broken.
|
305
|
+
#
|
306
|
+
# Value Class Type
|
307
|
+
# -------------------------------------
|
308
|
+
# "foo" String string
|
309
|
+
# new String("foo") String object
|
310
|
+
# 1.2 Number number
|
311
|
+
# new Number(1.2) Number object
|
312
|
+
# true Boolean boolean
|
313
|
+
# new Boolean(true) Boolean object
|
314
|
+
# new Date() Date object
|
315
|
+
# new Error() Error object
|
316
|
+
# [1,2,3] Array object
|
317
|
+
# new Array(1, 2, 3) Array object
|
318
|
+
# new Function("") Function function
|
319
|
+
# /abc/g RegExp object
|
320
|
+
# new RegExp("meow") RegExp object
|
321
|
+
# {} Object object
|
322
|
+
# new Object() Object object
|
323
|
+
#
|
324
|
+
# What is why I use Object.prototype.toString() to know better type of variable. Or use jQuery.type, if it available.
|
325
|
+
# _classToTypeCache used for perfomance cache of types map (underscore at the beginning mean private method - of course it doesn't realy private).
|
326
|
+
#
|
327
|
+
_classToTypeCache: null
|
328
|
+
_classToType: ->
|
329
|
+
return @_classToTypeCache if @_classToTypeCache?
|
330
|
+
@_classToTypeCache = {}
|
331
|
+
for name in "Boolean Number String Function Array Date RegExp Object Error".split(" ")
|
332
|
+
@_classToTypeCache["[object #{name}]"] = name.toLowerCase()
|
333
|
+
@_classToTypeCache
|
334
|
+
get_object_type: (obj) ->
|
335
|
+
return root.jQuery.type(obj) if root.jQuery and root.jQuery.type?
|
336
|
+
return "#{obj}" unless obj?
|
337
|
+
(if typeof obj is "object" or typeof obj is "function" then @_classToType()[Object::toString.call(obj)] or "object" else typeof obj)
|
338
|
+
|
339
|
+
# indexOf helper
|
340
|
+
indexOf: (array, element) -> if Array::indexOf then array.indexOf(element) else @indexOfImplementation(array, element)
|
341
|
+
indexOfImplementation: (array, element) ->
|
342
|
+
result = -1
|
343
|
+
(result = i for el, i in array when el is element)
|
344
|
+
result
|
345
|
+
|
346
|
+
namespace: (root, namespace, routes) ->
|
347
|
+
parts = namespace.split(".")
|
348
|
+
return routes if parts.length == 0
|
349
|
+
for part, index in parts
|
350
|
+
if index < parts.length - 1
|
351
|
+
root = (root[part] or= {})
|
352
|
+
else
|
353
|
+
return root[part] = routes
|
354
|
+
|
355
|
+
make: ->
|
356
|
+
routes = ROUTES
|
357
|
+
routes.options = defaults
|
358
|
+
routes.default_serializer = (object, prefix) ->
|
359
|
+
Utils.default_serializer(object, prefix)
|
360
|
+
Utils.namespace(root, NAMESPACE, routes)
|
361
|
+
|
362
|
+
# Set up Routes appropriately for the environment.
|
363
|
+
if typeof define is "function" and define.amd
|
364
|
+
# AMD
|
365
|
+
define [], -> Utils.make()
|
366
|
+
else
|
367
|
+
# Browser globals
|
368
|
+
Utils.make()
|
File without changes
|
@@ -0,0 +1,55 @@
|
|
1
|
+
App.routes.draw do
|
2
|
+
resource "3df1b2d050ae5a96eac8565c9daef37a"
|
3
|
+
resource "341f9e69e3db1c344de2fc6551885711"
|
4
|
+
resource "0e1bcb2dc1ce4d80ec15cae9140fb99a"
|
5
|
+
resource "15b91c612530bfc69c70d121c8713da4"
|
6
|
+
resource "49e12936168a64dce4d4ec148104fb5a"
|
7
|
+
resource "d878104611f88952aba49965c1d2d573"
|
8
|
+
resource "0e94bfc3c8aaee5ea09579fe73cbdaff"
|
9
|
+
resource "e1c2dd2ea9c63b380eb0947a0e1f49aa"
|
10
|
+
resource "587c6e26ad7f9a6aa09f81add77b16f5"
|
11
|
+
resource "8e00bfffebe0c874d6dad1c7b8c7cd6b"
|
12
|
+
resource "394482d3515e7e49989a8496afa7d367"
|
13
|
+
resource "4ab9c701622cba87eae50795564abe1c"
|
14
|
+
resource "af4b4a2ea501fefbdb8367eb108b2e14"
|
15
|
+
resource "116d17a93932a9a3e5bd2750665582f9"
|
16
|
+
resource "315f0a62063288cd56373c8a00870596"
|
17
|
+
resource "d5357ec6df4589f81ca8689cf0231667"
|
18
|
+
resource "560a3b8cf807e873843cd889400cd52b"
|
19
|
+
resource "361de6041f545e67db1aeaa6206c8ac7"
|
20
|
+
resource "28b0a54de4a0884386f1e324edc13194"
|
21
|
+
resource "ab77f21a956d956295187806cdf38cd1"
|
22
|
+
resource "0b8a362fd486247fb7c41898709b9815"
|
23
|
+
resource "5efa0a96733bc027b3309ffb54d1d1d0"
|
24
|
+
resource "70a3ee535c59fcf59c58b6d39178833c"
|
25
|
+
resource "5095fc05868c673ce450524f78cd28d3"
|
26
|
+
resource "79b994cfbc79432d644a3b83804f4924"
|
27
|
+
resource "e25125c477cd451fd74a76eaaebc9165"
|
28
|
+
resource "672fbfb432687e2fee7d0e799cc10ea4"
|
29
|
+
resource "2eb8350243305659082eb92b2e5b702c"
|
30
|
+
resource "08c9973b624e10b10dc7235659c81346"
|
31
|
+
resource "fee0d4b123529a2c652bef0ec0116ef2"
|
32
|
+
resource "8422445d2aa176b7733473164c461a2e"
|
33
|
+
resource "c24b8252b235431ca3df21a6ac119062"
|
34
|
+
resource "c08c66c7fc40e9937ff84a86f6c6d18a"
|
35
|
+
resource "964851acca72064d861188150e848d55"
|
36
|
+
resource "d02927a4fd37b37c03dbad5d3c7a4753"
|
37
|
+
resource "2a69df680ff9bd8d3855d9ce5a4e51f7"
|
38
|
+
resource "d8daed677f9a9a6926005afbdeebcf73"
|
39
|
+
resource "83d4db872f5f148e9ead108d483fec78"
|
40
|
+
resource "09f9fb4250595d26f4149b76fcfa957d"
|
41
|
+
resource "956cdb4d3cbf36bb9ccb7c7fcc36a602"
|
42
|
+
resource "02816449a6c929f55f8bad958f25d25a"
|
43
|
+
resource "2dd7ae38bd72f7e8b26aafb5f002d634"
|
44
|
+
resource "c7c9aaa3f7131f1e7dbc9325b3426d3e"
|
45
|
+
resource "7556e7d17c2a26acbad7d5fa86e6e640"
|
46
|
+
resource "d03081ef427a227a808c708282fdc86b"
|
47
|
+
resource "8f610d21e6e499c1eea98ca08191c05f"
|
48
|
+
resource "b6b412ae8a369f6bfc7f312245eacc8c"
|
49
|
+
resource "e9bcda8b00879c49bd7f05afee59a28e"
|
50
|
+
resource "6e89f4baddd4044b42be7c2d3b382567"
|
51
|
+
resource "5959c376d15a609f2e74f4f351d0a565"
|
52
|
+
resource "3b7e418511c305c78f2d2c292a3a1289"
|
53
|
+
resource "87acf6bf6e8191ff8900f420b33d5268"
|
54
|
+
resource "648a9b17078423f29f42aa2ecac1cc7d"
|
55
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe JsRoutes, "compatibility with AMD/require.js" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
evaljs("window.GlobalCheck = {};")
|
7
|
+
evaljs("window.define = function (requirs, callback) { window.GlobalCheck['js-routes'] = callback.call(this); return window.GlobalCheck['js-routes']; };")
|
8
|
+
evaljs("window.define.amd = { jQuery: true };")
|
9
|
+
strRequire =<<EOF
|
10
|
+
window.require = function (r, callback) {
|
11
|
+
var allArgs, i;
|
12
|
+
|
13
|
+
allArgs = (function() {
|
14
|
+
var _i, _len, _results;
|
15
|
+
_results = [];
|
16
|
+
for (_i = 0, _len = r.length; _i < _len; _i++) {
|
17
|
+
i = r[_i];
|
18
|
+
_results.push(window.GlobalCheck[i]);
|
19
|
+
}
|
20
|
+
return _results;
|
21
|
+
})();
|
22
|
+
|
23
|
+
return callback.apply(null, allArgs);
|
24
|
+
};
|
25
|
+
EOF
|
26
|
+
evaljs(strRequire)
|
27
|
+
evaljs(JsRoutes.generate({}))
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should working from global scope" do
|
31
|
+
expect(evaljs("Routes.inboxes_path()")).to eq(routes.inboxes_path())
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should working from define function" do
|
35
|
+
expect(evaljs("Routes.inboxes_path()")).to eq(evaljs("GlobalCheck['js-routes'].inboxes_path()"))
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should working from require" do
|
39
|
+
expect(evaljs("require(['js-routes'], function(r){ return r.inboxes_path(); })")).to eq(routes.inboxes_path())
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|