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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db1718354ae9ce8148221f6cb5331398809cb684450cf1d88d43636f5b2f0c40
4
- data.tar.gz: d883f5e22c950ed87481ac9d8d1fca08ef669c5fe56b7fd51cc48124d9640077
3
+ metadata.gz: 13b4bc245728511e15d787762ffddbe1bfb3799a7b61f69620a7f617435aed12
4
+ data.tar.gz: 1f2f759b537ce46f2628df9c17ea3f8325db4c7fb36e048270babc1a9116e637
5
5
  SHA512:
6
- metadata.gz: 319b235a6fcc6bf8564517486de5fb9790fc5076fa0b3030b711eb49ea058c5ba877fc7b8a217976f9556cd330c8f78114e5a2361a11367536d25fad233ef013
7
- data.tar.gz: 8ec656121b7a10bb0123ede54409a5327d215124d6fdd11f38f5aad34d1f56e0e982dc5139cada10a978037d6fe0767ed94ef1abdcdded1d61d104438a12ff9f
6
+ metadata.gz: d5c443ada290e81b71dc6776e02007966471f6c2c188be2fc03f849b1c5f6bf0954fa1e37508f79a2f4ec015bd2e4b582f5ae29ed655843d07a0dd43f9f6d793
7
+ data.tar.gz: ee9cfcdf677e351aa7631c34835c9fbac8fd29fbb6d380c9bedb6965435f681c52f6a50c14ec63a8f971bef211b9ebf5e1ef2a243ac72e841f567250056a1b48
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [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)
2
+
3
+
4
+
1
5
  ## [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
6
 
3
7
 
@@ -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
- Template.new(config.template_all_path).write_if_changed AllRoutes.new(routes, config)
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
- import <%= helper.js_name %> from '~/<%= helper.import_filename %>'
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
- }
@@ -0,0 +1,5 @@
1
+ //
2
+ // DO NOT MODIFY: This file was automatically generated by JsFromRoutes.
3
+ import * as helpers from '~/api/all'
4
+ export * from '~/api/all'
5
+ export default helpers
@@ -4,5 +4,5 @@
4
4
  # Generates one file per controller, and one function per route.
5
5
  module JsFromRoutes
6
6
  # Public: This library adheres to semantic versioning.
7
- VERSION = "2.0.3"
7
+ VERSION = "2.0.4"
8
8
  end
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.3
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: