File tree 3 files changed +25
-2
lines changed
3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,12 @@ $ rails g react:component HelloWorld greeting:string
87
87
88
88
Your component is added to ` app/javascript/components/ ` by default.
89
89
90
+ You can also generate your component in a subdirectory:
91
+
92
+ ```
93
+ $ rails g react:component my_subdirectory/HelloWorld greeting:string
94
+ ```
95
+
90
96
[ Render it in a Rails view] ( #view-helper ) :
91
97
92
98
``` erb
@@ -135,7 +141,7 @@ $ bundle exec rails webpacker:install:typescript
135
141
$ yarn add @types/react @types/react-dom
136
142
```
137
143
138
- Doing this will allow React-Rails to support the .tsx extension.
144
+ Doing this will allow React-Rails to support the .tsx extension.
139
145
140
146
## Use with Asset Pipeline
141
147
Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ def create_component_file
112
112
target_dir = 'app/assets/javascripts/components'
113
113
end
114
114
115
- file_path = File . join ( target_dir , "#{ new_file_name } .#{ extension } " )
115
+ file_path = File . join ( target_dir , class_path , "#{ new_file_name } .#{ extension } " )
116
116
template ( "component.#{ template_extension } " , file_path )
117
117
end
118
118
Original file line number Diff line number Diff line change @@ -10,10 +10,16 @@ class ComponentGeneratorTest < Rails::Generators::TestCase
10
10
def filename
11
11
'app/javascript/components/GeneratedComponent.js'
12
12
end
13
+ def filename_with_subfolder
14
+ 'app/javascript/components/generated_folder/GeneratedComponent.js'
15
+ end
13
16
else
14
17
def filename
15
18
'app/assets/javascripts/components/generated_component.js.jsx'
16
19
end
20
+ def filename_with_subfolder
21
+ 'app/assets/javascripts/components/generated_folder/generated_component.js.jsx'
22
+ end
17
23
end
18
24
19
25
test 'creates the component file' do
@@ -27,6 +33,17 @@ def filename
27
33
end
28
34
end
29
35
36
+ test 'creates the component file in a subdirectory' do
37
+ puts WebpackerHelpers . available?
38
+ run_generator %w( generated_folder/GeneratedComponent )
39
+ assert_file filename_with_subfolder do |contents |
40
+ if WebpackerHelpers . available?
41
+ assert_match /^import React from "react"/ , contents
42
+ assert_match /export default GeneratedComponent\n $/m , contents
43
+ end
44
+ end
45
+ end
46
+
30
47
test 'creates the component file with a node argument' do
31
48
run_generator %w( GeneratedComponent name )
32
49
assert_file filename , %r{name: PropTypes.node}
You can’t perform that action at this time.
0 commit comments