Skip to content

Commit

Permalink
removed jquery, fixed some linting. removed lodash completely
Browse files Browse the repository at this point in the history
  • Loading branch information
jbhatab committed Apr 24, 2016
1 parent 8401c9d commit 0ee40ba
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 71 deletions.
2 changes: 1 addition & 1 deletion lib/generators/USAGE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Description:

The react_on_rails:install generator integrates webpack with rails with ease. You can pass the redux option if you'd like to have redux setup for you automatically.
The react_on_rails:install generator integrates webpack with rails with ease. You can pass the redux option if you'd like to have redux setup for you automatically.

* Redux

Expand Down
12 changes: 1 addition & 11 deletions lib/generators/react_on_rails/base_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module ReactOnRails
module Generators
class BaseGenerator < Rails::Generators::Base # rubocop:disable Metrics/ClassLength
class BaseGenerator < Rails::Generators::Base
include GeneratorHelper
Rails::Generators.hide_namespace(namespace)
source_root(File.expand_path("../templates", __FILE__))
Expand Down Expand Up @@ -39,9 +39,6 @@ def update_git_ignore

def update_application_js
data = <<-DATA.strip_heredoc
// DO NOT REQUIRE jQuery or jQuery-ujs in this file!
// DO NOT REQUIRE TREE!
//= require webpack-bundle
DATA
Expand All @@ -55,13 +52,6 @@ def update_application_js
end
end

