react_webpack_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29f27718bf4f9c516d3de813560b52b5e7164d19
4
+ data.tar.gz: 1090c7f9014ddacb6e58c5f7a298c6dcce17d2f3
5
+ SHA512:
6
+ metadata.gz: de6c1cad348f6ce13aa40898e3e4472aeda9c83169199b21bc6208a5bf2ecf3d084f1191d73b2c0025d5b4bc3687db3447bb7d97eca45ca25c95ddff46f6e797
7
+ data.tar.gz: da62d8986d8184501c58bdd881b3a688ff81dee2f42d5858521572acb5bf46f6ea3c1fece8e1c43d60dff8896160face39139f8ed6a2f334be8f73d488db521a
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ react_webpack_rails-0.0.1.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in react_webpack_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Rafał Gawlik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # ReactWebpackRails
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/react_webpack_rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'react_webpack_rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install react_webpack_rails
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/react_webpack_rails.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "react_webpack_rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,109 @@
1
+ /*globals React, Turbolinks*/
2
+
3
+ // from https://github.com/reactjs/react-rails/blob/master/lib/assets/javascripts/react_ujs.js.erb
4
+ // Unobtrusive scripting adapter for React
5
+ ;(function(document, window) {
6
+ // jQuery is optional. Use it to support legacy browsers.
7
+ var $ = (typeof window.jQuery !== 'undefined') && window.jQuery;
8
+
9
+ window.reactComponents = {};
10
+ window.registerComponent = function (name, component) {
11
+ window.reactComponents[name] = component;
12
+ };
13
+
14
+ // create the namespace
15
+ window.ReactRailsUJS = {
16
+ CLASS_NAME_ATTR: 'data-react-class',
17
+ PROPS_ATTR: 'data-react-props',
18
+ RAILS_ENV_DEVELOPMENT: <%= Rails.env == "development" %>,
19
+ // helper method for the mount and unmount methods to find the
20
+ // `data-react-class` DOM elements
21
+ findDOMNodes: function(searchSelector) {
22
+ // we will use fully qualified paths as we do not bind the callbacks
23
+ var selector;
24
+ if (typeof searchSelector === 'undefined') {
25
+ var selector = '[' + window.ReactRailsUJS.CLASS_NAME_ATTR + ']';
26
+ } else {
27
+ var selector = searchSelector + ' [' + window.ReactRailsUJS.CLASS_NAME_ATTR + ']';
28
+ }
29
+
30
+ if ($) {
31
+ return $(selector);
32
+ } else {
33
+ return document.querySelectorAll(selector);
34
+ }
35
+ },
36
+
37
+ mountComponents: function(searchSelector) {
38
+ var nodes = window.ReactRailsUJS.findDOMNodes(searchSelector);
39
+
40
+ for (var i = 0; i < nodes.length; ++i) {
41
+ var node = nodes[i];
42
+ var className = node.getAttribute(window.ReactRailsUJS.CLASS_NAME_ATTR);
43
+
44
+ // Assume className is simple and can be found at top-level (window).
45
+ // Fallback to eval to handle cases like 'My.React.ComponentName'.
46
+
47
+ var constructor = window.reactComponents[className] || eval.call(window, className);
48
+ var propsJson = node.getAttribute(window.ReactRailsUJS.PROPS_ATTR);
49
+ var props = propsJson && JSON.parse(propsJson);
50
+
51
+ React.render(React.createElement(constructor, props), node);
52
+ }
53
+ },
54
+
55
+ unmountComponents: function(searchSelector) {
56
+ var nodes = window.ReactRailsUJS.findDOMNodes(searchSelector);
57
+
58
+ for (var i = 0; i < nodes.length; ++i) {
59
+ var node = nodes[i];
60
+
61
+ React.unmountComponentAtNode(node);
62
+ }
63
+ }
64
+ };
65
+
66
+ // functions not exposed publicly
67
+ function handleTurbolinksEvents () {
68
+ var handleEvent;
69
+ var unmountEvent;
70
+
71
+ if ($) {
72
+ handleEvent = function(eventName, callback) {
73
+ $(document).on(eventName, callback);
74
+ };
75
+
76
+ } else {
77
+ handleEvent = function(eventName, callback) {
78
+ document.addEventListener(eventName, callback);
79
+ };
80
+ }
81
+
82
+ if (Turbolinks.EVENTS) {
83
+ unmountEvent = Turbolinks.EVENTS.BEFORE_UNLOAD;
84
+ } else {
85
+ unmountEvent = 'page:receive';
86
+ Turbolinks.pagesCached(0);
87
+
88
+ if (window.ReactRailsUJS.RAILS_ENV_DEVELOPMENT) {
89
+ console.warn('The Turbolinks cache has been disabled (Turbolinks >= 2.4.0 is recommended). See https://github.com/reactjs/react-rails/issues/87 for more information.');
90
+ }
91
+ }
92
+ handleEvent('page:change', function() {window.ReactRailsUJS.mountComponents()});
93
+ handleEvent(unmountEvent, function() {window.ReactRailsUJS.unmountComponents()});
94
+ }
95
+
96
+ function handleNativeEvents() {
97
+ if ($) {
98
+ $(function() {window.ReactRailsUJS.mountComponents()});
99
+ } else {
100
+ document.addEventListener('DOMContentLoaded', function() {window.ReactRailsUJS.mountComponents()});
101
+ }
102
+ }
103
+
104
+ if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
105
+ handleTurbolinksEvents();
106
+ } else {
107
+ handleNativeEvents();
108
+ }
109
+ })(document, window);
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,20 @@
1
+ module ReactWebpackRails
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def generate_layout
6
+ copy_file 'webpack.config.js', 'webpack.config.js'
7
+ 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
+ template 'package.json.erb', 'package.json'
12
+ end
13
+
14
+ private
15
+
16
+ def file_name
17
+ layout_name.underscore
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ import React from 'react/addons';
2
+ const TestUtils = React.addons.TestUtils;
3
+ import expect from 'expect';
4
+ import HelloWorld from './hello-world';
5
+
6
+ describe('HelloWorld', () => {
7
+ const component = TestUtils.renderIntoDocument(<HelloWorld/>);
8
+
9
+ it('renders', () => {
10
+ expect(TestUtils.findRenderedComponentWithType(component, HelloWorld)).toExist();
11
+ });
12
+ });
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+
3
+ class Users extends React.Component {
4
+ render() {
5
+ return <div>Hello World</div>;
6
+ }
7
+ }
8
+
9
+ export default Users;
@@ -0,0 +1,4 @@
1
+ window.React = require('react');
2
+ import HelloWorld from './components/hello-world';
3
+
4
+ registerComponent('hello-world', HelloWorld);
@@ -0,0 +1,30 @@
1
+ var webpack = require('webpack');
2
+
3
+ module.exports = function (config) {
4
+ config.set({
5
+ browsers: ['Chrome'],
6
+ singleRun: true,
7
+ frameworks: ['mocha', 'sinon'],
8
+ files: ['tests.webpack.js'],
9
+ preprocessors: {'tests.webpack.js': ['webpack', 'sourcemap']},
10
+ reporters: ['dots'],
11
+ webpack: {
12
+ module: {
13
+ loaders: [
14
+ {
15
+ test: /\.jsx?$/,
16
+ exclude: /node_modules/,
17
+ loader: 'babel-loader'
18
+ }]
19
+ },
20
+ watch: true,
21
+ resolve: {
22
+ extensions: ["", ".js", ".jsx", ".js.jsx"]
23
+ },
24
+ devtool: 'inline-source-map',
25
+ },
26
+ webpackServer: {
27
+ noInfo: true
28
+ }
29
+ });
30
+ };
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "<%="#{Rails.application.class.parent_name}"%>",
3
+ "devDependencies": {
4
+ "babel-eslint": "^4.0.5",
5
+ "eslint": "^0.24.1",
6
+ "eslint-plugin-react": "^3.2.2",
7
+ "expect": "^1.9.0",
8
+ "karma": "^0.13.9",
9
+ "karma-chrome-launcher": "^0.2.0",
10
+ "karma-mocha": "^0.2.0",
11
+ "karma-sinon": "^1.0.4",
12
+ "karma-sourcemap-loader": "^0.3.5",
13
+ "karma-webpack": "^1.7.0"
14
+ },
15
+ "dependencies": {
16
+ "babel-core": "^5.8.19",
17
+ "babel-loader": "^5.3.2",
18
+ "chart.js": "^1.0.2",
19
+ "fuse.js": "^1.2.2",
20
+ "lodash": "^3.10.1",
21
+ "react": "^0.13.3",
22
+ "react-chartjs": "^0.6.0",
23
+ "react-tools": "*",
24
+ "webpack": "^1.10.5"
25
+ },
26
+ "scripts": {
27
+ "test": "karma start"
28
+ },
29
+ "license": "",
30
+ "engines": {
31
+ "node": ">= 0.10"
32
+ }
33
+ }
@@ -0,0 +1,2 @@
1
+ var context = require.context('./app/react', true, /-test\.jsx?$/);
2
+ context.keys().forEach(context);
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ context: __dirname + '/app/react',
3
+ entry: './index',
4
+ output: {
5
+ path: __dirname + '/app/assets/javascripts/generated',
6
+ filename: 'bundle.js'
7
+ },
8
+ module: {
9
+ loaders: [
10
+ {
11
+ test: /\.jsx?$/,
12
+ exclude: /(node_modules|bower_components$)/,
13
+ loader: 'babel-loader'
14
+ }
15
+ ]
16
+ },
17
+ resolve: {
18
+ extensions: ['', '.js', '.jsx', '.js.jsx']
19
+ }
20
+ };
@@ -0,0 +1,4 @@
1
+ module ReactWebpackRails
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ require 'react_webpack_rails/view_helpers'
2
+
3
+ module ReactWebpackRails
4
+ class Railtie < Rails::Railtie
5
+ initializer "react_webpack_rails.view_helpers" do
6
+ ActionView::Base.send :include, ViewHelpers
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module ReactWebpackRails
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,18 @@
1
+ module ReactWebpackRails
2
+ module ViewHelpers
3
+ # based on https://github.com/reactjs/react-rails/blob/master/lib/react/rails/view_helper.rb
4
+ def react_component(name, props = {}, options = {}, &block)
5
+ options = { tag: options } if options.is_a?(Symbol)
6
+
7
+ html_options = options.reverse_merge(data: {})
8
+ html_options[:data].tap do |data|
9
+ data[:react_class] = name
10
+ data[:react_props] = (props.is_a?(String) ? props : props.to_json)
11
+ end
12
+ html_tag = html_options[:tag] || :div
13
+ html_options.except!(:tag)
14
+
15
+ content_tag(html_tag, '', html_options, &block)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ require 'react_webpack_rails/version'
2
+ require 'react_webpack_rails/engine'
3
+ require 'react_webpack_rails/railtie'
4
+ require 'react_webpack_rails/view_helpers'
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'react_webpack_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'react_webpack_rails'
8
+ spec.version = ReactWebpackRails::VERSION
9
+ spec.authors = ['Rafał Gawlik', 'Radosław Piątek']
10
+ spec.email = ['gawlikraf@gmail.com', 'radek.nekath@gmail.com']
11
+
12
+ spec.summary = 'React and Rails integration done with webpack'
13
+ spec.description = ''
14
+ spec.homepage = ''
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.10'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec'
28
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: react_webpack_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rafał Gawlik
8
+ - Radosław Piątek
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-08-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: ''
57
+ email:
58
+ - gawlikraf@gmail.com
59
+ - radek.nekath@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/assets/javascripts/react-integration.js.erb
74
+ - lib/generators/react_webpack_rails/USAGE
75
+ - lib/generators/react_webpack_rails/install_generator.rb
76
+ - lib/generators/react_webpack_rails/templates/hello-world-test.jsx
77
+ - lib/generators/react_webpack_rails/templates/hello-world.jsx
78
+ - lib/generators/react_webpack_rails/templates/index.js
79
+ - lib/generators/react_webpack_rails/templates/karma.conf.js
80
+ - lib/generators/react_webpack_rails/templates/package.json.erb
81
+ - lib/generators/react_webpack_rails/templates/tests.webpack.js
82
+ - lib/generators/react_webpack_rails/templates/webpack.config.js
83
+ - lib/react_webpack_rails.rb
84
+ - lib/react_webpack_rails/engine.rb
85
+ - lib/react_webpack_rails/railtie.rb
86
+ - lib/react_webpack_rails/version.rb
87
+ - lib/react_webpack_rails/view_helpers.rb
88
+ - react_webpack_rails.gemspec
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.5
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: React and Rails integration done with webpack
113
+ test_files: []