js_from_routes 3.0.0 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4dc77943e97a5b5ddb24ebf0dea4f8eb246ceee14e7e0db6820d18fa3d5e880d
4
- data.tar.gz: f4903735ecf2a1456735483c9f79ff0852a76f6d2ec091196b4310d4cb453a08
3
+ metadata.gz: 2b4a7e4009c35ed9b21a6ea1010d157faaed01d21143086a7573d87ae1a21aae
4
+ data.tar.gz: 67db6af0cbae2656a450649384c86f19a9c890fd58e84ea99fa7f03299866dd0
5
5
  SHA512:
6
- metadata.gz: 18e08f5bbccf22d80325ed48f6dbde2381f7369749d1fcdf28793a44242e56291bff6b5024a5ecd634eef88dc01c0ca36e1104a25874c0baae48ed6acf77c116
7
- data.tar.gz: e5b921b29440548ae6624782084d5e90ed78c87609e8f3fbef64e3767b7e90cf9954c58184747df05cdb6f9998719f8a54c973ce95d863f7e4c1e77301d16108
6
+ metadata.gz: 4b519fba61999909979dd313995733497c9536cb5fda7bdf0c0585e133ab718f4b733c46014d2b3b039fa81b7b70d6b8939e3e155656613dafc0577f64970041
7
+ data.tar.gz: 570cc1c4a497adf344b02e52c8c1da005877830be355638f85be7c9fe664094b03ee9d62c66a5295db1dfcd5d47993928581c0949f239b90f041e0d85f51c619
data/CHANGELOG.md CHANGED
@@ -1,14 +1,30 @@
1
- # [3.0.0](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@2.1.0...js_from_routes@3.0.0) (2023-10-09)
1
+ ## [3.0.2](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@3.0.1...js_from_routes@3.0.2) (2024-09-25)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * remove references to OpenStruct ([#49](https://github.com/ElMassimo/js_from_routes/issues/49)) ([6c0d8de](https://github.com/ElMassimo/js_from_routes/commit/6c0d8ded2bf82ccc2f8f35508dc256c3b301069a)), closes [#47](https://github.com/ElMassimo/js_from_routes/issues/47)
7
+
8
+
9
+
10
+ ## [3.0.1](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@3.0.0...js_from_routes@3.0.1) (2023-10-09)
2
11
 
3
12
 
4
13
  ### Features
5
14
 
