File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,12 @@ class ComponentGenerator < ::Rails::Generators::NamedBase
65
65
default : false ,
66
66
desc : 'Output coffeescript based component'
67
67
68
+ class_option :function ,
69
+ type : :boolean ,
70
+ default : false ,
71
+ aliases : '--func' ,
72
+ desc : 'Output function based component'
73
+
68
74
REACT_PROP_TYPES = {
69
75
'node' => 'PropTypes.node' ,
70
76
'bool' => 'PropTypes.bool' ,
@@ -126,6 +132,8 @@ def create_component_file
126
132
'js.jsx.coffee'
127
133
elsif options [ :ts ]
128
134
'js.jsx.tsx'
135
+ elsif options [ :function ]
136
+ 'func.jsx'
129
137
elsif options [ :es6 ] || webpacker?
130
138
'es6.jsx'
131
139
else
Original file line number Diff line number Diff line change
1
+ < %= file_header % >
2
+ function < %= component_name % > () {
3
+ return (
4
+ < React . Fragment >
5
+ < % attributes . each do | attribute | - % >
6
+ < %= attribute [ :name ] . titleize % > : { this . props . < %= attribute [ :name ] . camelize ( :lower ) % > }
7
+ < % end - % >
8
+ </ React . Fragment >
9
+ );
10
+ }
11
+
12
+ < % if attributes . size > 0 -%>
13
+ < %= file_name . camelize % > .propTypes = {
14
+ < % attributes . each_with_index do | attribute , idx | - % >
15
+ < %= attribute [ :name ] . camelize ( :lower ) % > : < %= attribute [ :type ] % > < % if ( idx < attributes . length - 1 ) % > , < % end % >
16
+ < % end - % >
17
+ } ;
18
+ < % end - % >
19
+
20
+ < %= file_footer % >
You can’t perform that action at this time.
0 commit comments