react_on_rails 2.0.0.rc.3 → 2.0.0.rc.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f249c2ba093b9c1f2099bb6b5d9be21c932023e1
4
- data.tar.gz: 8fa0f6dae77949df12cdaea2d4e5bfe176e68bd6
3
+ metadata.gz: 00b3529c45b04826cc9f06735e62276563ddce94
4
+ data.tar.gz: 04d6beee91a23ebaba8161a828b5f1d8e20f34f5
5
5
  SHA512:
6
- metadata.gz: 8217b7fa116f964384bcecfb176eeb9036ad990da12d545ec8a2d52d3bc36f0be9edf73b23d3311962748ab72f4f75dc6f41e9e99d4d6bc547785baa3751f079
7
- data.tar.gz: 7d5ce3efd0ada7e7d9b722c6fb14e7cfa89466db9c58d95ff5773a7a6a929cf834ef95864749e080092878de8e50ce11de6974a10be8f93c9f278928730d7400
6
+ metadata.gz: 8d5d6aedc821b9ac2f7e3f53d1764413d7d42fdb48480edfa0833720bf3392075b8e228c697fd1caee841eebfca269bc793113b6775089728083c2aed15e86c1
7
+ data.tar.gz: f9944838c5cf645e5d00f19bf4846907572164428e89ec64b1afe9f75a6162ce43fd9a300be360f31134675455cea41248540e0cbf32405952cf875cd9a669b6
data/CHANGELOG.md CHANGED
@@ -39,6 +39,17 @@ All notable changes to this project will be documented in this file. Items under
39
39
  - JS Linter uses ShakaCode JavaScript style: https://github.com/shakacode/style-guide-javascript
40
40
  - Generators account these differences.
41
41
 