def strip_application_js_of_incompatible_sprockets_statements
application_js = File.join(destination_root, "app/assets/javascripts/application.js")
gsub_file(application_js, "//= require jquery_ujs", "// require jquery_ujs")
gsub_file(application_js, %r{//= require jquery$}, "// require jquery")
gsub_file(application_js, %r{//= require_tree \.$}, "// require_tree .")
end

def strip_application_js_of_double_blank_lines
application_js = File.join(destination_root, "app/assets/javascripts/application.js")
gsub_file(application_js, /^\n^\n/, "\n")
Expand Down
6 changes: 3 additions & 3 deletions lib/generators/react_on_rails/dev_tests_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def add_test_related_gems_to_gemfile
end

def gsub_prerender_if_server_rendering
return if !options.example_server_rendering
return unless options.example_server_rendering
hello_world_index = File.join(destination_root, "app", "views", "hello_world", "index.html.erb")
hello_world_contents = File.read(hello_world_index)
new_hello_world_contents = hello_world_contents.gsub(/\) %>/,
', prerender: true) %>')
new_hello_world_contents = hello_world_contents.gsub(/prerender: false/,
"prerender: true")

File.open(hello_world_index, "w+") { |f| f.puts new_hello_world_contents }
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h1 class="alert alert-info this-works">Hello World</h1>
<%%= react_component("HelloWorldApp", props: @hello_world_props) %>
<%%= react_component("HelloWorldApp", props: @hello_world_props, prerender: false) %>

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// all your dump component names with Widget.

import React, { PropTypes } from 'react';
import _ from 'lodash';

// Simple example of a React "dumb" component
export default class HelloWorldWidget extends React.Component {
Expand All @@ -13,15 +12,6 @@ export default class HelloWorldWidget extends React.Component {
name: PropTypes.string.isRequired,
};

constructor(props, context) {
super(props, context);

// Uses lodash to bind all methods to the context of the object instance, otherwise
// the methods defined here would not refer to the component's class, not the component
// instance itself.
_.bindAll(this, 'handleChange');
}

// React will automatically provide us with the event `e`
handleChange(e) {
const name = e.target.value;
Expand All @@ -43,7 +33,7 @@ export default class HelloWorldWidget extends React.Component {
<input
type="text"
value={name}
onChange={this.handleChange}
onChange={e => this.handleChange(e)}
/>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
"immutable": "^3.7.6",
<%- end -%>
"imports-loader": "^0.6.5",
"jquery": "^2.2.2",
"jquery-ujs": "^1.2.1",
<%- if options.redux? -%>
"mirror-creator": "1.1.0",
<%- end -%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ config = {
filename: 'webpack-bundle.js',
path: '../app/assets/webpack',
},

resolve: {
extensions: ['', '.js', '.jsx'],
alias: {
lib: path.join(process.cwd(), 'app', 'lib'),
// Look into
react: path.resolve('./node_modules/react'),
'react-dom': path.resolve('./node_modules/react-dom'),
},
Expand All @@ -35,11 +33,14 @@ config = {
],
module: {
loaders: [
{ test: require.resolve('jquery'), loader: 'expose?jQuery' },
{ test: require.resolve('jquery'), loader: 'expose?$' },
{ test: require.resolve('react'), loader: 'imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham' },
{ test: require.resolve('jquery-ujs'), loader: 'imports?jQuery=jquery' },
{ test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/ },
{
test: require.resolve('react'),
loader: 'imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham',
},
{
test: /\.jsx?$/, loader: 'babel-loader',
exclude: /node_modules/,
},
],
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
feature "Hello World", js: true do
scenario "the hello world example works" do
visit "/hello_world"
expect(heading).to have_text("Rendering")
expect(heading).to have_text("Hello World")
expect(message).to have_text("Stranger")
name_input.set("John Doe")
expect(message).to have_text("John Doe")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { PropTypes } from 'react';
import HelloWorldWidget from '../components/HelloWorldWidget';
import _ from 'lodash';

// Simple example of a React "smart" component
export default class HelloWorld extends React.Component {
Expand All @@ -14,11 +13,6 @@ export default class HelloWorld extends React.Component {
// How to set initial state in ES6 class syntax
// https://facebook.github.io/react/docs/reusable-components.html#es6-classes
this.state = { name: this.props.name };

// Uses lodash to bind all methods to the context of the object instance, otherwise
// the methods defined here would not refer to the component's class, not the component
// instance itself.
_.bindAll(this, 'updateName');
}

updateName(name) {
Expand All @@ -28,7 +22,7 @@ export default class HelloWorld extends React.Component {
render() {
return (
<div>
<HelloWorldWidget name={this.state.name} updateName={this.updateName} />
<HelloWorldWidget name={this.state.name} updateName={e => this.updateName(e)} />
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ const HelloWorldApp = (props) => {
};

// This is how react_on_rails can see the HelloWorldApp in the browser.
ReactOnRails.register({ HelloWorldApp });
ReactOnRails.register({ HelloWorldApp });
2 changes: 1 addition & 1 deletion spec/react_on_rails/support/generator_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def simulate_existing_rails_files(options)
if options.fetch(:hello_world_file, false)
simulate_existing_file(
"app/views/hello_world/index.html.erb",
"<%= react_component('HelloWorldApp', props: @hello_world_props) %>"
"<%= react_component('HelloWorldApp', props: @hello_world_props, prerender: false) %>"
)
end
simulate_existing_file("Gemfile", "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_examples "base_generator" do |options|
shared_examples "base_generator" do
it "adds a route for get 'hello_world' to 'hello_world#index'" do
match = <<-MATCH.strip_heredoc
Rails.application.routes.draw do
Expand All @@ -23,9 +23,6 @@

it "updates application.js" do
match = <<-MATCH.strip_heredoc
// DO NOT REQUIRE jQuery or jQuery-ujs in this file!
// DO NOT REQUIRE TREE!
//= require webpack-bundle
MATCH
Expand All @@ -34,36 +31,17 @@
end
end

it "doesn't include incompatible sprockets require statements" do
assert_file("app/assets/javascripts/application.js") do |contents|
refute_match(%r{//= require_tree \.$}, contents)
refute_match(%r{//= require jquery$}, contents)
refute_match("//= require jquery_ujs", contents)
end
end

it "comments out incompatible sprockets require statements" do
assert_file("app/assets/javascripts/application.js") do |contents|
if options[:application_js]
assert_match(%r{// require_tree \.$}, contents)
assert_match(%r{// require jquery$}, contents)
assert_match("//= require jquery-ui", contents)
assert_match("// require jquery_ujs", contents)
end
end
end

it "creates react directories" do
dirs = %w(components containers startup)
dirs.each { |dirname| assert_directory "client/app/bundles/HelloWorld/#{dirname}" }
end

it "copies react files" do
# client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx
%w(app/controllers/hello_world_controller.rb
app/views/hello_world/index.html.erb
client/webpack.config.js
client/.babelrc
client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx
client/package.json
config/initializers/react_on_rails.rb
package.json
Expand Down

0 comments on commit 0ee40ba

Please sign in to comment.