webpacker-routes 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/lib/webpacker/routes.rb +27 -15
- data/lib/webpacker/routes/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5194266884b788ff6ffd76ecf6408d7196fc8e4769381c6a63ef19ad49a30571
|
4
|
+
data.tar.gz: 3fc7761af1ec667dd6f9cb742dd5131439bd42e36e801bc1f21f4d1bfd44e7b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df569079481a998bec69b845602ee4f9ec35d6589fab7a91248608c9bcfeaa53a37ad2f25b35061b4be65ee427a6d188f98c5691526fa26deeca9d285c31d0d5
|
7
|
+
data.tar.gz: acd55b6c961fa9372b311d96ff6ea9494213f8dbd83d1963f73b8b0b5b16d2f5a1134467ef4f5d3d4459de648e750219f76a7be4faa3950c41ccd916fb53c9bf
|
data/README.md
CHANGED
data/lib/webpacker/routes.rb
CHANGED
@@ -10,27 +10,39 @@ module Webpacker
|
|
10
10
|
|
11
11
|
module Routes
|
12
12
|
JAVASCRIPT_VARIABLE_NAME_REGEX = /\A[_$a-z][_$a-z0-9]*\z/i
|
13
|
+
IGNORED_OPTIONS = %i[controller action]
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
JAVASCRIPT
|
19
|
-
|
20
|
-
route_set.named_routes.sort_by(&:first).each do |name, route|
|
21
|
-
raise `Invalid route name for javascript: ${name}` unless JAVASCRIPT_VARIABLE_NAME_REGEX =~ name
|
22
|
-
|
23
|
-
spec = route.path.spec.to_s.to_json
|
24
|
-
segment_keys = route.segment_keys.uniq.to_json
|
25
|
-
defaults = route.defaults.except(:controller, :action).to_json
|
15
|
+
class << self
|
16
|
+
def generate(route_set)
|
17
|
+
File.atomic_write(Webpacker.config.routes_path.join('index.js')) do |file|
|
18
|
+
default_url_options = js(route_set.default_url_options.except(*IGNORED_OPTIONS))
|
26
19
|
|
27
20
|
file.write(<<-JAVASCRIPT.strip_heredoc)
|
28
|
-
|
29
|
-
|
30
|
-
export const #{name}_path = (...args) => pathFor(#{name}_spec, ...args)
|
21
|
+
import { urlFor, pathFor } from 'webpacker-routes'
|
22
|
+
const default_url_options = #{default_url_options}
|
31
23
|
JAVASCRIPT
|
24
|
+
|
25
|
+
route_set.named_routes.sort_by(&:first).each do |name, route|
|
26
|
+
raise `Invalid route name for javascript: ${name}` unless JAVASCRIPT_VARIABLE_NAME_REGEX =~ name
|
27
|
+
|
28
|
+
spec = js(route.path.spec.to_s)
|
29
|
+
segment_keys = js(route.segment_keys.uniq)
|
30
|
+
options = js(route.defaults.except(*IGNORED_OPTIONS))
|
31
|
+
|
32
|
+
file.write(<<-JAVASCRIPT.strip_heredoc)
|
33
|
+
const #{name}_spec = [#{spec}, #{segment_keys}, { ...default_url_options, ...#{options} }]
|
34
|
+
export const #{name}_url = (...args) => urlFor(#{name}_spec, ...args)
|
35
|
+
export const #{name}_path = (...args) => pathFor(#{name}_spec, ...args)
|
36
|
+
JAVASCRIPT
|
37
|
+
end
|
32
38
|
end
|
33
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def js(obj)
|
44
|
+
ERB::Util.json_escape(obj.to_json)
|
45
|
+
end
|
34
46
|
end
|
35
47
|
end
|
36
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webpacker-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Harsha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|