react_on_rails 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +182 -56
  3. data/{LICENSE → docs/LICENSE} +0 -0
  4. data/docs/{gen-notes/reducers.md → additional_reading/generated_client_code.md} +5 -1
  5. data/docs/additional_reading/heroku_deployment.md +21 -0
  6. data/docs/{manual_configuration.md → additional_reading/manual_installation.md} +4 -63
  7. data/docs/{node_dependencies_and_npm.md → additional_reading/node_dependencies_and_npm.md} +0 -0
  8. data/docs/additional_reading/optional_configuration.md +34 -0
  9. data/docs/additional_reading/server_rendering_tips.md +16 -0
  10. data/docs/additional_reading/tips.md +10 -0
  11. data/{CODE_OF_CONDUCT.md → docs/code_of_conduct.md} +0 -0
  12. data/docs/{Contributing.md → contributing.md} +0 -0
  13. data/lib/generators/react_on_rails/base_generator.rb +35 -4
  14. data/lib/generators/react_on_rails/bootstrap_generator.rb +27 -7
  15. data/lib/generators/react_on_rails/generator_helper.rb +4 -2
  16. data/lib/generators/react_on_rails/install_generator.rb +13 -19
  17. data/lib/generators/react_on_rails/js_linters_generator.rb +19 -0
  18. data/lib/generators/react_on_rails/react_no_redux_generator.rb +7 -3
  19. data/lib/generators/react_on_rails/react_with_redux_generator.rb +6 -15
  20. data/lib/generators/react_on_rails/ruby_linters_generator.rb +33 -0
  21. data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/globals.jsx.tt +5 -0
  22. data/lib/generators/react_on_rails/templates/{redux → base}/base/client/package.json.tt +23 -10
  23. data/lib/generators/react_on_rails/templates/base/base/client/server.js +8 -2
  24. data/lib/generators/react_on_rails/templates/base/base/client/{webpack.client.base.config.js → webpack.client.base.config.js.tt} +2 -1
  25. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +1 -3
  26. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake +1 -3
  27. data/lib/generators/react_on_rails/templates/{linters/lib/tasks/linters.rake → base/base/lib/tasks/linters.rake.tt} +36 -29
  28. data/lib/generators/react_on_rails/templates/{linters → js_linters}/client/.eslintignore +0 -0
  29. data/lib/generators/react_on_rails/templates/{linters → js_linters}/client/.eslintrc +0 -0
  30. data/lib/generators/react_on_rails/templates/{linters → js_linters}/client/.jscsrc +0 -0
  31. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +12 -0
  32. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/index.jsx +2 -2
  33. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/{HelloWorldAppClient.jsx → HelloWorldAppClient.jsx.tt} +3 -2
  34. data/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js +1 -5
  35. data/lib/generators/react_on_rails/templates/ruby_linters/.rubocop.yml +26 -0
  36. data/lib/generators/react_on_rails/templates/ruby_linters/.scss-lint.yml +205 -0
  37. data/lib/generators/react_on_rails/templates/{linters → ruby_linters}/lib/tasks/brakeman.rake +0 -0
  38. data/lib/generators/react_on_rails/templates/{linters → ruby_linters}/lib/tasks/ci.rake +0 -0
  39. data/lib/generators/react_on_rails/templates/ruby_linters/ruby-lint.yml +20 -0
  40. data/lib/react_on_rails/version.rb +1 -1
  41. metadata +29 -24
  42. data/docs/gen-notes/react_syntax.md +0 -3
  43. data/docs/linters.md +0 -25
  44. data/lib/generators/react_on_rails/linters_generator.rb +0 -38
  45. data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/clientGlobals.jsx +0 -4
  46. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx +0 -11
  47. data/lib/generators/react_on_rails/templates/no_redux/base/client/package.json.tt +0 -75
@@ -1,11 +1,9 @@
1
1
  // This file is used by the webpack HMR dev server to load your component without using Rails
2
2
  // It should simply match routes to basic HTML or jade files that render your component
3
3
  /* eslint-disable no-console, func-names, no-var */
4
- var bodyParser = require('body-parser');
5
4
  var webpack = require('webpack');
6
5
  var WebpackDevServer = require('webpack-dev-server');
