webpacker-routes 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/webpacker/routes.rb +37 -21
- data/lib/webpacker/routes/railtie.rb +3 -4
- data/lib/webpacker/routes/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0ace4cd3e92b5e779788f42c032b8227f8352cc124f72d5725ac08280125097
|
4
|
+
data.tar.gz: ca63b493a4a7f3f3115ca19a87883628cfdf864e2862b00d35c9e807af795e63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2dec026375850eda7b48f59c0ffa89e17ccb36fc7f4ea87311047416aabd7fdfbaac2f53ec47a552c0e8c39b551a0ad8859df8a7dba5f4106a2bd53f23781de
|
7
|
+
data.tar.gz: ccf44fcf0f9e8c02b1de95b392a9992e3ed6646bd08bf11301d36bda1317347b256bcab93a83a197fd094436c8b7f27da742f499304b879b1d5b6662fce4b67d
|
data/lib/webpacker/routes.rb
CHANGED
@@ -24,28 +24,38 @@ module Webpacker
|
|
24
24
|
|
25
25
|
default_url_options_var = var_name.call('default_url_options')
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
raise `Invalid route name for javascript: ${name}` unless JAVASCRIPT_VARIABLE_NAME_REGEX =~ name
|
35
|
-
|
36
|
-
spec = route.path.spec.to_s
|
37
|
-
segment_keys = route.segment_keys.uniq
|
38
|
-
options = route.defaults.except(*IGNORED_OPTIONS)
|
39
|
-
|
40
|
-
spec_var = var_name.call("#{name}_spec")
|
41
|
-
url_var = var_name.call("#{name}_url")
|
42
|
-
path_var = var_name.call("#{name}_path")
|
43
|
-
|
44
|
-
file.write(<<-JAVASCRIPT.strip_heredoc)
|
45
|
-
const #{spec_var} = [#{js(spec)}, #{js(segment_keys)}, { ...#{default_url_options_var}, ...#{js(options)} }]
|
46
|
-
export const #{url_var} = (...args) => urlFor(#{spec_var}, ...args)
|
47
|
-
export const #{path_var} = (...args) => pathFor(#{spec_var}, ...args)
|
27
|
+
js_file = Webpacker.config.routes_path.join('index.js')
|
28
|
+
|
29
|
+
catch(:identical) do
|
30
|
+
File.atomic_write(js_file) do |temp_file|
|
31
|
+
temp_file.write(<<-JAVASCRIPT.strip_heredoc)
|
32
|
+
import { urlFor, pathFor } from 'webpacker-routes'
|
33
|
+
const #{default_url_options_var} = #{js(default_url_options)}
|
48
34
|
JAVASCRIPT
|
35
|
+
|
36
|
+
app.routes.named_routes.sort_by(&:first).each do |name, route|
|
37
|
+
raise `Invalid route name for javascript: ${name}` unless JAVASCRIPT_VARIABLE_NAME_REGEX =~ name
|
38
|
+
|
39
|
+
spec = route.path.spec.to_s
|
40
|
+
segment_keys = route.segment_keys.uniq
|
41
|
+
options = route.defaults.except(*IGNORED_OPTIONS)
|
42
|
+
|
43
|
+
spec_var = var_name.call("#{name}_spec")
|
44
|
+
url_var = var_name.call("#{name}_url")
|
45
|
+
path_var = var_name.call("#{name}_path")
|
46
|
+
|
47
|
+
temp_file.write(<<-JAVASCRIPT.strip_heredoc)
|
48
|
+
const #{spec_var} = [#{js(spec)}, #{js(segment_keys)}, { ...#{default_url_options_var}, ...#{js(options)} }]
|
49
|
+
export const #{url_var} = (...args) => urlFor(#{spec_var}, ...args)
|
50
|
+
export const #{path_var} = (...args) => pathFor(#{spec_var}, ...args)
|
51
|
+
JAVASCRIPT
|
52
|
+
end
|
53
|
+
|
54
|
+
temp_file.close
|
55
|
+
if identical?(js_file.to_s, temp_file.path)
|
56
|
+
temp_file.unlink
|
57
|
+
throw :identical
|
58
|
+
end
|
49
59
|
end
|
50
60
|
end
|
51
61
|
end
|
@@ -55,6 +65,12 @@ module Webpacker
|
|
55
65
|
def js(obj)
|
56
66
|
ERB::Util.json_escape(obj.to_json)
|
57
67
|
end
|
68
|
+
|
69
|
+
def identical?(path1, path2)
|
70
|
+
FileUtils.compare_file(path1, path2)
|
71
|
+
rescue Errno::ENOENT
|
72
|
+
false
|
73
|
+
end
|
58
74
|
end
|
59
75
|
end
|
60
76
|
end
|
@@ -8,13 +8,12 @@ module Webpacker
|
|
8
8
|
config.webpacker.routes.camel_case = false
|
9
9
|
|
10
10
|
config.after_initialize do |app|
|
11
|
-
generate = -> { Webpacker::Routes.generate(app.tap(&:reload_routes!)) }
|
12
11
|
if Rails::VERSION::MAJOR >= 5
|
13
|
-
app.reloader.to_run(
|
12
|
+
app.reloader.to_run(:after) { Webpacker::Routes.generate(app) }
|
14
13
|
else
|
15
|
-
ActionDispatch::Reloader.to_prepare(
|
14
|
+
ActionDispatch::Reloader.to_prepare(:after) { Webpacker::Routes.generate(app) }
|
16
15
|
end
|
17
|
-
generate.
|
16
|
+
Webpacker::Routes.generate(app.tap(&:reload_routes!)) unless ENV['WEBPACKER_ROUTES_INSTALL']
|
18
17
|
end
|
19
18
|
end
|
20
19
|
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.1.
|
4
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2019-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -100,8 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
|
-
|
104
|
-
rubygems_version: 2.7.6
|
103
|
+
rubygems_version: 3.0.3
|
105
104
|
signing_key:
|
106
105
|
specification_version: 4
|
107
106
|
summary: Convert Rails routes to JavaScript modules
|