redux-gem 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6cf8f3de0a3aacdeec02986223931af0a4f450bc
4
+ data.tar.gz: de83ed2634cd7cd4398af7c87c627db90fa47496
5
+ SHA512:
6
+ metadata.gz: 621ef56fc6e8057d5216ded6ce103804f95eaf30fc619612f56aafe537fad07c350580b3f26297f2dd7bb560d5f5014b72f2b66b1212d940c13b73967e35c9b4
7
+ data.tar.gz: c5e3443a429c79ce280a4f80ac4dd2560ca36d04f9ef2f333a84b44ff95b1a70d86595057ae1dae05966e72dc2a07a62cb4923c740912449fd6c6ca7c73474e7
@@ -0,0 +1,20 @@
1
+ Copyright 2017 luke popwell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,79 @@
1
+ # Redux::Gem
2
+ I Created this gem to add my style of file management using React and Redux to the React_on_Rails gem. Other than the stylesheets components and containers are now self contained and can be re-used easier between projects.
3
+
4
+ If you have and questions or you'd like to get in contact with me you can contact me through http://www.popwell.com or submit an issue to the github repo.
5
+
6
+ # Create a New Rails project
7
+ ```bash
8
+ $ Rails new #projectName
9
+ ```
10
+ cd into your new project folder
11
+ open in the editor of your choice
12
+
13
+ ## Installation
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem "react_on_rails", "~> 6"
18
+ gem 'redux-gem'
19
+ ```
20
+
21
+ And then execute:
22
+ ```bash
23
+ $ bundle
24
+ ```
25
+
26
+ Or install it yourself as:
27
+ ```bash
28
+ $ gem install redux-gem
29
+ ```
30
+
31
+ ## Usage
32
+ Knowing Redux is not a requirement to use this gem. It is available if you would like to generate containers.
33
+
34
+ Before you can use the Redux-gem you must install the React_on_Rails gem and run the generator
35
+
36
+ ```bash
37
+ $ rails generate react_on_rails:install
38
+ ```
39
+ you won't need to follow any of the other instructions for the React_on_Rails installation when you use the Redux-gem.
40
+
41
+ for more information on React_on_Rails visit
42
+ https://github.com/shakacode/react_on_rails#including-your-react-component-in-your-rails-views
43
+
44
+ Now that React_on_Rails is installed you need to run the Redux-gem start generator
45
+ ```bash
46
+ $ rails generate start
47
+ ```
48
+ This will remove all of the view components and files just created by React_on_Rails and replaces them with the Redux-gem files. It also installs redux, react-redux, react-router, redux-promises to the package.json file. Automatically install the foreman gem. The generator automatically runs npm i && bundle.
49
+
50
+ #To see your app on localhost
51
+ ```bash
52
+ $ foreman start -f Procfile.dev
53
+ ```
54
+ in your browser navigate to http://localhost:5000/ and you should see
55
+
56
+ Redux-gem installed!
57
+
58
+ To get started, edit client/app/App.jsx and save to reload.
59
+ edit styles in, app/assets/stylesheets/"component_name".scss
60
+
61
+ #To generate a new component run:
62
+
63
+ ```bash
64
+ $ rails generate component #component_name
65
+ ```
66
+ this generates a new component folder inside of the client folder with your components name entered as the class name and the export name. It adds the necessary lines to the registration file allowing your rails app to display them. Creates a Rails view page with the needed render method in views. Adds a scss file to the stylesheets folder with component_name.scss and a simple text-align center added to show it's working. Also, creates a route for your new component.
67
+
68
+ #To generate a new container run:
69
+
70
+ ```bash
71
+ $ rails generate container #container_name
72
+ ```
73
+ this generates a new container folder inside of the client folder with your container name entered as the class name and the export name. Creates a #container_name.js, action, constants and reducer. It adds the neccesary lines to the registration file allowing your rails app to display them. Creates a Rails view page with the needed render method in views. Adds a scss file to the stylesheets folder with container_name.scss and a simple text-align center added. Creates a route for your new container.
74
+
75
+ ## Contributing
76
+ Contribution directions go here.
77
+
78
+ ## License
79
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Redux::Gem'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,8 @@
1
+ Description:
2
+ The component generator creates a boilerplate dumb component inside of client section of a react_on_rails app
3
+
4
+ Example:
5
+ rails generate component Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,37 @@
1
+ class ComponentGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def create_route
5
+ route "get '#{name}', to: '#{name}#index'"
6
+ end
7
+
8
+ def create_view_directory
9
+ empty_directory("app/views/pages/components/#{name}")
10
+ end
11
+
12
+ def create_view
13
+ create_file "app/views/pages/components/#{name}/#{name}.html.erb", "<%= react_component('#{name}', {prerender: false}) %>"
14
+ create_file "app/assets/stylesheets/#{name}.scss"
15
+ end
16
+
17
+ def create_component_directory
18
+ empty_directory("client/app/components/#{name}")
19
+ end
20
+
21
+ def create_component_index
22
+ create_file "client/app/components/#{name}/#{name}.js",
23
+ "import React, { Component } from 'react';
24
+
25
+ class #{name} extends Component {
26
+ render() {
27
+ return (
28
+ <div>New Component</div>
29
+ )
30
+ }
31
+ }
32
+
33
+ export default #{name};"
34
+ inject_into_file "client/app/registration.jsx", " #{name},\n", :before => /^}/
35
+ inject_into_file "client/app/registration.jsx", "import #{name} from './components/#{name}/#{name}';\n", :after => "import ReactOnRails from 'react-on-rails';\n"
36
+ end
37
+ end
@@ -0,0 +1,12 @@
1
+ import React, { Component } from 'react';
2
+ import styles from './component.css';
3
+
4
+ class Index extends Component {
5
+ render() {
6
+ return (
7
+ <div>New Component</div>
8
+ )
9
+ }
10
+ }
11
+
12
+ export default Index;
@@ -0,0 +1,8 @@
1
+ Description:
2
+ hopefully creates a container inside of src with all template files
3
+
4
+ Example:
5
+ rails generate container Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,44 @@
1
+ class ContainerGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def create_route
5
+ route "get '#{name}', to: '#{name}#index'"
6
+ end
7
+
8
+ def create_directory
9
+ empty_directory("app/views/pages/containers/#{name}")
10
+ end
11
+
12
+ def create_view
13
+ create_file "app/views/pages/containers/#{name}/#{name}.html.erb", "<%= react_component('#{name}', {prerender: false}) %>"
14
+ create_file "app/assets/stylesheets/#{name}.scss"
15
+ end
16
+
17
+ def create_directory
18
+ empty_directory("client/app/containers/#{name}")
19
+ end
20
+
21
+ def create_contianer_index
22
+ create_file "client/app/containers/#{name}/#{name}.js",
23
+ "import React, { Component } from 'react';
24
+ import * as actions from './actions';
25
+
26
+ class #{name} extends Component {
27
+ render() {
28
+ return (
29
+ <div>#{name} Container</div>
30
+ );
31
+ }
32
+ }
33
+
34
+ export default #{name};"
35
+ inject_into_file "client/app/registration.jsx", " #{name},\n", :before => /^}/
36
+ inject_into_file "client/app/registration.jsx", "import #{name} from './containers/#{name}/#{name}';\n", :after => "import ReactOnRails from 'react-on-rails';\n"
37
+ end
38
+
39
+ def copy_container_files
40
+ copy_file "container/constants.js", "client/app/containers/#{name}/constants.js"
41
+ copy_file "container/actions.js", "client/app/containers/#{name}/actions.js"
42
+ copy_file "container/reducer.js", "client/app/containers/#{name}/reducer.js"
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ // import {} from './constants';
2
+
3
+ export const someAction = () => ({
4
+
5
+ });
@@ -0,0 +1 @@
1
+ // export const SOME_CONST = 'SOME_CONST';
@@ -0,0 +1,12 @@
1
+ import React, { Component } from 'react';
2
+ import * as actions from './actions';
3
+
4
+ class Index extends Component {
5
+ render() {
6
+ return (
7
+ <div>New Container</div>
8
+ );
9
+ }
10
+ }
11
+
12
+ export default Index;
@@ -0,0 +1,8 @@
1
+ const reducer = (state = {}, action) => {
2
+ switch (action.type) {
3
+ default:
4
+ return state;
5
+ }
6
+ };
7
+
8
+ export default reducer;
@@ -0,0 +1,36 @@
1
+ class StartGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def delete_bundles_folder
5
+ system("rm -rf client/app/bundles")
6
+ end
7
+
8
+ def create_base_files
9
+ generate(:scaffold, "page --skip-template-engine --no-view-specs --no-jbuilder --no-stylesheets" )
10
+ rails_command("db:migrate")
11
+ route "root 'pages#index'"
12
+ end
13
+
14
+ def install_views
15
+ create_file "app/views/pages/index.html.erb", "<%= react_component('Index', {prerender: false}) %>"
16
+ create_file "app/assets/stylesheets/App.scss",
17
+ ".App {
18
+ text-align: center
19
+ }"
20
+ end
21
+
22
+ def create_registration
23
+ copy_file "registration.jsx", "client/app/registration.jsx"
24
+ copy_file "Index.jsx", "client/app/Index.jsx"
25
+ copy_file "App.jsx", "client/app/App.jsx"
26
+ copy_file "reducers/index.js", "client/app/reducers/index.js"
27
+ copy_file "package.json", "client/package.json", force: true
28
+ copy_file "webpack.config.js", "client/webpack.config.js", force: true
29
+ system("gem install foreman")
30
+ system("bundle && npm install")
31
+ end
32
+
33
+ def start_server
34
+ system("foreman start -f Procfile.dev")
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ import React, { Component } from 'react';
2
+
3
+ class App extends Component {
4
+ render() {
5
+ return (
6
+ <div className="App">
7
+ <div className="App-header">
8
+ <h2>Redux-gem installed!</h2>
9
+ </div>
10
+ <p className="App-intro">
11
+ To get started, edit <code>client/app/App.jsx</code> and save to reload.
12
+ </p>
13
+ <p>edit styles in, <code>app/assets/stylesheets/"component_name".scss</code>
14
+ </p>
15
+ </div>
16
+ );
17
+ }
18
+ }
19
+
20
+ export default App;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { Router, IndexRoute, Route, hashHistory } from 'react-router';
3
+
4
+ import { Provider } from 'react-redux';
5
+ import { createStore, applyMiddleware } from 'redux';
6
+ import ReduxPromise from 'redux-promise';
7
+
8
+ import App from './App';
9
+ import reducers from './reducers';
10
+
11
+ const createStoreWithMiddleware = applyMiddleware(ReduxPromise)(createStore);
12
+
13
+ // railsContext provides contextual information especially useful for server rendering, such as
14
+ // knowing the locale. See the React on Rails documentation for more info on the railsContext
15
+
16
+ const Index = (props, _railsContext) => (
17
+ <Provider store={createStoreWithMiddleware(reducers)}>
18
+ <App />
19
+ </Provider>
20
+ );
21
+
22
+ export default Index;
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "react-webpack-rails-tutorial",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "engines": {
6
+ "node": "6.9.0",
7
+ "npm": "4.1.1"
8
+ },
9
+ "scripts": {
10
+ "build:test": "webpack --config webpack.config.js",
11
+ "build:production": "NODE_ENV=production webpack --config webpack.config.js",
12
+ "build:development": "webpack -w --config webpack.config.js"
13
+ },
14
+ "cacheDirectories": ["node_modules", "client/node_modules"],
15
+ "dependencies": {
16
+ "babel-cli": "^6.18.0",
17
+ "babel-core": "^6.21.0",
18
+ "babel-loader": "^6.2.10",
19
+ "babel-runtime": "^6.20.0",
20
+ "babel-polyfill": "^6.20.0",
21
+ "babel-preset-es2015": "^6.18.0",
22
+ "babel-preset-react": "^6.16.0",
23
+ "babel-preset-stage-0": "^6.16.0",
24
+ "es5-shim": "^4.5.9",
25
+ "expose-loader": "^0.7.1",
26
+ "imports-loader": "^0.7.0",
27
+ "react": "^15.4.1",
28
+ "react-dom": "^15.4.1",
29
+ "react-on-rails": "6.5.0",
30
+ "react-redux": "^5.0.2",
31
+ "react-router": "^3.0.2",
32
+ "redux-promise": "^0.5.3",
33
+ "redux": "^3.6.0",
34
+ "webpack": "^1.14.0"
35
+ },
36
+ "devDependencies": {
37
+ }
38
+ }
@@ -0,0 +1,7 @@
1
+ import { combineReducers } from 'redux';
2
+
3
+ const rootReducer = combineReducers({
4
+ state: (state = {}) => state
5
+ });
6
+
7
+ export default rootReducer;
@@ -0,0 +1,11 @@
1
+ import ReactOnRails from 'react-on-rails';
2
+
3
+ import App from './App';
4
+ import Index from './Index'
5
+
6
+ // This is how react_on_rails can see the your components and containers in the browser.
7
+
8
+ ReactOnRails.register({
9
+ App,
10
+ Index,
11
+ });
@@ -0,0 +1,63 @@
1
+ /* eslint comma-dangle: ["error",
2
+ {"functions": "never", "arrays": "only-multiline", "objects":
3
+ "only-multiline"} ] */
4
+
5
+ const webpack = require('webpack');
6
+ const path = require('path');
7
+
8
+ const devBuild = process.env.NODE_ENV !== 'production';
9
+ const nodeEnv = devBuild ? 'development' : 'production';
10
+
11
+ const config = {
12
+ entry: [
13
+ 'es5-shim/es5-shim',
14
+ 'es5-shim/es5-sham',
15
+ 'babel-polyfill',
16
+ './app/registration',
17
+ ],
18
+
19
+ output: {
20
+ filename: 'webpack-bundle.js',
21
+ path: '../app/assets/webpack',
22
+ },
23
+
24
+ resolve: {
25
+ extensions: ['', '.js', '.jsx'],
26
+ alias: {
27
+ react: path.resolve('./node_modules/react'),
28
+ 'react-dom': path.resolve('./node_modules/react-dom'),
29
+ },
30
+ },
31
+ plugins: [
32
+ new webpack.DefinePlugin({
33
+ 'process.env': {
34
+ NODE_ENV: JSON.stringify(nodeEnv),
35
+ },
36
+ }),
37
+ ],
38
+ module: {
39
+ loaders: [
40
+ {
41
+ test: require.resolve('react'),
42
+ loader: 'imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham',
43
+ },
44
+ {
45
+ test: /\.jsx?$/,
46
+ loader: 'babel-loader',
47
+ exclude: /node_modules/,
48
+ },
49
+ ],
50
+ },
51
+ };
52
+
53
+ module.exports = config;
54
+
55
+ if (devBuild) {
56
+ console.log('Webpack dev build for Rails'); // eslint-disable-line no-console
57
+ module.exports.devtool = 'eval-source-map';
58
+ } else {
59
+ config.plugins.push(
60
+ new webpack.optimize.DedupePlugin()
61
+ );
62
+ console.log('Webpack production build for Rails'); // eslint-disable-line no-console
63
+ }
@@ -0,0 +1,5 @@
1
+ module Redux
2
+ module Gem
3
+ # Your code goes here...
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Redux
2
+ module Gem
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :redux_gem do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redux-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luke Popwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: react_on_rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '6'
41
+ description: See README.md
42
+ email:
43
+ - lukepopwell@mac.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - lib/generators/component/USAGE
52
+ - lib/generators/component/component_generator.rb
53
+ - lib/generators/component/templates/component/index.js
54
+ - lib/generators/container/USAGE
55
+ - lib/generators/container/container_generator.rb
56
+ - lib/generators/container/templates/container/actions.js
57
+ - lib/generators/container/templates/container/constants.js
58
+ - lib/generators/container/templates/container/index.js
59
+ - lib/generators/container/templates/container/reducer.js
60
+ - lib/generators/start_generator.rb
61
+ - lib/generators/templates/App.jsx
62
+ - lib/generators/templates/Index.jsx
63
+ - lib/generators/templates/package.json
64
+ - lib/generators/templates/reducers/index.js
65
+ - lib/generators/templates/registration.jsx
66
+ - lib/generators/templates/webpack.config.js
67
+ - lib/redux/gem.rb
68
+ - lib/redux/gem/version.rb
69
+ - lib/tasks/redux/gem_tasks.rake
70
+ homepage: https://github.com/Luke-Popwell/redux-rails-gem
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.6.10
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Rails with react, redux and webpack.
94
+ test_files: []