js_from_routes 2.0.1 → 2.0.5
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 +4 -4
- data/CHANGELOG.md +42 -0
- data/lib/js_from_routes/generator.rb +21 -26
- data/lib/js_from_routes/railtie.rb +10 -0
- data/lib/js_from_routes/template_all.js.erb +1 -7
- data/lib/js_from_routes/template_index.js.erb +5 -0
- data/lib/js_from_routes/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '00930d579b2a7eaada963f2b8139bf03f850224ca6a93cc4715b938a84e26b58'
|
4
|
+
data.tar.gz: 10556d08300abe1e64c0fdfaa35db23099d7915306928a210f48717258fc9762
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c099a34cc949e8d600c1199f8bcb66228bf0f57c5d17de329c87fefcacdcbe2f465996a1d0111a1b964117977bc311477640508f49d4a33d5107ba03d1e2551
|
7
|
+
data.tar.gz: a720dfc8dd9d2c26291c8feb6f8e009e3612612be2db83278c27d632a2c1bbcfe4a7e2bf9f7d63aa68c4418f119693c83cf58229bf21691e9a4492b0f7f48ccd
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,48 @@
|
|
1
|
+
## [2.0.5](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@2.0.5...js_from_routes@2.0.5) (2021-09-02)
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
## [2.0.5](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@2.0.4...js_from_routes@2.0.5) (2021-09-02)
|
6
|
+
|
7
|
+
|
8
|
+
### Bug Fixes
|
9
|
+
|
10
|
+
* ensure :export is not added as a required default in routes ([40126ac](https://github.com/ElMassimo/js_from_routes/commit/40126ac27caeee33abef1c7067ba1db88ea03660))
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
## [2.0.4](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@2.0.3...js_from_routes@2.0.4) (2021-03-16)
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
* Allow importing individual helpers from "~/api" by adding exports ([2dfb8a2](https://github.com/ElMassimo/js_from_routes/commit/2dfb8a27d182376d75f0b037258bc772553e43f3)). Thanks @matias-capeletto!
|
19
|
+
|
20
|
+
|
21
|
+
## [2.0.3](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@2.0.2...js_from_routes@2.0.3) (2021-03-16)
|
22
|
+
|
23
|
+
|
24
|
+
### Bug Fixes
|
25
|
+
|
26
|
+
* Ensure changing the client library triggers code generation ([6cf2bdf](https://github.com/ElMassimo/js_from_routes/commit/6cf2bdf4896dafe0d1e80668551665c46bfcadc6))
|
27
|
+
|
28
|
+
|
29
|
+
### Features
|
30
|
+
|
31
|
+
* Allow passing JS_FROM_ROUTES_FORCE=true to ignore cache keys ([8a6d2a8](https://github.com/ElMassimo/js_from_routes/commit/8a6d2a807e0a9926c6b24e1fc9127f917ec0ed5d))
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
## [2.0.2](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@2.0.1...js_from_routes@2.0.2) (2021-03-14)
|
36
|
+
|
37
|
+
### Improvements
|
38
|
+
|
39
|
+
- Remove underscores from namespaced controllers in global file ([90fdcc2](https://github.com/ElMassimo/js_from_routes/commit/90fdcc2))
|
40
|
+
|
1
41
|
## [2.0.1](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@2.0.0...js_from_routes@2.0.1) (2021-03-14)
|
2
42
|
|
43
|
+
### Features ⚡️
|
3
44
|
|
45
|
+
- Enable generation of index combining and exporting all helpers (#9)
|
4
46
|
|
5
47
|
# [2.0.0](https://github.com/ElMassimo/js_from_routes/compare/v1.0.3...js_from_routes@2.0.0) (2021-03-13)
|
6
48
|
|
@@ -8,28 +8,6 @@ require "pathname"
|
|
8
8
|
# Public: Automatically generates JS for Rails routes with { export: true }.
|
9
9
|
# Generates one file per controller, and one function per route.
|
10
10
|
module JsFromRoutes
|
11
|
-
# Internal: Helper class used as a presenter for the all helpers template.
|
12
|
-
class AllRoutes
|
13
|
-
attr_reader :helpers
|
14
|
-
|
15
|
-
def initialize(helpers, config)
|
16
|
-
@helpers, @config = helpers, config
|
17
|
-
end
|
18
|
-
|
19
|
-
# Public: Used to check whether the file should be generated again, changes
|
20
|
-
# based on the configuration, and route definition.
|
21
|
-
def cache_key
|
22
|
-
helpers.map(&:import_filename).join + File.read(@config.template_all_path)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Internal: Name of the JS file where all helpers will be exported.
|
26
|
-
def filename
|
27
|
-
path = @config.all_helpers_file
|
28
|
-
path = "index#{File.extname(@config.file_suffix)}" if path == true
|
29
|
-
@config.output_folder.join(path)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
11
|
# Internal: Helper class used as a presenter for the routes template.
|
34
12
|
class ControllerRoutes
|
35
13
|
attr_reader :routes
|
@@ -44,7 +22,7 @@ module JsFromRoutes
|
|
44
22
|
# Public: Used to check whether the file should be generated again, changes
|
45
23
|
# based on the configuration, and route definition.
|
46
24
|
def cache_key
|
47
|
-
routes.map(&:inspect).join + [File.read(@config.template_path), @config.helper_mappings.inspect].join
|
25
|
+
routes.map(&:inspect).join + [File.read(@config.template_path), @config.helper_mappings.inspect, @config.client_library].join
|
48
26
|
end
|
49
27
|
|
50
28
|
# Public: Exposes the preferred import library to the generator.
|
@@ -64,7 +42,7 @@ module JsFromRoutes
|
|
64
42
|
|
65
43
|
# Public: Name of the file as a valid JS variable.
|
66
44
|
def js_name
|
67
|
-
@controller.camelize(:lower).tr(":", "
|
45
|
+
@controller.camelize(:lower).tr(":", "")
|
68
46
|
end
|
69
47
|
|
70
48
|
# Internal: The base name of the JS file to be written.
|
@@ -126,6 +104,11 @@ module JsFromRoutes
|
|
126
104
|
object.instance_eval(@compiled_template)
|
127
105
|
end
|
128
106
|
|
107
|
+
# Internal: Returns true if the cache key has changed since the last codegen.
|
108
|
+
def stale?(file, cache_key_comment)
|
109
|
+
ENV["JS_FROM_ROUTES_FORCE"] || file.gets != cache_key_comment
|
110
|
+
end
|
111
|
+
|
129
112
|
# Internal: Writes if the file does not exist or the cache key has changed.
|
130
113
|
# The cache strategy consists of a comment on the first line of the file.
|
131
114
|
#
|
@@ -134,7 +117,7 @@ module JsFromRoutes
|
|
134
117
|
FileUtils.mkdir_p(name.dirname)
|
135
118
|
cache_key_comment = "// JsFromRoutes CacheKey #{Digest::MD5.hexdigest(cache_key)}\n"
|
136
119
|
File.open(name, "a+") { |file|
|
137
|
-
if file
|
120
|
+
if stale?(file, cache_key_comment)
|
138
121
|
file.truncate(0)
|
139
122
|
file.write(cache_key_comment)
|
140
123
|
file.write(yield)
|
@@ -172,7 +155,18 @@ module JsFromRoutes
|
|
172
155
|
def generate_file_for_all(routes)
|
173
156
|
return unless config.all_helpers_file && !routes.empty?
|
174
157
|
|
175
|
-
|
158
|
+
preferred_extension = File.extname(config.file_suffix)
|
159
|
+
index_file = config.all_helpers_file == true ? "index#{preferred_extension}" : config.all_helpers_file
|
160
|
+
|
161
|
+
Template.new(config.template_all_path).write_if_changed OpenStruct.new(
|
162
|
+
cache_key: routes.map(&:import_filename).join + File.read(config.template_all_path),
|
163
|
+
filename: config.output_folder.join("all#{preferred_extension}"),
|
164
|
+
helpers: routes,
|
165
|
+
)
|
166
|
+
Template.new(config.template_index_path).write_if_changed OpenStruct.new(
|
167
|
+
cache_key: File.read(config.template_index_path),
|
168
|
+
filename: config.output_folder.join(index_file),
|
169
|
+
)
|
176
170
|
end
|
177
171
|
|
178
172
|
def default_config(root)
|
@@ -185,6 +179,7 @@ module JsFromRoutes
|
|
185
179
|
output_folder: root.join("app", dir, "api"),
|
186
180
|
template_path: File.expand_path("template.js.erb", __dir__),
|
187
181
|
template_all_path: File.expand_path("template_all.js.erb", __dir__),
|
182
|
+
template_index_path: File.expand_path("template_index.js.erb", __dir__),
|
188
183
|
}
|
189
184
|
end
|
190
185
|
|
@@ -24,4 +24,14 @@ class JsFromRoutes::Railtie < Rails::Railtie
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
# Prevents Rails from interpreting the :export option as a required default,
|
29
|
+
# which would cause controller tests to fail.
|
30
|
+
initializer "js_from_routes.required_defaults" do |app|
|
31
|
+
ActionDispatch::Journey::Route.prepend Module.new {
|
32
|
+
def required_default?(key)
|
33
|
+
key == :export ? false : super
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
27
37
|
end
|
@@ -1,11 +1,5 @@
|
|
1
1
|
//
|
2
2
|
// DO NOT MODIFY: This file was automatically generated by JsFromRoutes.
|
3
3
|
<% helpers.each do |helper| %>
|
4
|
-
|
4
|
+
export { default as <%= helper.js_name %> } from '~/<%= helper.import_filename %>'
|
5
5
|
<% end %>
|
6
|
-
|
7
|
-
export default {
|
8
|
-
<% helpers.each do |helper| %>
|
9
|
-
<%= helper.js_name %>,
|
10
|
-
<% end %>
|
11
|
-
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js_from_routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/js_from_routes/railtie.rb
|
147
147
|
- lib/js_from_routes/template.js.erb
|
148
148
|
- lib/js_from_routes/template_all.js.erb
|
149
|
+
- lib/js_from_routes/template_index.js.erb
|
149
150
|
- lib/js_from_routes/version.rb
|
150
151
|
homepage: https://github.com/ElMassimo/js_from_routes
|
151
152
|
licenses:
|