react_webpack_rails 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9013d3d9ed832b067ef13eef2818ee979c896e96
4
- data.tar.gz: 75af140b6ce33183f6917776e5abd6ef790caa39
3
+ metadata.gz: b7b168e4c9e7963d9286b677dfda26cb75faf04f
4
+ data.tar.gz: e7c801d0011fc8a2a4ae35dbf1b35af41b4ab4de
5
5
  SHA512:
6
- metadata.gz: fad1735106799d939a82f8d0eae96697d529eb60647df587bdb92d4399c752d44d079ac336c8480db3538601861bce6f47983e2cdde443207ad739c49b527323
7
- data.tar.gz: 2b2debfff85637619d44659abd999efd30ddc437131c66eb50734d4d9201c56c954f3bfbe0d22ab469f9a0c2cc1037de796949ccca3688187d6f026363e6d189
6
+ metadata.gz: d89a10bb7c891f157a382fbb6c6865043ff142db3094ee6cea4ca714c990ca2af203d2ed62252677891d64683fa1ac3f57ad7644ada1eb37019a7817b21a023f
7
+ data.tar.gz: 711c3ce95858e08945893afc8e13d5068cbef85bcf13b08fa65ad63da40b2f10e488c96f1b0ca5a0ebaff0a2e839b72fb210250f7f90b20be13ea3690ec9d216
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.3.0
2
+ * move integration with react-router to external plugin: https://github.com/netguru/rwr-react_router
3
+ * add redux integration by external plugin: https://github.com/netguru/rwr-redux
4
+ * support haml and coffee script in generator
5
+
1
6
  ## 0.2.1
2
7
  * Fix Readme typo
3
8
  * Fix json loader in generator
@@ -63,7 +68,7 @@ $ rails generate react_webpack_rails:install:server_side
63
68
 
64
69
  ```
65
70
  $ npm i --save-dev babel-core@^6.0.0 babel-loader@^6.0.0 babel-preset-stage-1@^6.0.0 babel-preset-react@^6.0.0 babel-preset-es2015@^6.0.0
66
- ```
71
+ ```
67
72
 
68
73
  4. Update babel config file (we use stage-1).
69
74
 
data/README.md CHANGED
@@ -4,6 +4,9 @@
4
4
  #### Rails - Webpack setup with React integration.
5
5
  This gem provides easy and convenient way to build modern JavaScript stack on top of Rails applications using [Webpack](http://webpack.github.io/) and [React](https://facebook.github.io/react/).
6
6
 
7
+ ### Development branch!
8
+ See [0.3-stable](https://github.com/netguru/react_webpack_rails/tree/0.3-stable) for latest release.
9
+
7
10
  ## Features
8
11
  * [Install Generator](https://github.com/netguru/react_webpack_rails/blob/master/docs/install_generator.md) for quick [Webpack](http://webpack.github.io/) setup.
9
12
  * Integrated [react-hot-loader](https://github.com/gaearon/react-hot-loader)
@@ -12,6 +15,10 @@ This gem provides easy and convenient way to build modern JavaScript stack on to
12
15
  * [React](https://facebook.github.io/react/) integration with server prerender option.
13
16
  * [React-router](https://github.com/rackt/react-router) integration.
14
17
 
18
+ ### Plugins:
19
+ * [rwr-alt](https://github.com/netguru/rwr-alt) plugin that makes it possible to populate and share Alt stores between react component located in different parts of rails views.
20
+ * [rwr-redux](https://github.com/netguru/rwr-redux) allows to use redux state containers in a rails views.
21
+
15
22
  ## Installation
16
23
 
17
24
  Add this line to your application's Gemfile:
@@ -28,44 +35,13 @@ Then run installation:
28
35
 
29
36
  $ rails g react_webpack_rails:install
30
37
 
31
- This will create following files:
38
+ *read more about [install generator](https://github.com/netguru/react_webpack_rails/blob/master/docs/install_generator.md) here*
32
39
 
33
- ```
34
- ├── app
35
- │ ├── react
36
- │ │ ├── components
37
- │ │ │ ├── hello-world.jsx
38
- │ │ │ └── hello-world-test.jsx
39
- │ │ └── index.js
40
- │ ├── views
41
- │ │ └── layouts
42
- │ │ └── _react_hot_assets.html.erb
43
- │ └── assets
44
- │ └── javascripts
45
- │ └──react_bundle.js
46
- ├── webpack
47
- │ ├── dev.config.js
48
- │ ├── hot-dev.config.js
49
- │ ├── production.config.js
50
- │ └── tests.config.js
51
- ├── .babelrc
52
- ├── karma.conf.js
53
- ├── package.json
54
- └── webpack.config.js
55
- ```
56
40
 
57
41
  Establish the node packages (may take a few moments)
58
42
 
59
43
  $ npm install # you may see warnings to consider updating the provided package.json file with license and repository
60
44
 
61
- Make sure you have [webpack](https://webpack.github.io/docs/installation.html) installed globally:
62
-
63
- $ npm install webpack -g
64
-
65
- Generate `react_bundle` for first time:
66
-
67
- $ webpack
68
-
69
45
  And require integration and bundle files in `application.js`
70
46
 
71
47
  ```js
