js_from_routes 2.0.3 → 2.0.4
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 +4 -0
- data/lib/js_from_routes/generator.rb +13 -23
- 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 +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13b4bc245728511e15d787762ffddbe1bfb3799a7b61f69620a7f617435aed12
|
4
|
+
data.tar.gz: 1f2f759b537ce46f2628df9c17ea3f8325db4c7fb36e048270babc1a9116e637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5c443ada290e81b71dc6776e02007966471f6c2c188be2fc03f849b1c5f6bf0954fa1e37508f79a2f4ec015bd2e4b582f5ae29ed655843d07a0dd43f9f6d793
|
7
|
+
data.tar.gz: ee9cfcdf677e351aa7631c34835c9fbac8fd29fbb6d380c9bedb6965435f681c52f6a50c14ec63a8f971bef211b9ebf5e1ef2a243ac72e841f567250056a1b48
|
data/CHANGELOG.md
CHANGED
@@ -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,6 +179,7 @@ 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
|
|
@@ -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,7 +1,7 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
@@ -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:
|