-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1299 from ippachi/use-ts-es6-same-time
Make generator es6 and ts usable at same time
- Loading branch information
Showing
4 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<%= file_header %> | ||
interface I<%= component_name %>Props { | ||
<% if attributes.size > 0 -%> | ||
<% attributes.each do |attribute| -%> | ||
<% if attribute[:union] -%> | ||
<%= attribute[:name].camelize(:lower) %>: <%= attribute[:name].titleize %>; | ||
<% else -%> | ||
<%= attribute[:name].camelize(:lower) %>: <%= attribute[:type] %>; | ||
<% end -%> | ||
<% end -%> | ||
<% end -%> | ||
} | ||
|
||
const <%= component_name %> = (props: I<%= component_name %>Props) => { | ||
return ( | ||
<React.Fragment> | ||
<% attributes.each do |attribute| -%> | ||
<%= attribute[:name].titleize %>: {props.<%= attribute[:name].camelize(:lower) %>} | ||
<% end -%> | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
<%= file_footer %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "generators/react/component_generator" | ||
|
||
class TsEs6ComponentGeneratorTest < Rails::Generators::TestCase | ||
destination File.join(Rails.root, "tmp", "component_generator_test_output") | ||
setup :prepare_destination | ||
tests React::Generators::ComponentGenerator | ||
|
||
if ShakapackerHelpers.available? | ||
def filename | ||
"app/javascript/components/GeneratedComponent.tsx" | ||
end | ||
else | ||
def filename | ||
"app/assets/javascripts/components/generated_component.es6.tsx" | ||
end | ||
end | ||
|
||
def component_name | ||
"GeneratedComponent" | ||
end | ||
|
||
test "uses ts and es6 syntax" do | ||
run_generator %w[GeneratedComponent name:string --ts --es6] | ||
|
||
assert_file filename, /const #{component_name} = \(props: I#{component_name}Props\) => {/ | ||
end | ||
|
||
test "defines props type" do | ||
run_generator %w[GeneratedComponent name:string --ts --es6] | ||
|
||
assert_file filename, /name: string;/ | ||
end | ||
end |