react_webpack_rails 0.0.2 → 0.0.3

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: 23e61ad851d49804d84cff1615b14aa4ddec2ba8
4
- data.tar.gz: 0adf9b76662d547ae6e2c22de4d117ce129669cd
3
+ metadata.gz: e5c7c1e774861da4a8dd6be317a5f624bb1d8f2e
4
+ data.tar.gz: 5f26add913b827882a39f459ca6546f16b4483e0
5
5
  SHA512:
6
- metadata.gz: 858c4be7c690ebb7784d2caee695bae07984b3d09c428c26775a5640bd205c27c06af4692d694e09fe481876182fecd944e640641e57e74517b08a9a0afd5f14
7
- data.tar.gz: 28d0dc73a1bb691ae1062e72d9551811452dc4a48e967f5f79e179b40671da3a600590cccd5e110e47d6430073b6a58c8d06f8172ee38d6927f28d8d0fc6fe3a
6
+ metadata.gz: 55934857a674403c7fbf1215877e54ef69bc2e121f7d47ad0bcc9e8dfc03f3bf27c56f243495f13ec6f7d62d791e9348a0a9142430acdc69a3dbc5085608f7bb
7
+ data.tar.gz: bef5eef2a86dc6bca571ba6ae52b74c25ae69098ce470982b90bdc4b225cc47b2236b60aed1481b1dcad4b6a7ae8493cfdcb3460a1f19d7de57aa3d316efd7ff
data/.gitignore CHANGED
@@ -7,4 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- react_webpack_rails-0.0.1.gem
10
+ react_webpack_rails-*.gem
data/CHANGELOG.md CHANGED
@@ -1,10 +1,20 @@
1
- ## (0.0.2)
2
- * using rails like names
3
- * simplifying webpack setup
4
- * making `registerComponent` helper part of ujs,
1
+ ## 0.0.3 (September 6, 2015)
2
+ * Reorganize config files.
3
+ * Add UJS helpers:
4
+ * `getComponent`
5
+ * `createComponent`
6
+ * `renderComponent`
7
+ * Add docs.
8
+ * Add various Readme fixes.
9
+ * Bump dependencies.
10
+
11
+ ## 0.0.2 (August 29, 2015)
12
+ * Use rails like names.
13
+ * Simplify webpack setup.
14
+ * Make `registerComponent` helper part of ujs.
5
15
 
6
16
  ### migration 0.0.1 -> 0.0.2
7
- * in `application.js` replace:
17
+ * In `application.js` replace:
8
18
 
9
19
  ```js
10
20
  //= require react-integration
@@ -17,9 +27,9 @@
17
27
  //= require react_bundle
18
28
  ```
19
29
 
20
- ## (0.0.1) Initial release
21
- * generators for webpack configuration
22
- * helpers:
30
+ ## 0.0.1 Initial release (August 25, 2015)
31
+ * Add generators for webpack configuration.
32
+ * Add helpers:
23
33
  * js - `registerComponent` exposing component for rails
24
- * rails - `react_component` using component based on https://github.com/reactjs/react-rails/blob/master/lib/react/rails/view_helper.rb
25
- * integration script based on https://github.com/reactjs/react-rails/blob/master/lib/assets/javascripts/react_ujs.js.erb
34
+ * rails - `react_component` using component based on https://github.com/reactjs/react-rails/blob/master/lib/react/rails/view_helper.rb.
35
+ * Add integration script based on https://github.com/reactjs/react-rails/blob/master/lib/assets/javascripts/react_ujs.js.erb.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ReactWebpackRails
2
- #### Rails - webpack setup with react integration.
3
- Inspired and partially based on https://github.com/reactjs/react-rails/ this gem provides generators and helpers that makes rails-webpack-react integration easy.
2
+ #### Rails - Webpack setup with React integration.
3
+ Inspired and partially based on https://github.com/reactjs/react-rails/ this gem provides generators and helpers that makes react-webpack-rails integration easy.
4
4
 
5
5
  ## Installation
6
6
 
@@ -22,6 +22,28 @@ Then run installation:
22
22
 
23
23
  $ rails g react_webpack_rails:install
24
24
 
