js_from_routes 2.0.3 → 2.0.6
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 +25 -0
- data/lib/js_from_routes/generator.rb +14 -24
- 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 +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9053499de4df17e1ef042b1b54e4c172ab8ab94b2c0c353e6b8035efa8d3c0e5
|
4
|
+
data.tar.gz: 6fc5926dfcf3b0f94bde9c7176af31522c36bf206d6636563415143655414c3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30c30f206f148dcb9ca5dac38f4f5eb07d0b6d49f5ca4c87dd4e358a3b7af12ce1fe0750cb0554c91c0655c2cadcaf6ad47438a35b9ee9678eaf3cf4945ba2d5
|
7
|
+
data.tar.gz: 2515d4737e9202d93e99b3f573f43667d2beea1dc61a2fafdabf2a3752478e36289fd742649fe55396185604b3ff8b04d0742048e6d8ec7ef7530627107e0931
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
## [2.0.6](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@2.0.5...js_from_routes@2.0.6) (2022-05-25)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* should not attempt to export routes without controllers ([47f8f70](https://github.com/ElMassimo/js_from_routes/commit/47f8f70b0db98baa240470f8b2b891a730499518))
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
## [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)
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* ensure :export is not added as a required default in routes ([40126ac](https://github.com/ElMassimo/js_from_routes/commit/40126ac27caeee33abef1c7067ba1db88ea03660))
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
## [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)
|
20
|
+
|
21
|
+
### Features
|
22
|
+
|
23
|
+
* Allow importing individual helpers from "~/api" by adding exports ([2dfb8a2](https://github.com/ElMassimo/js_from_routes/commit/2dfb8a27d182376d75f0b037258bc772553e43f3)). Thanks @matias-capeletto!
|
24
|
+
|
25
|
+
|
1
26
|
## [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)
|
2
27
|
|
3
28
|
|
@@ -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
|
@@ -177,7 +155,18 @@ module JsFromRoutes
|
|
177
155
|
def generate_file_for_all(routes)
|
178
156
|
return unless config.all_helpers_file && !routes.empty?
|
179
157
|
|
180
|
-
|
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
|
+
)
|
181
170
|
end
|
182
171
|
|
183
172
|
def default_config(root)
|
@@ -190,13 +179,14 @@ module JsFromRoutes
|
|
190
179
|
output_folder: root.join("app", dir, "api"),
|
191
180
|
template_path: File.expand_path("template.js.erb", __dir__),
|
192
181
|
template_all_path: File.expand_path("template_all.js.erb", __dir__),
|
182
|
+
template_index_path: File.expand_path("template_index.js.erb", __dir__),
|
193
183
|
}
|
194
184
|
end
|
195
185
|
|
196
186
|
# Internal: Returns exported routes grouped by controller name.
|
197
187
|
def exported_routes_by_controller(routes)
|
198
188
|
routes.select { |route|
|
199
|
-
route.defaults.fetch(:export, false)
|
189
|
+
route.defaults.fetch(:export, false) && route.requirements[:controller]
|
200
190
|
}.group_by { |route|
|
201
191
|
route.requirements.fetch(:controller)
|
202
192
|
}
|
@@ -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.6
|
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:
|
11
|
+
date: 2022-05-25 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:
|
@@ -166,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
167
|
- !ruby/object:Gem::Version
|
167
168
|
version: '0'
|
168
169
|
requirements: []
|
169
|
-
rubygems_version: 3.
|
170
|
+
rubygems_version: 3.2.32
|
170
171
|
signing_key:
|
171
172
|
specification_version: 4
|
172
173
|
summary: Generate JS automatically from Rails routes.
|