js-routes 1.4.9 → 2.0.0

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