diff --git a/lib/generators/react_on_rails/base_generator.rb b/lib/generators/react_on_rails/base_generator.rb
index 76d38b5b4..c296fde4f 100644
--- a/lib/generators/react_on_rails/base_generator.rb
+++ b/lib/generators/react_on_rails/base_generator.rb
@@ -44,7 +44,7 @@ def update_application_js
DATA
app_js_path = "app/assets/javascripts/application.js"
- found_app_js = dest_file_exists?(app_js_path) || dest_file_exists?(app_js_path + ".coffee")
+ found_app_js = dest_file_exists?(app_js_path) || dest_file_exists?("#{app_js_path}.coffee")
if found_app_js
prepend_to_file(found_app_js, data)
else
@@ -65,19 +65,19 @@ def create_react_directories
def copy_base_files
base_path = "base/base/"
base_files = %w(app/controllers/hello_world_controller.rb
+ client/app/bundles/HelloWorld/components/HelloWorld.jsx
client/.babelrc
client/webpack.config.js
client/REACT_ON_RAILS_CLIENT_README.md)
- base_files.each { |file| copy_file(base_path + file, file) }
+ base_files.each { |file| copy_file("#{base_path}#{file}", file) }
end
def template_base_files
base_path = "base/base/"
%w(config/initializers/react_on_rails.rb
Procfile.dev
- app/views/hello_world/index.html.erb
package.json
- client/package.json).each { |file| template(base_path + file + ".tt", file) }
+ client/package.json).each { |file| template("#{base_path}#{file}.tt", file) }
end
def add_base_gems_to_gemfile
diff --git a/lib/generators/react_on_rails/react_no_redux_generator.rb b/lib/generators/react_on_rails/react_no_redux_generator.rb
index b317ae0bd..1cbb5845c 100644
--- a/lib/generators/react_on_rails/react_no_redux_generator.rb
+++ b/lib/generators/react_on_rails/react_no_redux_generator.rb
@@ -13,11 +13,11 @@ def create_appropriate_templates
location = "client/app/bundles/HelloWorld/"
source = base_path + location
config = {
- class_name: "HelloWorldApp",
- app_relative_path: "../components/HelloWorldApp"
+ component_name: "HelloWorld",
+ app_relative_path: "../components/HelloWorld"
}
- template(source + "/startup/registration.jsx" + ".tt", location + "/startup/registration.jsx", config)
- template(source + "/components/HelloWorld.jsx" + ".tt", location + "/components/HelloWorldApp.jsx", config)
+ template("#{source}/startup/registration.jsx.tt", "#{location}/startup/registration.jsx", config)
+ template("#{base_path}app/views/hello_world/index.html.erb.tt", "app/views/hello_world/index.html.erb", config)
end
end
end
diff --git a/lib/generators/react_on_rails/react_with_redux_generator.rb b/lib/generators/react_on_rails/react_with_redux_generator.rb
index 1c1534f56..a1376f84f 100644
--- a/lib/generators/react_on_rails/react_with_redux_generator.rb
+++ b/lib/generators/react_on_rails/react_with_redux_generator.rb
@@ -25,15 +25,14 @@ def copy_base_redux_files
def create_appropriate_templates
base_path = "base/base/"
- destination = "client/app/bundles/HelloWorld/"
+ location = "client/app/bundles/HelloWorld/"
+ source = base_path + location
config = {
- class_name: "HelloWorld",
+ component_name: "HelloWorldApp",
app_relative_path: "./HelloWorldApp"
}
- %w(/startup/registration.jsx
- /components/HelloWorld.jsx).each do |file|
- template(base_path + destination + file + ".tt", destination + file, config)
- end
+ template("#{source}/startup/registration.jsx.tt", "#{location}/startup/registration.jsx", config)
+ template("#{base_path}app/views/hello_world/index.html.erb.tt", "app/views/hello_world/index.html.erb", config)
end
end
end
diff --git a/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt b/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt
index a4d030dc8..98deed972 100644
--- a/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt
+++ b/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt
@@ -1,3 +1,3 @@
Hello World
-<%%= react_component("HelloWorldApp", props: @hello_world_props, prerender: false) %>
+<%%= react_component("<%= config[:component_name] %>", props: @hello_world_props, prerender: false) %>
diff --git a/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorld.jsx.tt b/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorld.jsx
similarity index 93%
rename from lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorld.jsx.tt
rename to lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorld.jsx
index 1995b36ef..8ea8aae74 100644
--- a/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorld.jsx.tt
+++ b/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorld.jsx
@@ -1,6 +1,6 @@
import React, { PropTypes } from 'react';
-export default class <%= config[:class_name] %> extends React.Component {
+export default class HelloWorld extends React.Component {
static propTypes = {
name: PropTypes.string.isRequired, // this is passed from the Rails view
};
diff --git a/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/registration.jsx.tt b/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/registration.jsx.tt
index 54d163115..379de1f4f 100644
--- a/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/registration.jsx.tt
+++ b/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/registration.jsx.tt
@@ -1,8 +1,8 @@
import ReactOnRails from 'react-on-rails';
-import HelloWorldApp from '<%= config[:app_relative_path] %>';
+import <%= config[:component_name] %> from '<%= config[:app_relative_path] %>';
// This is how react_on_rails can see the HelloWorld in the browser.
ReactOnRails.register({
- HelloWorldApp,
+ <%= config[:component_name] %>,
});
diff --git a/package.json b/package.json
index b41b04fb3..f437e6a8b 100644
--- a/package.json
+++ b/package.json
@@ -54,8 +54,8 @@
"build-watch": "babel --watch --out-dir node_package/lib node_package/src",
"eslint": "eslint .",
"flow": "flow check node_package",
- "lint": "npm run eslint && npm run flow",
- "check": "npm run lint && npm run test",
+ "lint": "npm run eslint",
+ "check": "npm run lint && npm run flow && npm run test",
"prerelease": "npm run check && npm run clean && npm run build",
"release:patch": "node_package/scripts/release patch",
"release:minor": "node_package/scripts/release minor",
diff --git a/spec/react_on_rails/support/shared_examples/base_generator_examples.rb b/spec/react_on_rails/support/shared_examples/base_generator_examples.rb
index 5d87a607b..fa5ed45ad 100644
--- a/spec/react_on_rails/support/shared_examples/base_generator_examples.rb
+++ b/spec/react_on_rails/support/shared_examples/base_generator_examples.rb
@@ -38,7 +38,7 @@
it "copies react files" do
%w(app/controllers/hello_world_controller.rb
- app/views/hello_world/index.html.erb
+ client/app/bundles/HelloWorld/components/HelloWorld.jsx
client/REACT_ON_RAILS_CLIENT_README.md
client/webpack.config.js
client/.babelrc
diff --git a/spec/react_on_rails/support/shared_examples/react_no_redux_generator_examples.rb b/spec/react_on_rails/support/shared_examples/react_no_redux_generator_examples.rb
index d87829c24..424e032eb 100644
--- a/spec/react_on_rails/support/shared_examples/react_no_redux_generator_examples.rb
+++ b/spec/react_on_rails/support/shared_examples/react_no_redux_generator_examples.rb
@@ -1,10 +1,10 @@
shared_examples "no_redux_generator" do
it "creates appropriate templates" do
assert_file("client/app/bundles/HelloWorld/startup/registration.jsx") do |contents|
- assert_match("../components/HelloWorldApp", contents)
+ assert_match("import HelloWorld from '../components/HelloWorld';", contents)
end
- assert_file("client/app/bundles/HelloWorld/components/HelloWorldApp.jsx") do |contents|
- assert_match("class HelloWorldApp extends", contents)
+ assert_file("app/views/hello_world/index.html.erb") do |contents|
+ assert_match(/"HelloWorld"/, contents)
end
end
diff --git a/spec/react_on_rails/support/shared_examples/react_with_redux_generator_examples.rb b/spec/react_on_rails/support/shared_examples/react_with_redux_generator_examples.rb
index f9ab3bf3e..6862160a6 100644
--- a/spec/react_on_rails/support/shared_examples/react_with_redux_generator_examples.rb
+++ b/spec/react_on_rails/support/shared_examples/react_with_redux_generator_examples.rb
@@ -5,10 +5,10 @@
it "creates appropriate templates" do
assert_file("client/app/bundles/HelloWorld/startup/registration.jsx") do |contents|
- assert_match("./HelloWorldApp", contents)
+ assert_match("import HelloWorldApp from './HelloWorldApp';", contents)
end
- assert_file("client/app/bundles/HelloWorld/components/HelloWorld.jsx") do |contents|
- assert_match("class HelloWorld extends", contents)
+ assert_file("app/views/hello_world/index.html.erb") do |contents|
+ assert_match(/"HelloWorldApp"/, contents)
end
end