25
+ This will create following files:
26
+
27
+ ```
28
+ ├── app
29
+ │ └── react
30
+ │ ├── components
31
+ │ │ ├── hello-world.jsx
32
+ │ │ └── hello-world-test.jsx
33
+ │ └── index.js
34
+ ├── webpack
35
+ │ ├── dev.config.js
36
+ │ ├── production.config.js
37
+ │ └── tests.config.js
38
+ ├── karma.conf.js
39
+ ├── package.json
40
+ └── webpack.config.js
41
+ ```
42
+
43
+ Establish the node packages (may take a few moments)
44
+
45
+ $ npm install # you may see warnings to consider updating the provided package.json file with license and repository
46
+
25
47
  Generate `react_bundle` for first time:
26
48
 
27
49
  $ webpack
@@ -34,29 +56,45 @@ And require integration and bundle files in `application.js`
34
56
  ```
35
57
 
36
58
  ## Usage
37
- 1. Register component in index.js
59
+ ##### Check [docs](https://github.com/netguru/react_webpack_rails/tree/master/docs) for detailed api description.
60
+ #### Register component in index.js
38
61
 
39
62
  ```js
40
- import Component from 'some-component';
41
-
42
- registerComponent('customComponentName', Component)
63
+ import Component from './components/some-component';
64
+ registerComponent('customComponentName', Component);
43
65
  ```
44
66
 
45
- 2. Use it in view
67
+ #### Use it in rails view
46
68
 
47
69
  ```erb