42
+ ### Migration Steps
43
+ [Example of upgrading](https://github.com/shakacode/react-webpack-rails-tutorial/commit/5b1b8698e8daf0f0b94e987740bc85ee237ef608)
44
+
45
+ 1. Update the `react_on_rails` gem
46
+ 2. Search you app for 'generator_function' and remove lines in layouts and rb files that contain it. Determination of a generator function is handled automatically.
47
+ 3. Find your files where you registered client and server globals, and use the new ReactOnRails.register syntax. Optionally rename the files `clientRegistration.jsx` and `serverRegistration.jsx` rather than `Globals`.
48
+ 4. Update your index.jade to use the new API `ReactOnRails.render("MyApp", !{props}, 'app');`
49
+ 5. Update your webpack files per the example commit. Remove globally exposing React and ReactDom, as well as their inclusion in the `entry` section. These are automatically included now.
50
+
51
+ That's it!
52
+
42
53
  ## v1.2.2
43
54
  ### Fixed
44
55
  - Missing Lodash from generated package.json [#175](https://github.com/shakacode/react_on_rails/pull/175)
@@ -21,3 +21,49 @@ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-multi
21
21
  Heroku will now be able to use the multiple buildpacks specified in `.buildpacks`.
22
22
 
23
23
  Note, an alternative approach is to use the [Heroku Toolbelt to set buildpacks](https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app).
24
+
25
+ ## Fresh Rails Install
26
+
27
+ ### Swap out sqlite for postgres by doing the following:
28
+
29
+ 1. Delete the line with `sqlite` and replace it with:
30
+
31
+ ```ruby
32
+ gem 'pg'
33
+ ```
34
+
35
+ 2. Replace your `database.yml` file with this (assuming your app name is "ror")
36
+
37
+ ```yml
38
+ default: &default
39
+ adapter: postgresql
40
+ username:
41
+ password:
42
+ host: localhost
43
+
44
+ development:
45
+ <<: *default
46
+ database: ror_development
47
+
48
+ # Warning: The database defined as "test" will be erased and
49
+ # re-generated from your development database when you run "rake".
50
+ # Do not set this db to the same as development or production.
51
+ test:
52
+ <<: *default
53
+ database: ror_test
54
+
55
+ production:
56
+ <<: *default
57
+ database: ror_production
58
+ ```
59
+
60
+ Run:
61
+
62
+ ```
63
+ bundle
64
+ bin/rake db:migrate
65
+ bin/rake db:setup
66
+ ```
67
+
68
+
69
+
@@ -74,7 +74,7 @@ module.exports = {
74
74
  //libraryTarget: 'this',
75
75
  },
76
76
  resolve: {
77
- extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx', 'config.js'],
77
+ extensions: ['', '.js', '.jsx'],
78
78
  },
79
79
  module: {
80
80
  loaders: [
@@ -58,7 +58,7 @@ You can disable all rules for a line or block, or only specific rules, as shown
58
58
 
59
59
  * [Configuring ESLint](http://eslint.org/docs/user-guide/configuring.html#configuring-rules)
60
60
  * [ESLint quick start](http://untilfalse.com/eslint-quick-start/)
61
- * [RuboCop][https://github.com/bbatsov/rubocop]
62
- * [ESLint][http://eslint.org/]
63
- * [JSCS][https://github.com/jscs-dev/node-jscs]
61
+ * [RuboCop](https://github.com/bbatsov/rubocop)
62
+ * [ESLint](http://eslint.org/)
63
+ * [JSCS](https://github.com/jscs-dev/node-jscs)
64
64
 
@@ -6,26 +6,18 @@ This document describes the coding style of [ShakaCode](http://www.shakacode.com
6
6
  * Anything additional goes next.
7
7
 
8
8
  ## Client Side JavaScript and React
9
- * Use [Redux](https://github.com/rackt/redux) for your flux store.
10
- * Use [Lodash](https://lodash.com/) rather than Underscore.
11
- * Place all JavaScript for the client app in `/client`
12
- * Organize your app into high level domains which map to JavaScript bundles. These are like mini-apps that live within your entire app. Create directories named like `/client/app/<bundle>` and configure Webpack to generate different corresponding bundles.
13
- * Carefully organize your React components into [Smart and Dumb Components](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.ygdkh1l7b):
14
- 1. "dumb" components that live in the `/client/app/<bundle>/components/` directories. These components should take props, including values and callbacks, and should not talk directly to Redux or any AJAX endpoints.
15
- 2. "smart" components that live in the `/client/app/<bundle>/containers/` directory. These components will talk to the Redux store and AJAX endpoints.
16
- * Place common code shared across bundles in `/client/app/libs` and configure Webpack to generate a common bundle for this one.
17
- * Prefix Immutable.js variable names and properties with `$$`. By doing this, you will clearly know that you are dealing with an Immutable.js object and not a standard JavaScript Object or Array.
18
- * Use ES6 classes rather than `React.createClass`.
19
- * Bind callbacks passed to react components with `_.bindAll` in the constructor unless you need to bind additional parameters. In that case, you can call `_.bind` within the rendering.
9
+ * See the [Shakacode JavaScript Style Guide](https://github.com/shakacode/style-guide-javascript)
20
10
 
21
11
  ## Style Guides to Follow
22
12
  Follow these style guidelines per the linter configuration. Basically, lint your code and if you have questions about the suggested fixes, look here:
23
13
 
24
14
  ### Ruby Coding Standards
25
- * [RailsOnMaui Ruby Coding Standards](https://github.com/justin808/ruby)
15
+ * [ShakaCode Ruby Coding Standards](https://github.com/shakacode/style-guide-ruby)
26
16
  * [Ruby Documentation](http://guides.rubyonrails.org/api_documentation_guidelines.html)
27
17
 
28
18
  ### JavaScript Coding Standards
19
+ * [ShakaCode Javascript](https://github.com/shakacode/style-guide-javascript)
20
+ * Use the [eslint-config-shakacode](https://github.com/shakacode/style-guide-javascript/tree/master/packages/eslint-config-shakacode) npm package with eslint.
29
21
  * [AirBnb Javascript](https://github.com/airbnb/javascript)
30
22
  * [JSDoc](http://usejsdoc.org/)
31
23
 
data/docs/rails3.md ADDED
@@ -0,0 +1,7 @@
1
+ # Rails 3
2
+
3
+ Please let us know if you find any issues with Rails 3.
4
+
5
+ ## Known Issues
6
+
7
+ 1. If you do not skip bootstrap for the generator, you cannot generate a working app, as bootstrap-sass does not not support Rails 3, or at least the version we're using.
@@ -0,0 +1,210 @@
1
+ I just released RC3 of [React On Rails](https://github.com/shakacode/react_on_rails/tree/npm-react-on-rails-js). Here's a tiny tutorial to get you started. This tutorial setups up a new Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering.
2
+
3
+ You can find:
4
+
5
+ * [Source code for this sample app](https://github.com/justin808/test-react-on-rails-3)
6
+ * [Live on Heroku](https://shakacode-react-on-rails.herokuapp.com/hello_world)
7
+
8
+ By the time you read this, the latest may have changed. Be sure to check the versions here:
9
+
10
+ * https://rubygems.org/gems/react_on_rails
11
+ * https://www.npmjs.com/package/react-on-rails
12
+
13
+ Trying out v2 is super easy, so long as you have the basic prerequisites. This includes the basics for Rails 4.x and node version 4+. I recommend `rvm` and `nvm` to install Ruby and Node.
14
+
15
+ ```
16
+ cd <directory where you want to create your new Rails app>
17
+ # any name you like
18
+ rails new test-react-on-rails-3
19
+ cd test-react-on-rails-3
20
+ # git-extras command to make a new git repo and commit everything
21
+ git setup
22
+ vim Gemfile
23
+ ```
24
+
25
+ Add this line to your Gemfile:
26
+
27
+ ```
28
+ gem 'react_on_rails', '~> 2.0.0.rc.3'
29
+ ```
30
+
31
+ <img src="http://forum.shakacode.com/uploads/default/original/1X/fb2c41941cdc2b6cdfcc563f8a837a9cf5a51cec.png" width="482" height="113">
32
+
33
+ ```
34
+ bundle
35
+ bundle exec rails generate react_on_rails:install -R -S -H -L
36
+ bundle && npm i
37
+ npm run rails-server
38
+ ```
39
+
40
+ * R => Redux
41
+ * S => Server Rendering
42
+ * H => Heroku setup
43
+ * L => Linters
44
+
45
+
46
+ Visit http://localhost:3000/hello_world and see your React On Rails app running!
47
+
48
+ ```
49
+ npm run node-server-hot
50
+ ```
51
+
52
+ <img src="http://forum.shakacode.com/uploads/default/original/1X/5bd396a7f9c0764929b693fb79eb6685ec6f62cf.png" width="470" height="499">
53
+
54
+ Visit http://localhost:4000 and see your React On Rails app running using the Webpack Dev server.
55
+
56
+ With this setup, you can make changes to your JS or CSS and the browser will hot reload the changes (no page refresh required).
57
+
58
+ I'm going to add this line to:
59
+
60
+ ```html
61
+ <h1>Welcome to React On Rails!</h1>
62
+ ```
63
+
64
+ <img src="http://forum.shakacode.com/uploads/default/original/1X/d20719a52541e95ddd968a95192d3247369c3bf6.png" width="498" height="500">
65
+
66
+ If you save, you'll soon see this screen:
67
+
68
+ <img src="http://forum.shakacode.com/uploads/default/original/1X/228706a99a411548a4539f72446d3f115ed36f95.png" width="555" height="500">
69
+
70
+
71
+ If you're motivated to try the linting setup, you'll want to run the following commands:
72
+
73
+ bin/rake lint
74
+
75
+ You'll see a few rubocop errors.
76
+
77
+ rubocop -a
78
+
79
+ That will fix almost all the errors. However, the linter setup expects you to have rspec (small bug currently). These two commands address that issue:
80
+
81
+ ```
82
+ rm -rf test
83
+ mkdir spec
84
+ ```
85
+
86
+ bin/rake lint
87
+
88
+ The edit `application.scss`. Delete the comment at the top.
89
+
90
+ bin/rake lint
91
+
92
+ You should see
93
+
94
+ ```
95
+ bin/rake lint
96
+
97
+ Running via Spring preloader in process 26674
98
+ Running Rubocop Linters via `rubocop -S -D .`
99
+ rubocop -S -D .
100
+ Warning: Deprecated pattern style '/Users/justin/scratch/test-react-on-rails-3/client/node_modules/**/*' in /Users/justin/scratch/test-react-on-rails-3/.rubocop.yml
101
+ Inspecting 22 files
102
+ ......................
103
+
104
+ 22 files inspected, no offenses detected
105
+ Running ruby-lint Linters via `ruby-lint app config spec lib`
106
+ ruby-lint app config spec lib
107
+ scss-lint found no lints
108
+ Running eslint via `cd client && npm run eslint . -- --ext .jsx,.js`
109
+ cd client && npm run eslint . -- --ext .jsx,.js
110
+
111
+ > react-webpack-rails-tutorial@1.1.0 eslint /Users/justin/scratch/test-react-on-rails-3/client
112
+ > eslint --ext .js,.jsx . "." "--ext" ".jsx,.js"
113
+
114
+ Running jscs via `cd client && npm run jscs .`
115
+ cd client && npm run jscs .
116
+
117
+ > react-webpack-rails-tutorial@1.1.0 jscs /Users/justin/scratch/test-react-on-rails-3/client
118
+ > jscs --verbose . "."
119
+
120
+ Completed running all JavaScript Linters
121
+ Completed all linting
122
+ ```
123
+
124
+ ## RubyMine
125
+
126
+ It's super important to exclude certain directories from RubyMine or else it will slow to a crawl as it tries to parse all the npm files.
127
+
128
+ * `app/assets/javascripts/generated`
129
+ * `client/node_modules`
130
+
131
+ <img src="http://forum.shakacode.com/uploads/default/original/1X/a1b3e1146d86915f7d5d1c89548e81ec208458cc.png" width="338" height="500">
132
+
133
+
134
+ ## Deploying to Heroku
135
+
136
+ ### Create Your Heroku App
137
+ *Assuming you can login to heroku.com and have logged into to your shell for heroku.*
138
+
139
+ 1. Visit https://dashboard.heroku.com/new and create an app, say named `my-name-react-on-rails`:
140
+
141
+ <img src="http://forum.shakacode.com/uploads/default/original/1X/2d1b6abc40eef8e411e84d2679de91353f617567.png" width="690" height="319">
142
+
143
+ Run this command that looks like this from your new heroku app
144
+
145
+ heroku git:remote -a my-name-react-on-rails
146
+
147
+ Set the correct buildpack for using react-on-rails:
148
+
149
+ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-multi
150
+
151
+
152
+ ### Swap out sqlite for postgres by doing the following:
153
+
154
+ 1. Delete the line with `sqlite` and replace it with:
155
+
156
+ ```ruby
157
+ gem 'pg'
158
+ ```
159
+
160
+ 2. Replace your `database.yml` file with this (assuming your app name is "ror").
161
+
162
+ ```yml
163
+ default: &default
164
+ adapter: postgresql
165
+ username:
166
+ password:
167
+ host: localhost
168
+
169
+ development:
170
+ <<: *default
171
+ database: ror_development
172
+
173
+ # Warning: The database defined as "test" will be erased and
174
+ # re-generated from your development database when you run "rake".
175
+ # Do not set this db to the same as development or production.
176
+ test:
177
+ <<: *default
178
+ database: ror_test
179
+
180
+ production:
181
+ <<: *default
182
+ database: ror_production
183
+ ```
184
+
185
+ Then you need to setup postgres so you can run locally:
186
+
187
+ ```
188
+ bundle
189
+ bin/rake db:migrate
190
+ bin/rake db:setup
191
+ ```
192
+
193
+ I'd recommend adding this line to the top of your `routes.rb`. That way, your root page will go to the Hello World page for React On Rails.
194
+
195
+ ```ruby
196
+ root "hello_world#index"
197
+ ```
198
+
199
+ You can see the changes [here on github](https://github.com/justin808/test-react-on-rails-3/commit/09909433c186566a53f611e8b1cfeca3238f5266).
200
+
201
+ Then push your app to Heroku!
202
+
203
+ git push heroku master
204
+
205
+ Here's mine:
206
+
207
+ * [Source code for this sample app](https://github.com/justin808/test-react-on-rails-3)
208
+ * [Live on Heroku](https://shakacode-react-on-rails.herokuapp.com/hello_world)
209
+
210
+ Feedback is greatly appreciated! As are stars on github!
data/lib/generators/USAGE CHANGED
@@ -94,6 +94,23 @@ are such that the default is for the flag to be off. For example, the default fo
94
94
 
95
95
  We really love using all the linters! Give them a try.
96
96
 
97
+ *******************************************************************************
98
+
99
+ After running the generator, you will want to:
100
+
101
+ bundle && npm i
102
+
103
+ Then you may run
104
+
105
+ npm run
106
+
107
+ And you will see several useful commands:
108
+
109
+ node-server-hot
110
+ echo 'visit http://localhost:4000' && cd client && npm start
111
+ rails-server
112
+ echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev
113
+
97
114
  More Details:
98
115
 
99
116
  `https://github.com/shakacode/react_on_rails#generator`
@@ -52,11 +52,7 @@ module ReactOnRails
52
52
 
53
53
  application_scss = File.join(destination_root, "app/assets/stylesheets/application.scss")
54
54
 
55
- if File.exist?(application_scss)
56
- append_to_file(application_scss, data)
57
- else
58
- GeneratorMessages.add_error(setup_file_error(application_scss, data))
59
- end
55
+ append_to_file(application_scss, data)
60
56
  end
61
57
 
62
58
  def strip_application_scss_of_incompatible_sprockets_statements
@@ -16,8 +16,6 @@ module.exports = {
16
16
  vendor: [
17
17
  'babel-polyfill',
18
18
  'jquery',
19
- 'react',
20
- 'react-dom',
21
19
  ],
22
20
 
23
21
  // This will contain the app entry points defined by webpack.hot.config and webpack.rails.config
@@ -26,7 +24,7 @@ module.exports = {
26
24
  ],
27
25
  },
28
26
  resolve: {
29
- extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx', '.scss', '.css', 'config.js'],
27
+ extensions: ['', '.js', '.jsx'],
30
28
  alias: {
31
29
  lib: path.join(process.cwd(), 'app', 'lib'),
32
30
  react: path.resolve('./node_modules/react'),
@@ -34,7 +32,6 @@ module.exports = {
34
32
  },
35
33
  },
36
34
  plugins: [
37
-
38
35
  new webpack.DefinePlugin({
39
36
  'process.env': {
40
37
  NODE_ENV: JSON.stringify(nodeEnv),
@@ -25,8 +25,19 @@ config.entry.vendor.push('jquery-ujs');
25
25
 
26
26
  // See webpack.common.config for adding modules common to both the webpack dev server and rails
27
27
  config.module.loaders.push(
28
- { test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/ },
29
- { test: require.resolve('react'), loader: 'imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham' }
28
+ {
29
+ test: /\.jsx?$/,
30
+ loader: 'babel-loader',
31
+ exclude: /node_modules/,
32
+ },
33
+ {
34
+ test: require.resolve('react'),
35
+ loader: 'imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham',
36
+ },
37
+ {
38
+ test: require.resolve('jquery-ujs'),
39
+ loader: 'imports?jQuery=jquery',
40
+ }
30
41
  );
31
42
 
32
43
  module.exports = config;
@@ -10,9 +10,8 @@
10
10
  "scripts": {
11
11
  "postinstall": "cd client && npm install",
12
12
  "test": "rspec && (cd client && npm run lint)",
13
- "node-server-hot": "cd client && npm start",
14
- "rails-server-hot": "foreman start -f Procfile.dev-hot",
15
- "rails-server": "foreman start -f Procfile.dev"
13
+ "node-server-hot": "echo 'visit http://localhost:4000' && cd client && npm start",
14
+ "rails-server": "echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev"
16
15
  },
17
16
  "repository": {
18
17
  "type": "git",
@@ -19,7 +19,7 @@ module.exports = {
19
19
  path: '../app/assets/javascripts/generated',
20
20
  },
21
21
  resolve: {
22
- extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx', 'config.js'],
22
+ extensions: ['', '.js', '.jsx'],
23
23
  alias: {
24
24
  lib: path.join(process.cwd(), 'app', 'lib'),
25
25
  },
@@ -1,4 +1,3 @@
1
- require_relative "version_checker"
2
1
 
3
2
  module ReactOnRails
4
3
  def self.configure
@@ -6,7 +5,6 @@ module ReactOnRails
6
5
  end
7
6
 
8
7
  def self.configuration
9
- VersionChecker.warn_if_gem_and_node_package_versions_differ
10
8
  @configuration ||= Configuration.new(
11
9
  server_bundle_js_file: "app/assets/javascripts/generated/server.js",
12
10
  prerender: false,
@@ -1,6 +1,11 @@
1
+ require_relative "version_checker"
2
+
1
3
  module ReactOnRails
2
4
  class Engine < ::Rails::Engine
3
5
  config.to_prepare do
6
+ if File.exist?(VersionChecker::NodePackageVersion.package_json_path)
7
+ VersionChecker.build.warn_if_gem_and_node_package_versions_differ
8
+ end
4
9
  ReactOnRails::ServerRenderingPool.reset_pool
5
10
  end
6
11
  end
@@ -1,3 +1,3 @@
1
1
  module ReactOnRails
2
- VERSION = "2.0.0.rc.3"
2
+ VERSION = "2.0.0.rc.4"
3
3
  end
@@ -1,51 +1,85 @@
1
1
  require_relative "version"
2
2
 
3
3
  module ReactOnRails
4
- module VersionChecker
5
- # TODO: ROB
6
- # parse the client/package.json and ensure that either:
7
- # 1. version number matches
8
- # 2. version number is a relative path (for testing)
9
- # Throw error if not.
10
- # Allow skipping this check in the configuration in case somebody has a wacky configuration, such
11
- # as you don't know where their package.json
4
+ class VersionChecker
5
+ attr_reader :node_package_version, :logger
6
+
7
+ def self.build
8
+ new(NodePackageVersion.build, Rails.logger)
9
+ end
10
+
11
+ def initialize(node_package_version, logger)
12
+ @logger = logger
13
+ @node_package_version = node_package_version
14
+ end
12
15
 
13
16
  # For compatibility, the gem and the node package versions should always match, unless the user
14
17
  # really knows what they're doing. So we will give a warning if they do not.
15
- def self.warn_if_gem_and_node_package_versions_differ
16
- return unless node_package_version_is_standard_version_number? &&
17
- gem_version != node_package_version
18
- msg = "**WARNING** ReactOnRails: ReactOnRails gem and node package versions do not match\n" \
19
- " gem: #{gem_version}\n" \
20
- " node package: #{node_package_version}\n" \
21
- "Ensure the installed version of the gem is the same as the version of your installed node package"
22
- puts(msg)
23
- Rails.logger.warn(msg)
18
+ def warn_if_gem_and_node_package_versions_differ
19
+ return if node_package_version.major == gem_major_version || node_package_version.relative_path?
20
+ log_differing_versions_warning
24
21
  end
25
22
 
26
23
  private
27
24
 
28
- def self.gem_version
29
- ReactOnRails::VERSION
25
+ def log_differing_versions_warning
26
+ msg = "**WARNING** ReactOnRails: ReactOnRails gem and node package MAJOR versions do not match\n" \
27
+ " gem: #{gem_version}\n" \
28
+ " node package: #{node_package_version.raw}\n" \
29
+ "Ensure the installed MAJOR version of the gem is the same as the MAJOR version of \n"\
30
+ "your installed node package."
31
+ logger.warn(msg)
30
32
  end
31
33
 
32
- # Warning: we replace all hyphens with periods for normalization purposes
33
- def self.node_package_version
34
- return unless client_package_json.present? && File.exist?(client_package_json)
35
- contents = File.read(client_package_json)
36
- raw_version = contents.match(/"react-on-rails": "(.*)",/)[1]
37
- raw_version.tr("-", ".")
34
+ def gem_version
35
+ ReactOnRails::VERSION
38
36
  end
39
37
 
40
- def self.client_package_json
41
- return unless Rails.root.present?
42
- Rails.root.join("client", "package.json")
38
+ def gem_major_version
39
+ gem_version.match(/(\d+)\./)[1]
43
40
  end
44
41
 
45
- # Basically this means "not a relative path" as we don't want warn the user
46
- # if they are purposely doing some wacky configuration.
47
- def self.node_package_version_is_standard_version_number?
48
- node_package_version =~ (/\d+\.\d+\.\d+(\..+\.\d+)?/)
42
+ class NodePackageVersion
43
+ attr_reader :package_json
44
+
45
+ def self.build
46
+ new(package_json_path)
47
+ end
48
+
49
+ def self.package_json_path
50
+ Rails.root.join("client", "package.json")
51
+ end
52
+
53
+ def initialize(package_json)
54
+ @package_json = package_json
55
+ end
56
+
57
+ def raw
58
+ JSON.parse(package_json_contents)["dependencies"]["react-on-rails"]
59
+ end
60
+
61
+ def normalized
62
+ match = raw
63
+ .tr("-", ".")
64
+ .strip
65
+ .match(/(\d.*)/)
66
+ match.present? ? match[0] : nil
67
+ end
68
+
69
+ def relative_path?
70
+ normalized.nil? # must be a relative path if nil and we haven't failed
71
+ end
72
+
73
+ def major
74
+ return if normalized.nil?
75
+ normalized.match(/(\d+)\./)[1]
76
+ end
77
+
78
+ private
79
+
80
+ def package_json_contents
81
+ @package_json_contents ||= File.read(package_json)
82
+ end
49
83
  end
50
84
  end
51
85
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "2.0.0-rc.1",
3
+ "version": "2.0.0-rc.4",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc.3
4
+ version: 2.0.0.rc.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-10 00:00:00.000000000 Z
11
+ date: 2016-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -302,7 +302,9 @@ files:
302
302
  - docs/coding-style/style.md
303
303
  - docs/contributing.md
304
304
  - docs/generator_testing.md
305
+ - docs/rails3.md
305
306
  - docs/releasing.md
307
+ - docs/tutorial-v2.md
306
308
  - lib/generators/USAGE
307
309
  - lib/generators/react_on_rails/base_generator.rb
308
310
  - lib/generators/react_on_rails/bootstrap_generator.rb