Skip to content

Commit 945f095

Browse files
committed
Rails React Component CoffeeScript version generator is fixed to output the modules and require React objects
1 parent 43e07ac commit 945f095

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/generators/react/component_generator.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,23 @@ def component_name
125125

126126
def file_header
127127
if webpacker?
128-
%|var React = require("react")\n|
128+
if options[:coffee]
129+
%|React = require('react')\n|
130+
else
131+
%|var React = require("react")\n|
132+
end
129133
else
130134
""
131135
end
132136
end
133137

134138
def file_footer
135139
if webpacker?
136-
%|module.exports = #{component_name}|
140+
if options[:coffee]
141+
%|module.exports = @#{component_name}|
142+
else
143+
%|module.exports = #{component_name}|
144+
end
137145
else
138146
""
139147
end

lib/generators/templates/component.js.jsx.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<%= file_header %>
12
class @<%= component_name %> extends React.Component
23
<% if attributes.size > 0 -%>
34
@propTypes =
@@ -16,3 +17,5 @@ class @<%= component_name %> extends React.Component
1617
<% else -%>
1718
`<div />`
1819
<% end -%>
20+
21+
<%= file_footer %>

0 commit comments

Comments
 (0)