48
- <%= react_component('customComponentName', { user: User.last })
70
+ <%= react_component('customComponentName', { user: User.last }) %>
71
+ ```
72
+
73
+ #### Use it in javascript file
74
+
75
+ ```js
76
+ const element = $('#my-element');
77
+ renderComponent('customComponentName', {user_id: 1}, element);
49
78
  ```
50
79
 
51
- #### Development
52
- Run webpack in watch mode so it will react on any file change.
80
+ ### Development
81
+ Run webpack in watch mode using script:
82
+
83
+ $ npm start
84
+
85
+ Or manually:
86
+
87
+ $ webpack -w --config YOUR_CONFIG
88
+
89
+
90
+ ### Production
91
+ Run webpack in production mode before compiling assets using script:
53
92
 
54
- webpack -w
93
+ $ npm run build
55
94
 
56
- #### Production
57
- Run webpack in production mode before compiling assets
95
+ or manually:
58
96
 
59
- webpack -p
97
+ $ webpack -p --config YOUR_CONFIG
60
98
 
61
99
  ## Development
62
100
 
data/docs/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Docs
2
+
3
+ ## UJS helpers
4
+
5
+ * ### registerComponent
6
+ ```js
7
+ registerComponent(String componentName, class|function component)
8
+ ```
9
+
10
+ Register component so it's globally accessible.
11
+
12
+ ##### example:
13
+
14
+ ```js
15
+ import MyComponent from 'my-component';
16
+
17
+ registerComponent('MyComponentName', MyComponent);
18
+ ```
19
+
20
+ **note:** Registered components are accessible in globally exposed `ReactRailsUJS` under `reactComponents` property.
21
+
22
+ * ### getComponent
23
+
24
+ ```js
25
+ getComponent(String componentName)
26
+ ```
27
+
28
+ Shortcut for accessing registered component.
29
+
30
+ ##### example:
31
+
32
+ ```js
33
+ getComponent('MyComponentName');
34
+ ```
35
+
36
+ * ### createComponent
37
+
38
+ ```js
39
+ createComponent(String componentName[, Object props])
40
+ ```
41
+
42
+ Wrapper over React.createElement that creates ready to render component with props.
43
+
44
+ ##### example:
45
+
46
+ ```js
47
+ createComponent('MyComponentName', {foo: 'bar'});
48
+ ```
49
+
50
+ * ### renderComponent
51
+
52
+ ```js
53
+ renderComponent(String componentName, Object props, DOMElement container)
54
+ ```
55
+
56
+ Wrapper over `React.render` and `React.createElement`. Renders component with given props into specified DOM element.
57
+
58
+ ##### example:
59
+
60
+ ```js
61
+ var element = document.getElementById('my-element');
62
+ renderComponent('MyComponentName', {foo: 'bar'}, element);
63
+ ```
64
+
65
+ ## Rails helpers
66
+
67
+ * ### react_component
68
+
69
+ ```ruby
70
+ react_component(String component_name[, Object props])
71
+ ```
72
+
73
+ Creates DOM node with props as data attributes in rendered view so ReactRailsUJS can grab it and mount proper component.
74
+
75
+ ##### example:
76
+
77
+ ```ruby
78
+ <%= react_component('MyComponentName', MySerializer.new(my_data)) %>
79
+ ```
80
+
81
+ **note:** Props Object will parsed to JSON. Be careful when passing rails models there - all its data accessible after `.to_json` will be exposed as data-attributes. We recommend using serializers to control it.
@@ -34,6 +34,20 @@
34
34
  window.ReactRailsUJS.reactComponents[name] = component;
35
35
  },
36
36
 
37
+ getComponent: function(name) {
38
+ return window.ReactRailsUJS.reactComponents[name];
39
+ },
40
+
41
+ createComponent: function (name, props) {
42
+ var constructor = window.ReactRailsUJS.getComponent(name);
43
+ return React.createElement(constructor, props);
44
+ },
45
+
46
+ renderComponent: function (name, props, element) {
47
+ var component = window.ReactRailsUJS.createComponent(name, props);
48
+ React.render(component, element);
49
+ },
50
+
37
51
  mountComponents: function(searchSelector) {
38
52
  var nodes = window.ReactRailsUJS._findDOMNodes(searchSelector);
39
53
 
@@ -44,7 +58,7 @@
44
58
  // Assume className is simple and can be found at top-level (window).
45
59
  // Fallback to eval to handle cases like 'My.React.ComponentName'.
46
60
 
47
- var constructor = window.ReactRailsUJS.reactComponents[className] || eval.call(window, className);
61
+ var constructor = window.ReactRailsUJS.reactComponents[className];
48
62
  var propsJson = node.getAttribute(window.ReactRailsUJS.PROPS_ATTR);
49
63
  var props = propsJson && JSON.parse(propsJson);
50
64
 
@@ -63,8 +77,11 @@
63
77
  }
64
78
  };
65
79
 
66
- // expose registerComponent globally
80
+ // expose helpers globally
67
81
  window.registerComponent = ReactRailsUJS.registerComponent;
82
+ window.getComponent = ReactRailsUJS.getComponent;
83
+ window.createComponent = ReactRailsUJS.createComponent;
84
+ window.renderComponent = ReactRailsUJS.renderComponent;
68
85
 
69
86
  // functions not exposed publicly
70
87
  function handleTurbolinksEvents () {
@@ -1,13 +1,21 @@
1
1
  module ReactWebpackRails
2
2
  class InstallGenerator < Rails::Generators::Base
3
3
  source_root File.expand_path('../templates', __FILE__)
4
+ class_option :example, type: :boolean, default: true, desc: 'Include example component and test files.'
4
5
 
5
6
  def generate_layout
6
7
  copy_file 'webpack.config.js', 'webpack.config.js'
8
+ copy_file 'webpack/dev.config.js', 'webpack/dev.config.js'
9
+ copy_file 'webpack/production.config.js', 'webpack/production.config.js'
7
10
  copy_file 'karma.conf.js', 'karma.conf.js'
8
- copy_file 'tests.webpack.js', 'tests.webpack.js'
9
- copy_file 'index.js', 'app/react/index.js'
10
- copy_file 'hello-world.jsx', 'app/react/components/hello-world.jsx'
11
+ copy_file 'webpack/tests.config.js', 'webpack/tests.config.js'
12
+ template 'react/index.js.erb', 'app/react/index.js'
13
+ if options.example
14
+ copy_file 'react/components/hello-world.jsx', 'app/react/components/hello-world.jsx'
15
+ copy_file 'react/components/hello-world-test.jsx', 'app/react/components/hello-world-test.jsx'
16
+ else
17
+ create_file 'app/react/components/.keep'
18
+ end
11
19
  template 'package.json.erb', 'package.json'
12
20
  end
13
21
 
@@ -5,8 +5,8 @@ module.exports = function (config) {
5
5
  browsers: ['Chrome'],
6
6
  singleRun: true,
7
7
  frameworks: ['mocha', 'sinon'],
8
- files: ['tests.webpack.js'],
9
- preprocessors: {'tests.webpack.js': ['webpack', 'sourcemap']},
8
+ files: ['webpack/tests.config.js'],
9
+ preprocessors: {'webpack/tests.config.js': ['webpack', 'sourcemap']},
10
10
  reporters: ['dots'],
11
11
  webpack: {
12
12
  module: {
@@ -1,30 +1,32 @@
1
1
  {
2
2
  "name": "<%="#{Rails.application.class.parent_name}"%>",
3
3
  "devDependencies": {
4
- "babel-eslint": "^4.0.5",
4
+ "babel-eslint": "^4.1.1",
5
5
  "eslint": "^0.24.1",
6
- "eslint-plugin-react": "^3.2.2",
6
+ "eslint-plugin-react": "^3.3.1",
7
7
  "expect": "^1.9.0",
8
8
  "karma": "^0.13.9",
9
9
  "karma-chrome-launcher": "^0.2.0",
10
10
  "karma-mocha": "^0.2.0",
11
11
  "karma-sinon": "^1.0.4",
12
12
  "karma-sourcemap-loader": "^0.3.5",
13
- "karma-webpack": "^1.7.0"
13
+ "karma-webpack": "^1.7.0",
14
+ "webpack-notifier": "^1.2.1"
14
15
  },
15
16
  "dependencies": {
16
17
  "babel-core": "^5.8.19",
17
18
  "babel-loader": "^5.3.2",
18
- "chart.js": "^1.0.2",
19
- "fuse.js": "^1.2.2",
20
- "lodash": "^3.10.1",
19
+ "extract-text-webpack-plugin": "^0.8.2",
20
+ "node-sass": "^3.2.0",
21
21
  "react": "^0.13.3",
22
- "react-chartjs": "^0.6.0",
23
22
  "react-tools": "*",
24
- "webpack": "^1.10.5"
23
+ "sass-loader": "^2.0.1",
24
+ "webpack": "^1.12.1"
25
25
  },
26
26
  "scripts": {
27
- "test": "karma start"
27
+ "test": "karma start",
28
+ "start": "webpack -w --config webpack/dev.config.js",
29
+ "build": "webpack -p --config webpack/production.config.js"
28
30
  },
29
31
  "license": "",
30
32
  "engines": {
@@ -0,0 +1,11 @@
1
+ window.React = require('react');
2
+ <% if options.example %>
3
+ import HelloWorld from './components/hello-world';
4
+
5
+ registerComponent('hello-world', HelloWorld);
6
+ <% else %>
7
+ // example usage:
8
+ // import HelloWorld from './components/hello-world';
9
+
10
+ // registerComponent('hello-world', HelloWorld);
11
+ <% end %>
@@ -1,3 +1,5 @@
1
+ var ExtractTextPlugin = require('extract-text-webpack-plugin');
2
+
1
3
  module.exports = {
2
4
  context: __dirname + '/app/react',
3
5
  entry: './index',
@@ -9,12 +11,25 @@ module.exports = {
9
11
  loaders: [
10
12
  {
11
13
  test: /\.jsx?$/,
12
- exclude: /(node_modules|bower_components$)/,
14
+ exclude: /node_modules/,
13
15
  loader: 'babel-loader'
16
+ },
17
+ {
18
+ test: /\.scss$/,
19
+ loader: ExtractTextPlugin.extract('css!sass')
20
+ },
21
+ {
22
+ test: /\.css$/,
23
+ loader: ExtractTextPlugin.extract('css!sass')
14
24
  }
15
25
  ]
16
26
  },
17
27
  resolve: {
18
28
  extensions: ['', '.js', '.jsx', '.js.jsx']
19
- }
29
+ },
30
+ plugins: [
31
+ new ExtractTextPlugin('../stylesheets/react_bundle.css', {
32
+ allChunks: true
33
+ })
34
+ ]
20
35
  };
@@ -0,0 +1,6 @@
1
+ const WebpackNotifierPlugin = require('webpack-notifier');
2
+ const config = require('./../webpack.config');
3
+
4
+ config.plugins.push(new WebpackNotifierPlugin());
5
+
6
+ module.exports = config;
@@ -0,0 +1,3 @@
1
+ const config = require('./../webpack.config');
2
+
3
+ module.exports = config;
@@ -0,0 +1,2 @@
1
+ var context = require.context('./../app/react', true, /-test\.jsx?$/);
2
+ context.keys().forEach(context);
@@ -2,7 +2,7 @@ require 'react_webpack_rails/view_helpers'
2
2
 
3
3
  module ReactWebpackRails
4
4
  class Railtie < Rails::Railtie
5
- initializer "react_webpack_rails.view_helpers" do
5
+ initializer 'react_webpack_rails.view_helpers' do
6
6
  ActionView::Base.send :include, ViewHelpers
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module ReactWebpackRails
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'.freeze
3
3
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = 'React and Rails integration done with webpack'
13
13
  spec.description = ''
14
- spec.homepage = ''
14
+ spec.homepage = 'https://github.com/netguru/react_webpack_rails'
15
15
  spec.license = 'MIT'
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.10'
26
26
  spec.add_development_dependency 'rake', '~> 10.0'
27
- spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'rspec', '~> 3.3'
28
28
  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.0.2
4
+ version: 0.0.3
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: 2015-08-29 00:00:00.000000000 Z
12
+ date: 2015-09-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -43,16 +43,16 @@ dependencies:
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: '3.3'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: '3.3'
56
56
  description: ''
57
57
  email:
58
58
  - gawlikraf@gmail.com
@@ -71,23 +71,25 @@ files:
71
71
  - Rakefile
72
72
  - bin/console
73
73
  - bin/setup
74
+ - docs/README.md
74
75
  - lib/assets/javascripts/react_integration.js.erb
75
- - lib/generators/react_webpack_rails/USAGE
76
76
  - lib/generators/react_webpack_rails/install_generator.rb
77
- - lib/generators/react_webpack_rails/templates/hello-world-test.jsx
78
- - lib/generators/react_webpack_rails/templates/hello-world.jsx
79
- - lib/generators/react_webpack_rails/templates/index.js
80
77
  - lib/generators/react_webpack_rails/templates/karma.conf.js
81
78
  - lib/generators/react_webpack_rails/templates/package.json.erb
82
- - lib/generators/react_webpack_rails/templates/tests.webpack.js
79
+ - lib/generators/react_webpack_rails/templates/react/components/hello-world-test.jsx
80
+ - lib/generators/react_webpack_rails/templates/react/components/hello-world.jsx
81
+ - lib/generators/react_webpack_rails/templates/react/index.js.erb
83
82
  - lib/generators/react_webpack_rails/templates/webpack.config.js
83
+ - lib/generators/react_webpack_rails/templates/webpack/dev.config.js
84
+ - lib/generators/react_webpack_rails/templates/webpack/production.config.js
85
+ - lib/generators/react_webpack_rails/templates/webpack/tests.config.js
84
86
  - lib/react_webpack_rails.rb
85
87
  - lib/react_webpack_rails/engine.rb
86
88
  - lib/react_webpack_rails/railtie.rb
87
89
  - lib/react_webpack_rails/version.rb
88
90
  - lib/react_webpack_rails/view_helpers.rb
89
91
  - react_webpack_rails.gemspec
90
- homepage: ''
92
+ homepage: https://github.com/netguru/react_webpack_rails
91
93
  licenses:
92
94
  - MIT
93
95
  metadata: {}
@@ -1,8 +0,0 @@
1
- this will create:
2
- webpack.config.js
3
- karma.conf.js
4
- tests.webpack.js
5
- package.json.erb
6
- app/react/index.js
7
- app/react/components/hello-world.jsx
8
- app/react/components/hello-world-test.jsx
@@ -1,4 +0,0 @@
1
- window.React = require('react');
2
- import HelloWorld from './components/hello-world';
3
-
4
- registerComponent('hello-world', HelloWorld);
@@ -1,2 +0,0 @@
1
- var context = require.context('./app/react', true, /-test\.jsx?$/);
2
- context.keys().forEach(context);