6
- * **breaking:** no longer map `index` to `list` and `show` to `get` ([5eb3f48](https://github.com/ElMassimo/js_from_routes/commit/5eb3f48de71fe38ee1c67d9b91a81d71a437e1a8))
7
- * add `export_if` to allow using custom `:export` values ([fd1776c](https://github.com/ElMassimo/js_from_routes/commit/fd1776cc91402f1e9a9003031cb9fd6c3a0d63f9))
15
+ * allow rollup to tree-shake unused path helpers ([150ccd9](https://github.com/ElMassimo/js_from_routes/commit/150ccd9dd616ce448b50ae6c2807dd7f5678479d))
16
+
8
17
 
9
18
 
19
+ # [3.0.0](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@2.1.0...js_from_routes@3.0.0) (2023-10-09)
10
20
 
11
21
 
22
+ ### Features
23
+
24
+ * add `export_if` to allow using custom `:export` values ([fd1776c](https://github.com/ElMassimo/js_from_routes/commit/fd1776cc91402f1e9a9003031cb9fd6c3a0d63f9))
25
+
26
+ * **breaking:** no longer map `index` to `list` and `show` to `get` ([5eb3f48](https://github.com/ElMassimo/js_from_routes/commit/5eb3f48de71fe38ee1c67d9b91a81d71a437e1a8))
27
+
12
28
  If you want to preserve the old behavior:
13
29
 
14
30
  ```ruby
@@ -126,10 +126,29 @@ module JsFromRoutes
126
126
  end
127
127
  end
128
128
 
129
+ class Configuration
130
+ attr_accessor :all_helpers_file, :client_library, :export_if, :file_suffix,
131
+ :helper_mappings, :output_folder, :template_path,
132
+ :template_all_path, :template_index_path
133
+
134
+ def initialize(root)
135
+ dir = %w[frontend packs javascript assets].find { |dir| root.join("app", dir).exist? }
136
+ @all_helpers_file = true
137
+ @client_library = "@js-from-routes/client"
138
+ @export_if = ->(route) { route.defaults.fetch(:export, nil) }
139
+ @file_suffix = "Api.js"
140
+ @helper_mappings = {}
141
+ @output_folder = root.join("app", dir, "api")
142
+ @template_path = File.expand_path("template.js.erb", __dir__)
143
+ @template_all_path = File.expand_path("template_all.js.erb", __dir__)
144
+ @template_index_path = File.expand_path("template_index.js.erb", __dir__)
145
+ end
146
+ end
147
+
129
148
  class << self
130
149
  # Public: Configuration of the code generator.
131
150
  def config
132
- @config ||= OpenStruct.new(default_config(::Rails.root || Pathname.new(Dir.pwd)))
151
+ @config ||= Configuration.new(::Rails.root || Pathname.new(Dir.pwd))
133
152
  yield(@config) if block_given?
134
153
  @config
135
154
  end
@@ -156,7 +175,7 @@ module JsFromRoutes
156
175
  return unless config.all_helpers_file && !routes.empty?
157
176
 
158
177
  preferred_extension = File.extname(config.file_suffix)
159
- index_file = config.all_helpers_file == true ? "index#{preferred_extension}" : config.all_helpers_file
178
+ index_file = (config.all_helpers_file == true) ? "index#{preferred_extension}" : config.all_helpers_file
160
179
 
161
180
  Template.new(config.template_all_path).write_if_changed OpenStruct.new(
162
181
  cache_key: routes.map(&:import_filename).join + File.read(config.template_all_path),
@@ -169,21 +188,6 @@ module JsFromRoutes
169
188
  )
170
189
  end
171
190
 
172
- def default_config(root)
173
- dir = %w[frontend packs javascript assets].find { |dir| root.join("app", dir).exist? }
174
- {
175
- all_helpers_file: true,
176
- client_library: "@js-from-routes/client",
177
- export_if: ->(route) { route.defaults.fetch(:export, nil) },
178
- file_suffix: "Api.js",
179
- helper_mappings: {},
180
- output_folder: root.join("app", dir, "api"),
181
- template_path: File.expand_path("template.js.erb", __dir__),
182
- template_all_path: File.expand_path("template_all.js.erb", __dir__),
183
- template_index_path: File.expand_path("template_index.js.erb", __dir__),
184
- }
185
- end
186
-
187
191
  # Internal: Returns exported routes grouped by controller name.
188
192
  def exported_routes_by_controller(routes)
189
193
  routes.select { |route|
@@ -30,7 +30,7 @@ class JsFromRoutes::Railtie < Rails::Railtie
30
30
  initializer "js_from_routes.required_defaults" do |app|
31
31
  ActionDispatch::Journey::Route.prepend Module.new {
32
32
  def required_default?(key)
33
- key == :export ? false : super
33
+ (key == :export) ? false : super
34
34
  end
35
35
  }
36
36
  end
@@ -4,6 +4,6 @@ import { definePathHelper } from '<%= client_library %>'
4
4
 
5
5
  export default {
6
6
  <% routes.each do |route| %>
7
- <%= route.helper %>: definePathHelper('<%= route.verb %>', '<%= route.path %>'),
7
+ <%= route.helper %>: /* #__PURE__ */ definePathHelper('<%= route.verb %>', '<%= route.path %>'),
8
8
  <% end %>
9
9
  }
@@ -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 = "3.0.0"
7
+ VERSION = "3.0.2"
8
8
  end
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: 3.0.0
4
+ version: 3.0.2
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: 2023-10-09 00:00:00.000000000 Z
11
+ date: 2024-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubygems_version: 3.4.10
170
+ rubygems_version: 3.5.16
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: Generate JS automatically from Rails routes.