7
6
  var jade = require('jade');
8
- var sleep = require('sleep');
9
7
  var config = require('./webpack.client.hot.config');
10
8
 
11
9
  var server = new WebpackDevServer(webpack(config), {
@@ -21,6 +19,14 @@ var server = new WebpackDevServer(webpack(config), {
21
19
  },
22
20
  });
23
21
 
22
+ // The following code is commented out because the HelloWorld example
23
+ // does not use any asynchronous functionality. It is meant to serve
24
+ // as an example of how one might implement an API in express for their
25
+ // webpack dev server
26
+ // Note, it would be necessary to run `npm i --save body-parser sleep` for
27
+ // the following to work:
28
+ // var bodyParser = require('body-parser');
29
+ // var sleep = require('sleep');
24
30
  // See tutorial for example of using AJAX:
25
31
  // https://github.com/shakacode/react-webpack-rails-tutorial
26
32
 
@@ -1,3 +1,4 @@
1
+ <%- client_globals_name = options.server_rendering? ? "clientGlobals" : "globals" -%>
1
2
  // Common client-side webpack configuration used by webpack.hot.config and webpack.rails.config.
2
3
 
3
4
  const webpack = require('webpack');
@@ -20,7 +21,7 @@ module.exports = {
20
21
 
21
22
  // This will contain the app entry points defined by webpack.hot.config and webpack.rails.config
22
23
  app: [
23
- './app/bundles/HelloWorld/startup/clientGlobals',
24
+ './app/bundles/HelloWorld/startup/<%= client_globals_name %>',
24
25
  ],
25
26
  },
26
27
  resolve: {
@@ -4,9 +4,7 @@ ReactOnRails.configure do |config|
4
4
 
5
5
  # Server rendering:
6
6
  # Server bundle is a single file for all server rendering of components.
7
- # It is important to set this to "" if you are not doing server rendering to avoid an extraneous log warning
8
- # that the default file of server-bundle.js does not exist.
9
- config.server_bundle_js_file = "app/assets/javascripts/generated/server-bundle.js" # This is the default
7
+ config.server_bundle_js_file = "app/assets/javascripts/generated/server-bundle.js"
10
8
  # increase if you're on JRuby
11
9
  config.server_renderer_pool_size = 1
12
10
  # seconds
@@ -19,8 +19,6 @@ namespace :assets do
19
19
  end
20
20
 
21
21
  task :clobber do
22
- rm_rf "#{Rails.application.config.root}/app/assets/javascripts/generated/vendor-bundle.js"
23
- rm_rf "#{Rails.application.config.root}/app/assets/javascripts/generated/client-bundle.js"
24
- rm_rf "#{Rails.application.config.root}/app/assets/javascripts/generated/server-bundle.js"
22
+ rm_r Dir.glob(Rails.root.join("app/assets/javascripts/generated/*"))
25
23
  end
26
24
  end
@@ -1,5 +1,6 @@
1
1
  if %w(development test).include? Rails.env
2
2
  namespace :lint do
3
+ <%- if options.ruby_linters? -%>
3
4
  # This fails: https://github.com/bbatsov/rubocop/issues/1840
4
5
  # RuboCop::RakeTask.new
5
6
  # require "rubocop/rake_task"
@@ -24,23 +25,17 @@ if %w(development test).include? Rails.env
24
25
  sh cmd
25
26
  end
26
27
 
27
- desc "eslint"
28
- task :eslint do
29
- cmd = "cd client && npm run eslint . -- --ext .jsx,.js"
30
- puts "Running eslint via `#{cmd}`"
31
- sh cmd
32
- end
33
-
34
- desc "jscs"
35
- task :jscs do
36
- cmd = "cd client && npm run jscs ."
37
- puts "Running jscs via `#{cmd}`"
38
- sh cmd
39
- end
40
-
41
- desc "JS Linting"
42
- task js: [:eslint, :jscs] do
43
- puts "Completed running all JavaScript Linters"
28
+ desc "See docs for task 'scss_lint'"
29
+ task :scss do
30
+ begin
31
+ require 'scss_lint/rake_task'
32
+ SCSSLint::RakeTask.new do |t|
33
+ t.files = ["app/assets/stylesheets/", "client/assets/stylesheets/"]
34
+ end
35
+ Rake::Task[:scss_lint].invoke
36
+ rescue LoadError
37
+ puts "** add gem 'scss_lint' to your Gemfile for scss linting."
38
+ end
44
39
  end
45
40
 
46
41
  # desc "haml_lint"
@@ -58,20 +53,32 @@ if %w(development test).include? Rails.env
58
53
  # t.files = ["app/views"]
59
54
  # end
60
55
 
61
- desc "See docs for task 'scss_lint'"
62
- task :scss do
63
- begin
64
- require 'scss_lint/rake_task'
65
- SCSSLint::RakeTask.new do |t|
66
- t.files = ["app/assets/stylesheets/", "client/assets/stylesheets/"]
67
- end
68
- Rake::Task[:scss_lint].invoke
69
- rescue LoadError
70
- puts "** add gem 'scss_lint' to your Gemfile for scss linting."
71
- end
56
+ <%- end -%>
57
+ <%- unless options.skip_js_linters? -%>
58
+ desc "eslint"
59
+ task :eslint do
60
+ cmd = "cd client && npm run eslint . -- --ext .jsx,.js"
61
+ puts "Running eslint via `#{cmd}`"
62
+ sh cmd
63
+ end
64
+
65
+ desc "jscs"
66
+ task :jscs do
67
+ cmd = "cd client && npm run jscs ."
68
+ puts "Running jscs via `#{cmd}`"
69
+ sh cmd
70
+ end
71
+
72
+ desc "JS Linting"
73
+ task js: [:eslint, :jscs] do
74
+ puts "Completed running all JavaScript Linters"
72
75
  end
76
+ <%- end -%>
73
77
 
74
- task lint: [:rubocop, :ruby, :js, :scss] do
78
+ <%- enabled_linters = [] -%>
79
+ <%- enabled_linters << %i(rubocop, ruby) if options.ruby_linters? -%>
80
+ <%- enabled_linters << %i(js scss) unless options.skip_js_linters? -%>
81
+ task lint: <%= enabled_linters.flatten %> do
75
82
  puts "Completed all linting"
76
83
  end
77
84
  end
@@ -0,0 +1,12 @@
1
+ <%- component_name = options.server_rendering? ? "HelloWorldAppClient" : "HelloWorldApp" -%>
2
+ import React from 'react';
3
+ import HelloWorld from '../containers/HelloWorld';
4
+
5
+ const <%= component_name %> = props => {
6
+ const reactComponent = (
7
+ <HelloWorld {...props} />
8
+ );
9
+ return reactComponent;
10
+ };
11
+
12
+ export default <%= component_name %>;
@@ -1,7 +1,7 @@
1
1
  // This file is our manifest of all reducers for the app.
2
- // See /client/app/bundles/HelloWorld/store/helloWorldStore.jsx
2
+ // See also /client/app/bundles/HelloWorld/store/helloWorldStore.jsx
3
3
  // A real world app will like have many reducers and it helps to organize them in one file.
4
- // See `docs/generators/reducers.md` at https://github.com/shakacode/react_on_rails
4
+ // `https://github.com/shakacode/react_on_rails/tree/master/docs/additional_reading/generated_client_code.md`
5
5
  import helloWorldReducer from './helloWorldReducer';
6
6
  import { $$initialState as $$helloWorldState } from './helloWorldReducer';
7
7
 
@@ -1,3 +1,4 @@
1
+ <%- generator_function_name = options.server_rendering? ? "HelloWorldAppClient" : "HelloWorldApp" -%>
1
2
  import React from 'react';
2
3
  import { Provider } from 'react-redux';
3
4
 
@@ -7,7 +8,7 @@ import HelloWorld from '../containers/HelloWorld';
7
8
  // See documentation for https://github.com/rackt/react-redux.
8
9
  // This is how you get props from the Rails view into the redux store.
9
10
  // This code here binds your smart component to the redux store.
10
- const HelloWorldAppClient = props => {
11
+ const <%= generator_function_name %> = props => {
11
12
  const store = createStore(props);
12
13
  const reactComponent = (
13
14
  <Provider store={store}>
@@ -17,4 +18,4 @@ const HelloWorldAppClient = props => {
17
18
  return reactComponent;
18
19
  };
19
20
 
20
- export default HelloWorldAppClient;
21
+ export default <%= generator_function_name %>;
@@ -10,13 +10,9 @@ export default function logger({ getState }) {
10
10
  // Call the next dispatch method in the middleware chain.
11
11
  const result = next(action);
12
12
 
13
- // We can't console.log immutable objects out-of-the-box.
14
13
  const immutableState = getState();
15
- const readableState = _.reduce(immutableState, (result, immutable, key) => {
16
- result[key] = immutable.toJS();
17
- }, {});
18
14
 
19
- console.log('state after dispatch', readableState);
15
+ console.log('state after dispatch', JSON.stringify(immutableState));
20
16
 
21
17
  // This will likely be the action itself, unless
22
18
  // a middleware further in chain changed it.
@@ -0,0 +1,26 @@
1
+ # This is the configuration used to check the rubocop source code.
2
+ # Check out: https://github.com/bbatsov/rubocop
3
+
4
+ AllCops:
5
+ Include:
6
+ - '**/Rakefile'
7
+ - '**/config.ru'
8
+ Exclude:
9
+ - 'vendor/**/*'
10
+ - 'spec/fixtures/**/*'
11
+ - 'node_modules/**/*'
12
+ - 'db/**/*'
13
+ - 'db/schema.rb'
14
+ - 'db/seeds.rb'
15
+ - 'client/node_modules/**/*'
16
+ - 'bin/**/*'
17
+ - !ruby/regexp /old_and_unused\.rb$/
18
+
19
+ Metrics/LineLength:
20
+ Max: 120
21
+
22
+ Style/StringLiterals:
23
+ EnforcedStyle: double_quotes
24
+
25
+ Style/Documentation:
26
+ Enabled: false
@@ -0,0 +1,205 @@
1
+ # See http://sass-guidelin.es/#zeros
2
+
3
+ scss_files:
4
+ - 'app/assets/stylesheets/**/*.scss'
5
+ - 'client/assets/stylesheets/**/*.scss'
6
+
7
+ linters:
8
+ # BangFormat:
9
+ # enabled: true
10
+ # space_before_bang: true
11
+ # space_after_bang: false
12
+ #
13
+ # BorderZero:
14
+ # enabled: true
15
+ # convention: zero # or `none`
16
+ #
17
+ ColorKeyword:
18
+ enabled: false
19
+ ColorVariable:
20
+ enabled: false
21
+ #
22
+ # Comment:
23
+ # enabled: true
24
+ #
25
+ # DebugStatement:
26
+ # enabled: true
27
+ #
28
+ # DeclarationOrder:
29
+ # enabled: true
30
+ #
31
+ # DuplicateProperty:
32
+ # enabled: true
33
+ #
34
+ # ElsePlacement:
35
+ # enabled: true
36
+ # style: same_line # or 'new_line'
37
+ #
38
+ # EmptyLineBetweenBlocks:
39
+ # enabled: true
40
+ # ignore_single_line_blocks: true
41
+ #
42
+ # EmptyRule:
43
+ # enabled: true
44
+ #
45
+ # FinalNewline:
46
+ # enabled: true
47
+ # present: true
48
+ #
49
+ HexLength:
50
+ enabled: true
51
+ style: long
52
+
53
+ HexNotation:
54
+ enabled: true
55
+ style: uppercase
56
+ #
57
+ # HexValidation:
58
+ # enabled: true
59
+ #
60
+ IdSelector:
61
+ enabled: true
62
+ #
63
+ # ImportantRule:
64
+ # enabled: true
65
+ #
66
+ # ImportPath:
67
+ # enabled: true
68
+ # leading_underscore: false
69
+ # filename_extension: false
70
+ #
71
+ # Indentation:
72
+ # enabled: true
73
+ # allow_non_nested_indentation: false
74
+ # character: space # or 'tab'
75
+ # width: 2
76
+ #
77
+ LeadingZero:
78
+ enabled: true
79
+ style: include_zero
80
+ #
81
+ # MergeableSelector:
82
+ # enabled: true
83
+ # force_nesting: true
84
+ #
85
+ # NameFormat:
86
+ # enabled: true
87
+ # allow_leading_underscore: true
88
+ # convention: hyphenated_lowercase # or 'camel_case', or 'snake_case', or a regex pattern
89
+ #
90
+ # NestingDepth:
91
+ # enabled: true
92
+ # max_depth: 3
93
+ #
94
+ # PlaceholderInExtend:
95
+ # enabled: true
96
+ #
97
+ # PropertyCount:
98
+ # enabled: false
99
+ # include_nested: false
100
+ # max_properties: 10
101
+ #
102
+ # PropertyUnits:
103
+ # enabled: true
104
+ # global: [
105
+ # 'ch', 'em', 'ex', 'rem', # Font-relative lengths
106
+ # 'cm', 'in', 'mm', 'pc', 'pt', 'px', 'q', # Absolute lengths
107
+ # 'vh', 'vw', 'vmin', 'vmax', # Viewport-percentage lengths
108
+ # 'deg', 'grad', 'rad', 'turn', # Angle
109
+ # 'ms', 's', # Duration
110
+ # 'Hz', 'kHz', # Frequency
111
+ # 'dpi', 'dpcm', 'dppx', # Resolution
112
+ # '%', # Other
113
+ # ]
114
+ # properties: {}
115
+ #
116
+ # PropertySortOrder:
117
+ # enabled: true
118
+ # ignore_unspecified: false
119
+ # separate_groups: false
120
+ #
121
+ # PropertySpelling:
122
+ # enabled: true
123
+ # extra_properties: []
124
+ #
125
+ # QualifyingElement:
126
+ # enabled: true
127
+ # allow_element_with_attribute: false
128
+ # allow_element_with_class: false
129
+ # allow_element_with_id: false
130
+ #
131
+ # SelectorDepth:
132
+ # enabled: true
133
+ # max_depth: 3
134
+ #
135
+ # SelectorFormat:
136
+ # enabled: true
137
+ # convention: hyphenated_lowercase # or 'strict_BEM', or 'hyphenated_BEM', or 'snake_case', or 'camel_case', or a regex pattern
138
+ #
139
+ # Shorthand:
140
+ # enabled: true
141
+ # allowed_shorthands: [1, 2, 3]
142
+ #
143
+ # SingleLinePerProperty:
144
+ # enabled: true
145
+ # allow_single_line_rule_sets: true
146
+ #
147
+ # SingleLinePerSelector:
148
+ # enabled: true
149
+ #
150
+ # SpaceAfterComma:
151
+ # enabled: true
152
+ #
153
+ # SpaceAfterPropertyColon:
154
+ # enabled: true
155
+ # style: one_space # or 'no_space', or 'at_least_one_space', or 'aligned'
156
+ #
157
+ # SpaceAfterPropertyName:
158
+ # enabled: true
159
+ #
160
+ # SpaceBeforeBrace:
161
+ # enabled: true
162
+ # style: space # or 'new_line'
163
+ # allow_single_line_padding: false
164
+ #
165
+ # SpaceBetweenParens:
166
+ # enabled: true
167
+ # spaces: 0
168
+ #
169
+ # StringQuotes:
170
+ # enabled: true
171
+ # style: single_quotes # or double_quotes
172
+ #
173
+ # TrailingSemicolon:
174
+ # enabled: true
175
+ #
176
+ # TrailingZero:
177
+ # enabled: false
178
+ #
179
+ # UnnecessaryMantissa:
180
+ # enabled: true
181
+ #
182
+ # UnnecessaryParentReference:
183
+ # enabled: true
184
+ #
185
+ # UrlFormat:
186
+ # enabled: true
187
+ #
188
+ # UrlQuotes:
189
+ # enabled: true
190
+ #
191
+ # VariableForProperty:
192
+ # enabled: false
193
+ # properties: []
194
+ #
195
+ # VendorPrefix:
196
+ # enabled: true
197
+ # identifier_list: base
198
+ # additional_identifiers: []
199
+ # excluded_identifiers: []
200
+ #
201
+ # ZeroUnit:
202
+ # enabled: true
203
+ #
204
+ # Compass::*:
205
+ # enabled: false