Skip to content

Commit

Permalink
per review
Browse files Browse the repository at this point in the history
  • Loading branch information
Judahmeek committed Nov 30, 2016
1 parent 8fccc92 commit 3503176
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 27 deletions.
8 changes: 4 additions & 4 deletions lib/generators/react_on_rails/base_generator.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/generators/react_on_rails/react_no_redux_generator.rb
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions lib/generators/react_on_rails/react_with_redux_generator.rb
Expand Up @@ -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
Expand Down
@@ -1,3 +1,3 @@
<h1>Hello World</h1>
<%%= react_component("HelloWorldApp", props: @hello_world_props, prerender: false) %>
<%%= react_component("<%= config[:component_name] %>", props: @hello_world_props, prerender: false) %>

@@ -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
};
Expand Down
@@ -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] %>,
});
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -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",
Expand Down
Expand Up @@ -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
Expand Down
@@ -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

Expand Down
Expand Up @@ -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

Expand Down

0 comments on commit 3503176

Please sign in to comment.