@@ -122,19 +98,18 @@ Run webpack in hot-auto-reloading mode using script (to use it you have to add `
122
98
 
123
99
  $ npm run start-hot-dev
124
100
 
125
- Or manually:
126
-
127
- $ webpack -w --config YOUR_CONFIG
101
+ If you are using server side render in components *(it's enabled by default in generated example)*, run node server:
128
102
 
103
+ $ npm run rwr-node-dev-server
129
104
 
130
105
  ### Production environment
131
106
  Run webpack in production mode before compiling assets using script:
132
107
 
133
108
  $ npm run build
134
109
 
135
- or manually:
110
+ If you are using server side render *(it's enabled by default in generated example)*, run node server:
136
111
 
137
- $ webpack -p --config YOUR_CONFIG
112
+ $ npm run rwr-node-server
138
113
 
139
114
  #### Deployment
140
115
  Check [docs/deployment.md](docs/deployment.md)
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ namespace :test do
14
14
 
15
15
  desc 'Run gem tests'
16
16
  task :gem do
17
- sh %Q(bundle exec rspec spec/react_webpack_rails_spec.rb)
17
+ sh %Q(bundle exec rspec spec/react_webpack_rails_spec.rb spec/react_webpack_rails)
18
18
  end
19
19
 
20
20
  desc 'Run rspec for rails3 application'
@@ -1,4 +1,4 @@
1
- Instlall Generator
1
+ Install Generator
2
2
  =======
3
3
 
4
4
  `Install` generator is build from 6 independent generators responsible for different parts of installation process. All steps except core generator can be skipped by passing one of possible [options]().
@@ -50,6 +50,6 @@ And modify:
50
50
  * *--no-hot-reload* - skip hot_reload generator
51
51
  * *--no-server-side* - skip server_side generator
52
52
  * *--no-karma-setup* - skip karma_setup generator
53
- * *--react-router* - run react_rotuer generator
53
+ * *--react-router* - run react_rotuer generator [DEPRECIATED since v0.3.0 - use [rwr-react_router](https://github.com/netguru/rwr-react_router) instead]
54
54
 
55
55
  *Detailed description of generators coming soon...*
@@ -21,7 +21,7 @@ To set the node server address, override this option to a string of your choice:
21
21
  <%# A view in erb %>
22
22
  <%= react_component('HelloWorld', { name: @name }, server_side: true) %>
23
23
  ```
24
- `HelloWorld` is the name of the react component, which has to be `import`ed and `registered`ed in your `app/react/index.js` like so:
24
+ `HelloWorld` is the name of the react component, which has to be `import`ed and `register`ed in your `app/react/index.js` like so:
25
25
  ```js
26
26
  import HelloWorld from './components/hello-world';
27
27
  RWR.registerComponent('HelloWorld', HelloWorld);
@@ -1,5 +1,16 @@
1
1
  import ReactDOM from 'react-dom';
2
2
 
3
+ function deprecationWarning() {
4
+ if (typeof console !== 'undefined' && console.warn) {
5
+ const msg = [
6
+ 'Deprecation warning - since v0.3.0: current integration with react-router was extracted and moved to external plugin.',
7
+ 'Use https://github.com/netguru/rwr-react_router instead.'
8
+ ]
9
+
10
+ console.warn(msg.join('\n'));
11
+ }
12
+ }
13
+
3
14
  class ReactRouterIntegration {
4
15
  constructor() {
5
16
  this.routers = {};
@@ -7,6 +18,7 @@ class ReactRouterIntegration {
7
18
  this.registerRouter = this.registerRouter.bind(this);
8
19
  this.getRouter = this.getRouter.bind(this);
9
20
  this.renderRouter = this.renderRouter.bind(this);
21
+ deprecationWarning();
10
22
  }
11
23
 
12
24
  registerRouter(name, route) {
data/js/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '0.2.1';
1
+ export default '0.3.0';
@@ -13,6 +13,7 @@ module ReactWebpackRails
13
13
  def base
14
14
  copy_file '.babelrc', '.babelrc'
15
15
  create_file 'app/assets/javascripts/react_bundle.js'
16
+ require_bundles_in_application_js
16
17
  template 'react/index.js', 'app/react/index.js'
17
18
  end
18
19
 
@@ -42,6 +43,42 @@ module ReactWebpackRails
42
43
  copy_file 'webpack/dev.config.js', 'webpack/dev.config.js'
43
44
  copy_file 'webpack/production.config.js', 'webpack/production.config.js'
44
45
  end
46
+
47
+ private
48
+
49
+ def require_bundles_in_application_js
50
+ manifest_file = Dir.glob('app/assets/javascripts/application.*').first
51
+
52
+ case manifest_file
53
+ when /.*\.coffee(\.erb)?$/
54
+ requires = <<-REQUIRE_STRING.strip_heredoc
55
+ #= require react_integration
56
+ #= require react_bundle
57
+ REQUIRE_STRING
58
+
59
+ return if inject_into_file manifest_file, requires, before: '#= require_tree .'
60
+ append_to_file manifest_file, requires
61
+ when /.*\.js(\.erb)?$/
62
+ requires = <<-REQUIRE_STRING.strip_heredoc
63
+ //= require react_integration
64
+ //= require react_bundle
65
+ REQUIRE_STRING
66
+
67
+ inject_into_file manifest_file, requires, before: '//= require_tree .'
68
+ append_to_file manifest_file, requires
69
+ else
70
+ manifest_info = <<-NO_MANIFEST.strip_heredoc
71
+ Missing manifest?
72
+
73
+ Javascript manifest (normally application.js) could not be found.
74
+ Please require following files in your manifest file:
75
+ react_integration
76
+ react_bundle
77
+
78
+ NO_MANIFEST
79
+ say_status(:not_found, manifest_info, :red)
80
+ end
81
+ end
45
82
  end
46
83
  end
47
84
  end
@@ -23,10 +23,23 @@ module ReactWebpackRails
23
23
 
24
24
  def partial
25
25
  copy_file 'partial/_react_hot_assets.html.erb', 'app/views/layouts/_react_hot_assets.html.erb'
26
+ settings = template_language_settings("render 'layouts/react_hot_assets'")
26
27
 
27
- inject_into_file 'app/views/layouts/application.html.erb', after: "<body>\n" do <<-'HTML'.strip_heredoc
28
- <%= render 'layouts/react_hot_assets' %>
29
- HTML
28
+ inject_into_file settings[:layout_file], settings[:parsed_command], after: "#{settings[:body_tag]}\n"
29
+ end
30
+
31
+ private
32
+
33
+ def template_language_settings(command)
34
+ layout_file = Dir.glob('app/views/layouts/application.*').first
35
+
36
+ case File.extname(layout_file)
37
+ when '.slim'
38
+ return { layout_file: layout_file, body_tag: 'body', parsed_command: " = #{command}\n" }
39
+ when '.haml'
40
+ return { layout_file: layout_file, body_tag: '%body', parsed_command: " = #{command}\n" }
41
+ else
42
+ return { layout_file: layout_file, body_tag: '<body>', parsed_command: "<%= #{command} %>\n" }
30
43
  end
31
44
  end
32
45
  end
@@ -52,6 +52,7 @@ module ReactWebpackRails
52
52
 
53
53
  def generate_react_router
54
54
  return unless options.react_router
55
+ deprecation_warning
55
56
  generate 'react_webpack_rails:install:react_router --tmp_package'
56
57
  end
57
58
 
@@ -62,5 +63,17 @@ module ReactWebpackRails
62
63
  def cleanup
63
64
  remove_file('tmp/package.json')
64
65
  end
66
+
67
+ private
68
+
69
+ def deprecation_warning
70
+ message = [
71
+ "\nDEPRECATION WARNING - since v0.3.0:",
72
+ "current integration with react-router was extracted and moved to external plugin.",
73
+ "Use https://github.com/netguru/rwr-react_router instead.\n\n",
74
+ ]
75
+
76
+ warn message.join("\n")
77
+ end
65
78
  end
66
79
  end
@@ -16,7 +16,7 @@
16
16
  "node-sass": "^3.3.3",
17
17
  "react": "^0.14.0",
18
18
  "react-dom": "^0.14.0",
19
- "react-webpack-rails": "^0.2.1",
19
+ "react-webpack-rails": "^0.3.0",
20
20
  "sass-loader": "^3.0.0",
21
21
  "webpack": "^1.12.1"
22
22
  },
@@ -6,4 +6,5 @@ if defined?(Rails)
6
6
  require 'react_webpack_rails/node_integration_runner'
7
7
  require 'react_webpack_rails/errors/base'
8
8
  require 'react_webpack_rails/errors/node_failure'
9
+ require 'react_webpack_rails/services'
9
10
  end
@@ -0,0 +1 @@
1
+ require 'react_webpack_rails/services/camelize_keys'
@@ -0,0 +1,13 @@
1
+ module ReactWebpackRails
2
+ module Services
3
+ class CamelizeKeys
4
+ def self.call(props)
5
+ return props unless props.is_a?(Hash)
6
+ props.inject({}) do |h, (k, v)|
7
+ h[k.to_s.camelize(:lower)] = v.is_a?(Hash) ? self.call(v) : v
8
+ h
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module ReactWebpackRails
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,3 +1,5 @@
1
+ require_relative 'services/camelize_keys'
2
+
1
3
  module ReactWebpackRails
2
4
  module ViewHelpers
3
5
  def react_element(integration_name, payload = {}, html_options = {}, &block)
@@ -13,7 +15,7 @@ module ReactWebpackRails
13
15
 
14
16
  def react_component(name, raw_props = {}, options = {})
15
17
  props = raw_props.as_json
16
- props = camelize_props_key(props) if Rails.application.config.react.camelize_props
18
+ props = Services::CamelizeKeys.call(props) if Rails.application.config.react.camelize_props
17
19
  if server_side(options.delete(:server_side))
18
20
  result = NodeIntegrationRunner.new('react-component', props: props, name: name).run
19
21
  react_element('react-component', { props: props, name: name }, options) do
@@ -25,21 +27,24 @@ module ReactWebpackRails
25
27
  end
26
28
 
27
29
  def react_router(name)
30
+ deprecation_warning
28
31
  react_element('react-router', name: name)
29
32
  end
30
33
 
31
34
  private
32
35
 
33
- def camelize_props_key(props)
34
- return props unless props.is_a?(Hash)
35
- props.inject({}) do |h, (k, v)|
36
- h[k.to_s.camelize(:lower)] = v.is_a?(Hash) ? camelize_props_key(v) : v
37
- h
38
- end
39
- end
40
-
41
36
  def server_side(server_side)
42
37
  server_side.nil? ? Rails.application.config.react.server_side : server_side
43
38
  end
39
+
40
+ def deprecation_warning
41
+ message = [
42
+ "\nDEPRECATION WARNING - since v0.3.0:",
43
+ "current integration with react-router was extracted and moved to external plugin.",
44
+ "Use https://github.com/netguru/rwr-react_router instead.\n\n",
45
+ ]
46
+
47
+ warn message.join("\n")
48
+ end
44
49
  end
45
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_webpack_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafał Gawlik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-02-22 00:00:00.000000000 Z
12
+ date: 2016-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -146,6 +146,8 @@ files:
146
146
  - lib/react_webpack_rails/node_integration_runner.rb
147
147
  - lib/react_webpack_rails/railtie.rb
148
148
  - lib/react_webpack_rails/react_component_renderer.rb
149
+ - lib/react_webpack_rails/services.rb
150
+ - lib/react_webpack_rails/services/camelize_keys.rb
149
151
  - lib/react_webpack_rails/version.rb
150
152
  - lib/react_webpack_rails/view_helpers.rb
151
153
  - package.json