js-routes 2.2.8 → 2.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -9
- data/Readme.md +60 -45
- data/lib/js_routes/configuration.rb +80 -34
- data/lib/js_routes/engine.rb +2 -0
- data/lib/js_routes/generators/base.rb +19 -0
- data/lib/js_routes/generators/middleware.rb +6 -8
- data/lib/js_routes/generators/webpacker.rb +1 -3
- data/lib/js_routes/instance.rb +50 -15
- data/lib/js_routes/middleware.rb +16 -3
- data/lib/js_routes/route.rb +60 -17
- data/lib/js_routes/types.rb +38 -0
- data/lib/js_routes/version.rb +2 -1
- data/lib/js_routes.rb +25 -7
- metadata +28 -45
- data/.document +0 -5
- data/.eslintrc.js +0 -15
- data/.github/workflows/ci.yml +0 -36
- data/.gitignore +0 -65
- data/.nvmrc +0 -1
- data/.rspec +0 -1
- data/Appraisals +0 -17
- data/Gemfile +0 -4
- data/Rakefile +0 -37
- data/VERSION_2_UPGRADE.md +0 -66
- data/gemfiles/rails50_sprockets_3.gemfile +0 -8
- data/gemfiles/rails51_sprockets_3.gemfile +0 -8
- data/gemfiles/rails52_sprockets_3.gemfile +0 -8
- data/gemfiles/rails70_sprockets_4.gemfile +0 -8
- data/js-routes.gemspec +0 -39
- data/package.json +0 -38
- data/spec/dummy/app/assets/config/manifest.js +0 -2
- data/spec/dummy/app/assets/javascripts/.gitkeep +0 -0
- data/spec/dummy/config/routes.rb +0 -55
- data/spec/js_routes/default_serializer_spec.rb +0 -31
- data/spec/js_routes/module_types/amd_spec.rb +0 -35
- data/spec/js_routes/module_types/cjs_spec.rb +0 -15
- data/spec/js_routes/module_types/dts/routes.spec.d.ts +0 -115
- data/spec/js_routes/module_types/dts/test.spec.ts +0 -56
- data/spec/js_routes/module_types/dts_spec.rb +0 -111
- data/spec/js_routes/module_types/esm_spec.rb +0 -45
- data/spec/js_routes/module_types/nil_spec.rb +0 -87
- data/spec/js_routes/module_types/umd_spec.rb +0 -85
- data/spec/js_routes/options_spec.rb +0 -508
- data/spec/js_routes/rails_routes_compatibility_spec.rb +0 -473
- data/spec/js_routes/route_specification_spec.rb +0 -37
- data/spec/js_routes/zzz_sprockets_spec.rb +0 -152
- data/spec/spec_helper.rb +0 -135
- data/spec/support/routes.rb +0 -81
- data/spec/tsconfig.json +0 -4
- data/tsconfig.json +0 -28
- data/yarn.lock +0 -2457
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f69479723e452f1b4ed09bf940b3150ad45430b5c601f966f05a082bce0a9494
|
4
|
+
data.tar.gz: bd47ceb7b1cba241262b8308e913f7d87aef6304d93d9185026e70dd4980487f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f67b2ccc88195647ea7c694f935848aad52ddd9e46ac1a766df0c29b7e123a147169deb5b8207c8d3a598fcf0c0ba01f98b0d24ee30b326737200f02f2f8235
|
7
|
+
data.tar.gz: 9aad6d181099b3fdd7ada0facf1269e08669cd1181f94d3039f0e13f8bf2bc5a44172e13843fec5a8317b4c99e1eee6a2de2343e34fe6c3cddebb7a63f9608fb
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
1
3
|
## master
|
2
4
|
|
5
|
+
## v2.2.10
|
6
|
+
|
7
|
+
* Remove sorbet files from repo
|
8
|
+
* Clearly define files included in gem
|
9
|
+
* Fix Middleware and Middleware generator bugs [#316](https://github.com/railsware/js-routes/issue/316)
|
10
|
+
* Remove empty object linter warning on DTS module
|
11
|
+
* Generators: Add `.ts` extension when searching for main JS file of the project
|
12
|
+
|
13
|
+
## v2.2.9
|
14
|
+
|
15
|
+
* Fix middleware error for non-modern setup.
|
16
|
+
* Added [Sorbet](https://sorbet.org/) method signatures.
|
17
|
+
* Always use DTS module type when calling JsRoutes.definitions or .definitions!. [#313](https://github.com/railsware/js-routes/issues/313)
|
18
|
+
|
3
19
|
## v2.2.8
|
4
20
|
|
5
21
|
* Leave emoji symbols intact when encoding URI fragment [#312](https://github.com/railsware/js-routes/issues/312)
|
@@ -28,10 +44,10 @@
|
|
28
44
|
## v2.2.3
|
29
45
|
|
30
46
|
* Fixed NIL module type namespace defintion [#297](https://github.com/railsware/js-routes/issues/297).
|
31
|
-
* The patch may cause a problem with nested `namespace` option
|
47
|
+
* The patch may cause a problem with nested `namespace` option.
|
32
48
|
* Ex. Value like `MyProject.Routes` requires to define `window.MyProject` before importing the routes file
|
33
49
|
|
34
|
-
## v2.2.2
|
50
|
+
## v2.2.2
|
35
51
|
|
36
52
|
* Fix custom file path [#295](https://github.com/railsware/js-routes/issues/295)
|
37
53
|
|
@@ -156,10 +172,9 @@ See [UPGRADE TO 2.0](./VERSION_2_UPGRADE.md) for guidance.
|
|
156
172
|
|
157
173
|
* Fixed bug when js-routes is used in envs without window.location #224
|
158
174
|
|
159
|
-
|
160
175
|
## v1.4.0
|
161
176
|
|
162
|
-
*
|
177
|
+
* Implemented Routes.config() and Routes.configure instead of Routes.defaults
|
163
178
|
|
164
179
|
New methods support 4 options at the moment:
|
165
180
|
|
@@ -245,7 +260,7 @@ Routes.configure({
|
|
245
260
|
|
246
261
|
* Support host, port and protocol inline parameters
|
247
262
|
* Support host, port and protocol parameters given to a route explicitly
|
248
|
-
* Remove all incompatibilities between
|
263
|
+
* Remove all incompatibilities between Actiondispatch and js-routes
|
249
264
|
|
250
265
|
## v1.1.2
|
251
266
|
|
@@ -271,10 +286,10 @@ Routes.configure({
|
|
271
286
|
|
272
287
|
## v1.0.0
|
273
288
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
289
|
+
* Add the compact mode [#125](https://github.com/railsware/js-routes/pull/125)
|
290
|
+
* Add support for host, protocol, and port configuration [#137](https://github.com/railsware/js-routes/pull/137)
|
291
|
+
* Routes path specs [#135](https://github.com/railsware/js-routes/pull/135)
|
292
|
+
* Support Rails 4.2 and Ruby 2.2 [#140](https://github.com/railsware/js-routes/pull/140)
|
278
293
|
|
279
294
|
## v0.9.9
|
280
295
|
|
data/Readme.md
CHANGED
@@ -16,22 +16,22 @@ gem "js-routes"
|
|
16
16
|
|
17
17
|
There are several possible ways to setup JsRoutes:
|
18
18
|
|
19
|
-
|
19
|
+
1. [Quick and easy](#quick-start) - Recommended
|
20
20
|
* Uses Rack Middleware to automatically update routes locally
|
21
21
|
* Automatically generates routes files on javascript build
|
22
22
|
* Works great for a simple Rails application
|
23
|
-
|
23
|
+
2. [Advanced Setup](#advanced-setup)
|
24
24
|
* Allows very custom setups
|
25
25
|
* Automatic updates need to be customized
|
26
|
-
|
26
|
+
3. [Webpacker ERB Loader](#webpacker) - Legacy
|
27
27
|
* Requires ESM module system (the default)
|
28
28
|
* Doesn't support typescript definitions
|
29
|
-
|
29
|
+
4. [Sprockets](#sprockets) - Legacy
|
30
30
|
* Deprecated and not recommended for modern apps
|
31
31
|
|
32
|
-
<div id=
|
32
|
+
<div id="quick-start"></div>
|
33
33
|
|
34
|
-
### Quick Start
|
34
|
+
### Quick Start
|
35
35
|
|
36
36
|
Setup [Rack Middleware](https://guides.rubyonrails.org/rails_on_rack.html#action-dispatcher-middleware-stack)
|
37
37
|
to automatically generate and maintain `routes.js` file and corresponding
|
@@ -77,13 +77,12 @@ Add js-routes files to `.gitignore`:
|
|
77
77
|
/app/javascript/routes.d.ts
|
78
78
|
```
|
79
79
|
|
80
|
-
<div id=
|
80
|
+
<div id="webpack"></div>
|
81
81
|
|
82
82
|
### Webpacker ERB loader
|
83
83
|
|
84
84
|
**IMPORTANT**: the setup doesn't support IDE autocompletion with [Typescript](https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html)
|
85
85
|
|
86
|
-
|
87
86
|
#### Use a Generator
|
88
87
|
|
89
88
|
Run a command:
|
@@ -133,7 +132,7 @@ Create routes file `app/javascript/routes.js.erb`:
|
|
133
132
|
<%= JsRoutes.generate() %>
|
134
133
|
```
|
135
134
|
|
136
|
-
Use routes wherever you need them:
|
135
|
+
Use routes wherever you need them:
|
137
136
|
|
138
137
|
``` javascript
|
139
138
|
import {post_path} from 'routes.js.erb';
|
@@ -141,62 +140,78 @@ import {post_path} from 'routes.js.erb';
|
|
141
140
|
alert(post_path(2));
|
142
141
|
```
|
143
142
|
|
144
|
-
<div id=
|
143
|
+
<div id="advanced-setup"></div>
|
145
144
|
|
146
145
|
### Advanced Setup
|
147
146
|
|
148
|
-
|
149
|
-
|
150
|
-
Routes file can be generated with a `rake` task:
|
147
|
+
In case you need multiple route files for different parts of your application, there are low level methods:
|
151
148
|
|
152
|
-
```
|
153
|
-
|
154
|
-
|
155
|
-
|
149
|
+
``` ruby
|
150
|
+
# Returns a routes file as a string
|
151
|
+
JsRoutes.generate(options)
|
152
|
+
# Writes routes to specific file location
|
153
|
+
JsRoutes.generate!(file_name, options)
|
154
|
+
# Writes Typescript definitions file for routes
|
155
|
+
JsRoutes.definitions!(file_name, options)
|
156
156
|
```
|
157
157
|
|
158
|
-
|
159
|
-
If your application has an `admin` and an `application` namespace for example:
|
160
|
-
|
161
|
-
**IMPORTANT**: Requires [Webpacker ERB Loader](#webpacker) setup.
|
158
|
+
They can also be used in ERB context
|
162
159
|
|
163
160
|
``` erb
|
164
|
-
|
165
|
-
<%= JsRoutes.generate(
|
161
|
+
<script>
|
162
|
+
var AdminRoutes = <%= JsRoutes.generate(
|
163
|
+
include: /admin/, module_type: nil, namespace: nil
|
164
|
+
) %>;
|
165
|
+
</script>
|
166
166
|
```
|
167
167
|
|
168
|
-
|
169
|
-
// app/javascript/customer/routes.js.erb
|
170
|
-
<%= JsRoutes.generate(exclude: /admin/) %>
|
171
|
-
```
|
168
|
+
Routes can be returns via API:
|
172
169
|
|
173
|
-
|
170
|
+
``` ruby
|
171
|
+
class Api::RoutesController < Api::BaseController
|
172
|
+
def index
|
173
|
+
options = {
|
174
|
+
include: /\Aapi_/,
|
175
|
+
default_url_options: { format: 'json' },
|
176
|
+
}
|
177
|
+
render json: {
|
178
|
+
routes: {
|
179
|
+
source: JsRoutes.generate(options),
|
180
|
+
definitions: JsRoutes.definitions(options),
|
181
|
+
}
|
182
|
+
}
|
183
|
+
end
|
184
|
+
end
|
174
185
|
|
175
|
-
``` erb
|
176
|
-
export const routes = <%= JsRoutes.generate(module_type: nil, namespace: nil) %>
|
177
186
|
```
|
178
187
|
|
179
|
-
|
188
|
+
Default auto-update middleware for development
|
189
|
+
doesn't support configuration out of the box,
|
190
|
+
but it can be extended through inheritence:
|
180
191
|
|
181
192
|
``` ruby
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
+
class AdvancedJsRoutesMiddleware < JsRoutes::Middleware
|
194
|
+
def regenerate
|
195
|
+
path = Rails.root.join("app/javascript")
|
196
|
+
|
197
|
+
JsRoutes.generate!(
|
198
|
+
"#{path}/app_routes.js", exclude: [/^admin_/, /^api_/]
|
199
|
+
)
|
200
|
+
JsRoutes.generate!(
|
201
|
+
"#{path}/adm_routes.js", include: /^admin_/
|
202
|
+
)
|
203
|
+
JsRoutes.generate!(
|
204
|
+
"#{path}/api_routes.js", include: /^api_/, default_url_options: {format: "json"}
|
205
|
+
)
|
206
|
+
end
|
207
|
+
end
|
193
208
|
```
|
194
209
|
|
195
|
-
<div id=
|
210
|
+
<div id="definitions"></div>
|
196
211
|
|
197
212
|
#### Typescript Definitions
|
198
213
|
|
199
|
-
JsRoutes has typescript support out of the box.
|
214
|
+
JsRoutes has typescript support out of the box.
|
200
215
|
|
201
216
|
Restrictions:
|
202
217
|
|
@@ -208,7 +223,7 @@ More advanced setup would involve calling manually:
|
|
208
223
|
|
209
224
|
``` ruby
|
210
225
|
JsRoutes.definitions! # to output to file
|
211
|
-
# or
|
226
|
+
# or
|
212
227
|
JsRoutes.definitions # to output to string
|
213
228
|
```
|
214
229
|
|
@@ -1,81 +1,122 @@
|
|
1
|
+
# typed: strict
|
1
2
|
require "pathname"
|
3
|
+
require "js_routes/types"
|
2
4
|
|
3
5
|
module JsRoutes
|
4
6
|
class Configuration
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
21
|
-
|
22
|
-
|
23
|
-
|
7
|
+
include JsRoutes::Types
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
sig { returns(T.nilable(String)) }
|
11
|
+
attr_accessor :namespace
|
12
|
+
sig { returns(Clusivity) }
|
13
|
+
attr_accessor :exclude
|
14
|
+
sig { returns(Clusivity) }
|
15
|
+
attr_accessor :include
|
16
|
+
sig { returns(FileName) }
|
17
|
+
attr_accessor :file
|
18
|
+
sig { returns(Prefix) }
|
19
|
+
attr_accessor :prefix
|
20
|
+
sig { returns(T::Boolean) }
|
21
|
+
attr_accessor :url_links
|
22
|
+
sig { returns(T::Boolean) }
|
23
|
+
attr_accessor :camel_case
|
24
|
+
sig { returns(Options) }
|
25
|
+
attr_accessor :default_url_options
|
26
|
+
sig { returns(T::Boolean) }
|
27
|
+
attr_accessor :compact
|
28
|
+
sig { returns(T.nilable(String)) }
|
29
|
+
attr_accessor :serializer
|
30
|
+
sig { returns(Literal) }
|
31
|
+
attr_accessor :special_options_key
|
32
|
+
sig { returns(ApplicationCaller) }
|
33
|
+
attr_accessor :application
|
34
|
+
sig { returns(T::Boolean) }
|
35
|
+
attr_accessor :documentation
|
36
|
+
sig { returns(T.nilable(String)) }
|
37
|
+
attr_accessor :module_type
|
38
|
+
|
39
|
+
sig {params(attributes: T.nilable(Options)).void }
|
24
40
|
def initialize(attributes = nil)
|
25
|
-
|
41
|
+
@namespace = nil
|
42
|
+
@exclude = T.let([], Clusivity)
|
43
|
+
@include = T.let([//], Clusivity)
|
44
|
+
@file = T.let(nil, FileName)
|
45
|
+
@prefix = T.let(-> { Rails.application.config.relative_url_root || "" }, T.untyped)
|
46
|
+
@url_links = T.let(false, T::Boolean)
|
47
|
+
@camel_case = T.let(false, T::Boolean)
|
48
|
+
@default_url_options = T.let(T.unsafe({}), Options)
|
49
|
+
@compact = T.let(false, T::Boolean)
|
50
|
+
@serializer = T.let(nil, T.nilable(String))
|
51
|
+
@special_options_key = T.let("_options", Literal)
|
52
|
+
@application = T.let(-> { Rails.application }, ApplicationCaller)
|
53
|
+
@module_type = T.let('ESM', T.nilable(String))
|
54
|
+
@documentation = T.let(true, T::Boolean)
|
55
|
+
|
26
56
|
return unless attributes
|
27
57
|
assign(attributes)
|
28
58
|
end
|
29
59
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
60
|
+
sig do
|
61
|
+
params(
|
62
|
+
attributes: Options,
|
63
|
+
).returns(JsRoutes::Configuration)
|
64
|
+
end
|
65
|
+
def assign(attributes)
|
35
66
|
if attributes
|
36
67
|
attributes.each do |attribute, value|
|
37
|
-
|
38
|
-
send(:"#{attribute}=", value)
|
68
|
+
public_send(:"#{attribute}=", value)
|
39
69
|
end
|
40
70
|
end
|
41
71
|
normalize_and_verify
|
42
72
|
self
|
43
73
|
end
|
44
74
|
|
75
|
+
sig { params(block: ConfigurationBlock).returns(T.self_type) }
|
76
|
+
def setup(&block)
|
77
|
+
tap(&block)
|
78
|
+
end
|
79
|
+
|
80
|
+
sig { params(attribute: Literal).returns(T.untyped) }
|
45
81
|
def [](attribute)
|
46
|
-
|
82
|
+
public_send(attribute)
|
47
83
|
end
|
48
84
|
|
85
|
+
sig { params(attributes: Options).returns(JsRoutes::Configuration) }
|
49
86
|
def merge(attributes)
|
50
87
|
clone.assign(attributes)
|
51
88
|
end
|
52
89
|
|
53
|
-
|
54
|
-
Hash[*members.zip(values).flatten(1)].symbolize_keys
|
55
|
-
end
|
56
|
-
|
90
|
+
sig {returns(T::Boolean)}
|
57
91
|
def esm?
|
58
92
|
module_type === 'ESM'
|
59
93
|
end
|
60
94
|
|
95
|
+
sig {returns(T::Boolean)}
|
61
96
|
def dts?
|
62
97
|
self.module_type === 'DTS'
|
63
98
|
end
|
64
99
|
|
100
|
+
sig {returns(T::Boolean)}
|
65
101
|
def modern?
|
66
102
|
esm? || dts?
|
67
103
|
end
|
68
104
|
|
105
|
+
sig { void }
|
69
106
|
def require_esm
|
70
107
|
raise "ESM module type is required" unless modern?
|
71
108
|
end
|
72
109
|
|
110
|
+
sig { returns(String) }
|
73
111
|
def source_file
|
74
112
|
File.dirname(__FILE__) + "/../" + default_file_name
|
75
113
|
end
|
76
114
|
|
115
|
+
sig { returns(Pathname) }
|
77
116
|
def output_file
|
78
|
-
webpacker_dir = defined?(Webpacker) ?
|
117
|
+
webpacker_dir = defined?(::Webpacker) ?
|
118
|
+
T.unsafe(::Webpacker).config.source_path :
|
119
|
+
pathname('app', 'javascript')
|
79
120
|
sprockets_dir = pathname('app','assets','javascripts')
|
80
121
|
file_name = file || default_file_name
|
81
122
|
sprockets_file = sprockets_dir.join(file_name)
|
@@ -85,23 +126,28 @@ module JsRoutes
|
|
85
126
|
|
86
127
|
protected
|
87
128
|
|
129
|
+
sig { void }
|
88
130
|
def normalize_and_verify
|
89
131
|
normalize
|
90
132
|
verify
|
91
133
|
end
|
92
134
|
|
135
|
+
sig { params(parts: String).returns(Pathname) }
|
93
136
|
def pathname(*parts)
|
94
|
-
Pathname.new(File.join(*parts))
|
137
|
+
Pathname.new(File.join(*T.unsafe(parts)))
|
95
138
|
end
|
96
139
|
|
140
|
+
sig { returns(String) }
|
97
141
|
def default_file_name
|
98
142
|
dts? ? "routes.d.ts" : "routes.js"
|
99
143
|
end
|
100
144
|
|
145
|
+
sig {void}
|
101
146
|
def normalize
|
102
147
|
self.module_type = module_type&.upcase || 'NIL'
|
103
148
|
end
|
104
149
|
|
150
|
+
sig { void }
|
105
151
|
def verify
|
106
152
|
if module_type != 'NIL' && namespace
|
107
153
|
raise "JsRoutes namespace option can only be used if module_type is nil"
|
data/lib/js_routes/engine.rb
CHANGED
@@ -3,14 +3,33 @@ require "rails/generators"
|
|
3
3
|
|
4
4
|
class JsRoutes::Generators::Base < Rails::Generators::Base
|
5
5
|
|
6
|
+
def self.inherited(subclass)
|
7
|
+
super
|
8
|
+
subclass.source_root(File.expand_path(__FILE__ + "/../../../templates"))
|
9
|
+
end
|
10
|
+
|
6
11
|
protected
|
7
12
|
|
8
13
|
def application_js_path
|
9
14
|
[
|
15
|
+
"app/javascript/packs/application.ts",
|
10
16
|
"app/javascript/packs/application.js",
|
17
|
+
"app/javascript/controllers/application.ts",
|
11
18
|
"app/javascript/controllers/application.js",
|
12
19
|
].find do |path|
|
13
20
|
File.exist?(Rails.root.join(path))
|
14
21
|
end
|
15
22
|
end
|
23
|
+
|
24
|
+
def depends_on?(gem_name)
|
25
|
+
!!Bundler.load.gems.find {|g| g.name == gem_name}
|
26
|
+
end
|
27
|
+
|
28
|
+
def depends_on_js_bundling?
|
29
|
+
depends_on?('jsbundling-rails')
|
30
|
+
end
|
31
|
+
|
32
|
+
def depends_on_webpacker?
|
33
|
+
depends_on?('webpacker')
|
34
|
+
end
|
16
35
|
end
|
@@ -2,8 +2,6 @@ require "js_routes/generators/base"
|
|
2
2
|
|
3
3
|
class JsRoutes::Generators::Middleware < JsRoutes::Generators::Base
|
4
4
|
|
5
|
-
source_root File.expand_path(__FILE__ + "/../../../templates")
|
6
|
-
|
7
5
|
def create_middleware
|
8
6
|
copy_file "initializer.rb", "config/initializers/js_routes.rb"
|
9
7
|
inject_into_file "config/environments/development.rb", middleware_content, before: /^end\n\z/
|
@@ -13,15 +11,15 @@ class JsRoutes::Generators::Middleware < JsRoutes::Generators::Base
|
|
13
11
|
inject_into_file path, pack_content
|
14
12
|
end
|
15
13
|
JsRoutes.generate!
|
16
|
-
JsRoutes.definitions!
|
14
|
+
JsRoutes.definitions! if JsRoutes.configuration.modern?
|
17
15
|
end
|
18
16
|
|
19
17
|
protected
|
20
18
|
|
21
19
|
def pack_content
|
22
20
|
<<-JS
|
23
|
-
import
|
24
|
-
|
21
|
+
import {root_path} from '../routes';
|
22
|
+
alert(`JsRoutes installed.\\nYour root path is ${root_path()}`)
|
25
23
|
JS
|
26
24
|
end
|
27
25
|
|
@@ -35,11 +33,11 @@ window.Routes = Routes;
|
|
35
33
|
end
|
36
34
|
|
37
35
|
def rakefile_content
|
38
|
-
enhanced_task =
|
39
|
-
|
36
|
+
enhanced_task = depends_on_js_bundling? ? "javascript:build" : "assets:precompile"
|
37
|
+
dependency_task = JsRoutes.configuration.modern? ? "js:routes:typescript" : 'js:routes'
|
40
38
|
<<-RB
|
41
39
|
# Update js-routes file before javascript build
|
42
|
-
task "#{enhanced_task}" => "
|
40
|
+
task "#{enhanced_task}" => "#{dependency_task}"
|
43
41
|
RB
|
44
42
|
end
|
45
43
|
|
@@ -2,8 +2,6 @@ require "rails/generators"
|
|
2
2
|
|
3
3
|
class JsRoutes::Generators::Webpacker < Rails::Generators::Base
|
4
4
|
|
5
|
-
source_root File.expand_path(__FILE__ + "/../../../templates")
|
6
|
-
|
7
5
|
def create_webpack
|
8
6
|
copy_file "initializer.rb", "config/initializers/js_routes.rb"
|
9
7
|
copy_file "erb.js", "config/webpack/loaders/erb.js"
|
@@ -21,7 +19,7 @@ class JsRoutes::Generators::Webpacker < Rails::Generators::Base
|
|
21
19
|
def pack_content
|
22
20
|
<<-JS
|
23
21
|
import * as Routes from 'routes.js.erb';
|
24
|
-
|
22
|
+
alert(Routes.root_path())
|
25
23
|
JS
|
26
24
|
end
|
27
25
|
|