File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,12 @@ $ rails g react:component HelloWorld greeting:string
8787
8888Your component is added to ` app/javascript/components/ ` by default.
8989
90+ You can also generate your component in a subdirectory:
91+
92+ ```
93+ $ rails g react:component my_subdirectory/HelloWorld greeting:string
94+ ```
95+
9096[ Render it in a Rails view] ( #view-helper ) :
9197
9298``` erb
@@ -135,7 +141,7 @@ $ bundle exec rails webpacker:install:typescript
135141$ yarn add @types/react @types/react-dom
136142```
137143
138- Doing this will allow React-Rails to support the .tsx extension.
144+ Doing this will allow React-Rails to support the .tsx extension.
139145
140146## Use with Asset Pipeline
141147
Original file line number Diff line number Diff line change @@ -10,10 +10,16 @@ class ComponentGeneratorTest < Rails::Generators::TestCase
1010 def filename
1111 'app/javascript/components/GeneratedComponent.js'
1212 end
13+ def filename_with_subfolder
14+ 'app/javascript/components/generated_folder/GeneratedComponent.js'
15+ end
1316 else
1417 def filename
1518 'app/assets/javascripts/components/generated_component.js.jsx'
1619 end
20+ def filename_with_subfolder
21+ 'app/assets/javascripts/components/generated_folder/generated_component.js.jsx'
22+ end
1723 end
1824
1925 test 'creates the component file' do
@@ -27,6 +33,17 @@ def filename
2733 end
2834 end
2935
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+
3047 test 'creates the component file with a node argument' do
3148 run_generator %w( GeneratedComponent name )
3249 assert_file filename , %r{name: PropTypes.node}
You can’t perform that action at this time.
0 commit comments