react-rails-generator 0.1.0 → 0.2.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: 66943eab35a513046f76786edb170141e5f0b3e3
4
- data.tar.gz: 5d2bd336671172faf959fa03615633041e9bed81
3
+ metadata.gz: c291ed05662e2ee59ddbdde7adf61b4168e7d3ae
4
+ data.tar.gz: 66131c9026fdd97bc8c198127789faff1a79b4a9
5
5
  SHA512:
6
- metadata.gz: cf82fb4f11f096514375d746d85cef411fdea93f32038ed499a6b8943a9fc8427323f2a2069bd39ddf8bbfd5f9b9fa809d85c0636a174ef78a656a7cb2519c62
7
- data.tar.gz: 15ea11d8914edccc46b2a6d3a942762a2f343098da56ca16e49963e4bd53f909a973525c8ec63d10dcdf0edc6f7f4aa4ceda48a0be43330e3542c7bee45db9d0
6
+ metadata.gz: fcee67245d976b3ab207bc7bf13e5dca9184679f89c9901d5743c8c048c50274fcff05a8e11e8bcd567c208f39a6a6cfcaf8fa927535527b7a16ac02bd448a2d
7
+ data.tar.gz: 1ff1173a6e5ba0a0c454fc19737d4e0bf651192f4f8ad101865d44b12c6d0c72fdf4bfd141028319a9f049bc0c3dc733323713bf6fb36a8059edc0ec8c47634d
checksums.yaml.gz.sig CHANGED
Binary file
data/bin/react-rails CHANGED
@@ -1,7 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "generators/init_react"
4
+ require "thor"
4
5
 
5
- system("rails new #{ARGV[0]}")
6
- InitReact.new(ARGV[0]).init
7
- Dir.chdir ARGV[0]
6
+ class ReactRails < Thor
7
+ desc "new <project_name>", "Initialize a Rails project combine with React"
8
+ def new project_name
9
+ system("rails new #{project_name}")
10
+ InitReact.new(project_name).init
11
+ end
12
+ end
13
+
14
+ ReactRails.start(ARGV)
@@ -18,20 +18,12 @@ class InitReact
18
18
  create_react_controller
19
19
  create_react_view
20
20
  add_to_routes
21
+ init_api
21
22
  end
22
23
 
23
24
  def create_babelrc
24
- babelrc = <<-HEREDOC
25
- {
26
- presets: [
27
- "es2017",
28
- "react",
29
- ],
30
- "plugins": [
31
- "transform-class-properties",
32
- ],
33
- }
34
- HEREDOC
25
+ file_path = File.join(File.dirname(__FILE__), "../templates/.babelrc")
26
+ babelrc = File.read(file_path)
35
27
 
36
28
  File.open("#{@app_name}/.babelrc", "w") do |f|
37
29
  f.write(babelrc)
@@ -50,22 +42,8 @@ HEREDOC
50
42
  end
51
43
 
52
44
  def create_app_jsx
53
- app_jsx = <<-HEREDOC
54
- import getMuiTheme from "material-ui/styles/getMuiTheme";
55
- import MuiThemeProvider from "material-ui/styles/MuiThemeProvider";
56
-
57
- export default class App extends React.Component {
58
- render() {
59
- return (
60
- <MuiThemeProvider muiTheme={getMuiTheme()}>
61
- <mui.Drawer open={true}>
62
- <mui.MenuItem>FAQ</mui.MenuItem>
63
- </mui.Drawer>
64
- </MuiThemeProvider>
65
- );
66
- }
67
- }
68
- HEREDOC
45
+ file_path = File.join(File.dirname(__FILE__), "../templates/jsx/app.jsx")
46
+ app_jsx = File.read(file_path)
69
47
 
70
48
  File.open("#{@app_name}/app/jsx/app.jsx", "w") do |f|
71
49
  f.write(app_jsx)
@@ -73,26 +51,8 @@ HEREDOC
73
51
  end
74
52
 
75
53
  def create_bootstrap_jsx
76
- bootstrap_jsx = <<-HEREDOC
77
- import ReactDOM from "react-dom";
78
- import {Router, Route, Link, browserHistory} from "react-router"
79
-
80
- import injectTapEventPlugin from "react-tap-event-plugin";
81
- injectTapEventPlugin();
82
-
83
- import App from "./app";
84
-
85
- const router = (
86
- <Router history={browserHistory}>
87
- <Route path="/" component={App}>
88
- </Route>
89
- </Router>
90
- );
91
-
92
- $(document).on("ready page:load", function() {
93
- ReactDOM.render(router, document.getElementById("react-wrapper"));
94
- });
95
- HEREDOC
54
+ file_path = File.join(File.dirname(__FILE__), "../templates/jsx/bootstrap.jsx")
55
+ bootstrap_jsx = File.read(file_path)
96
56
 
97
57
  File.open("#{@app_name}/app/jsx/bootstrap.jsx", "w") do |f|
98
58
  f.write(bootstrap_jsx)
@@ -107,28 +67,8 @@ HEREDOC
107
67
  end
108
68
 
109
69
  def create_package_json
110
- package_json = <<-HEREDOC
111
- {
112
- "private": true,
113
- "dependencies": {
114
- "babel-core": "^6.18.2",
115
- "babel-loader": "^6.2.7",
116
- "babel-preset-es2017": "^1.4.0",
117
- "babel-preset-react-hmre": "^1.1.1",
118
- "babel-preset-react": "^6.16.0",
119
- "babel-plugin-add-module-exports": "~0.2.1",
120
- "babel-plugin-transform-class-properties": "~6.19.0",
121
- "material-ui": "^0.16.0",
122
- "react": "^15.4.0",
123
- "react-addons-update": "^15.4.0",
124
- "react-dom": "^15.4.0",
125
- "react-router": "^3.0.0",
126
- "react-tap-event-plugin": "^2.0.0",
127
- "react-toastr": "^2.8.0",
128
- "webpack": "~1.13.3"
129
- }
130
- }
131
- HEREDOC
70
+ file_path = File.join(File.dirname(__FILE__), "../templates/package.json")
71
+ package_json = File.read(file_path)
132
72
 
133
73
  File.open("#{@app_name}/package.json", "w") do |f|
134
74
  f.write(package_json)
@@ -136,42 +76,8 @@ HEREDOC
136
76
  end
137
77
 
138
78
  def create_webpack_config
139
- webpack_config = <<-HEREDOC
140
- var webpack = require("webpack");
141
-
142
- const paths = {
143
- js: "./app/assets/javascripts/",
144
- jsx: "./app/jsx/",
145
- }
146
-
147
- var alias = {
148
- "react/lib/CSSPropertyOperations": "react-dom/lib/CSSPropertyOperations"
149
- };
150
-
151
- module.exports = {
152
- entry: paths.jsx + "bootstrap.jsx",
153
- output: {
154
- path: paths.js,
155
- filename: "react-app.js",
156
- },
157
- resolve: {
158
- extensions: ['', '.js', '.jsx'],
159
- alias: alias,
160
- },
161
- module: {
162
- loaders: [{
163
- test: /\.jsx?$/,
164
- loaders: ['babel?cacheDirectory'],
165
- }]
166
- },
167
- plugins: [
168
- new webpack.ProvidePlugin({
169
- React: "react",
170
- mui: "material-ui",
171
- })
172
- ],
173
- }
174
- HEREDOC
79
+ file_path = File.join(File.dirname(__FILE__), "../templates/webpack.config.js")
80
+ webpack_config = File.read(file_path)
175
81
 
176
82
  File.open("#{@app_name}/webpack.config.js", "w") do |f|
177
83
  f.write(webpack_config)
@@ -179,12 +85,8 @@ HEREDOC
179
85
  end
180
86
 
181
87
  def create_react_controller
182
- controller = <<-HEREDOC
183
- class ReactAppController < ApplicationController
184
- def home
185
- end
186
- end
187
- HEREDOC
88
+ file_path = File.join(File.dirname(__FILE__), "../templates/controllers/react_app_controller.rb")
89
+ controller = File.read(file_path)
188
90
 
189
91
  File.open("#{@app_name}/app/controllers/react_app_controller.rb", "w") do |f|
190
92
  f.write(controller)
@@ -213,4 +115,20 @@ HEREDOC
213
115
  f.write(routes.join)
214
116
  end
215
117
  end
118
+
119
+ def init_api
120
+ FileUtils::mkdir_p "#{@app_name}/app/jsx/CallAPI"
121
+
122
+ base_api_path = File.join(File.dirname(__FILE__), "../templates/jsx/CallAPI/BaseAPI.js")
123
+ base_api = File.read(base_api_path)
124
+ File.open("#{@app_name}/app/jsx/CallAPI/BaseAPI.js", "w") do |f|
125
+ f.write(base_api)
126
+ end
127
+
128
+ index_api_path = File.join(File.dirname(__FILE__), "../templates/jsx/CallAPI/index.jsx")
129
+ index_api = File.read(index_api_path)
130
+ File.open("#{@app_name}/app/jsx/CallAPI/index.jsx", "w") do |f|
131
+ f.write(index_api)
132
+ end
133
+ end
216
134
  end
@@ -0,0 +1,9 @@
1
+ {
2
+ presets: [
3
+ "es2017",
4
+ "react",
5
+ ],
6
+ "plugins": [
7
+ "transform-class-properties",
8
+ ],
9
+ }
@@ -0,0 +1,4 @@
1
+ class ReactAppController < ApplicationController
2
+ def home
3
+ end
4
+ end
@@ -0,0 +1,29 @@
1
+ export default class BaseAPI {
2
+ static sendAjax(callback, options) {
3
+ BaseAPI.requestNumber = BaseAPI.requestNumber || 0;
4
+ BaseAPI.requestNumber++;
5
+
6
+ options.success = (response) => {
7
+ if (callback) {
8
+ callback(response.status, response.data);
9
+ }
10
+ }
11
+
12
+ options.error = (xhr) => {
13
+ if (xhr.status == 422 || xhr.status == 401) {
14
+ return false;
15
+ }
16
+
17
+ if (callback) {
18
+ callback(false);
19
+ }
20
+ }
21
+
22
+ options.complete = () => {
23
+ BaseAPI.requestNumber--;
24
+ }
25
+
26
+ options.url = "/api/" + options.url;
27
+ $.ajax(options);
28
+ }
29
+ }
@@ -0,0 +1,3 @@
1
+ // Add modules api here
2
+ module.exports = {
3
+ };
@@ -0,0 +1,73 @@
1
+ import getMuiTheme from "material-ui/styles/getMuiTheme";
2
+ import MuiThemeProvider from "material-ui/styles/MuiThemeProvider";
3
+ import NotificationsIcon from 'material-ui/svg-icons/social/notifications';
4
+
5
+ class AppBarExampleComposition extends React.Component {
6
+ constructor(props) {
7
+ super(props);
8
+
9
+ this.state = {
10
+ logged: true,
11
+ };
12
+ }
13
+
14
+ handleChange = (event, logged) => {
15
+ this.setState({logged: logged});
16
+ };
17
+
18
+ render() {
19
+ return (
20
+ <div>
21
+ <h3>AppBar</h3>
22
+ <mui.Toggle
23
+ label="Logged"
24
+ defaultToggled={true}
25
+ onToggle={this.handleChange}
26
+ labelPosition="right"
27
+ style={{margin: 20}}
28
+ />
29
+ <mui.AppBar
30
+ title="Title"
31
+ iconElementRight={this.state.logged ? <mui.FlatButton label="Logged" /> : <mui.FlatButton label="Login" />}
32
+ />
33
+
34
+ <h3>Badge</h3>
35
+ <div>
36
+ <mui.Badge
37
+ badgeContent={4}
38
+ primary={true}
39
+ >
40
+ <NotificationsIcon />
41
+ </mui.Badge>
42
+ <mui.Badge
43
+ badgeContent={10}
44
+ secondary={true}
45
+ badgeStyle={{top: 12, right: 12}}
46
+ >
47
+ <mui.IconButton tooltip="Notifications">
48
+ <NotificationsIcon />
49
+ </mui.IconButton>
50
+ </mui.Badge>
51
+ </div>
52
+
53
+ <h3>Date Picker</h3>
54
+ <div>
55
+ <mui.DatePicker hintText="Portrait Dialog" />
56
+ <mui.DatePicker hintText="Landscape Dialog" mode="landscape" />
57
+ <mui.DatePicker hintText="Dialog Disabled" disabled={true} />
58
+ </div>
59
+ </div>
60
+ );
61
+ }
62
+ }
63
+
64
+ export default class App extends React.Component {
65
+ render() {
66
+ return (
67
+ <MuiThemeProvider muiTheme={getMuiTheme()}>
68
+ // You can replace AppBarExampleComposition to your code
69
+ <AppBarExampleComposition />
70
+ </MuiThemeProvider>
71
+ );
72
+ }
73
+ }
@@ -0,0 +1,18 @@
1
+ import ReactDOM from "react-dom";
2
+ import {Router, Route, Link, browserHistory} from "react-router"
3
+
4
+ import injectTapEventPlugin from "react-tap-event-plugin";
5
+ injectTapEventPlugin();
6
+
7
+ import App from "./app";
8
+
9
+ const router = (
10
+ <Router history={browserHistory}>
11
+ <Route path="/" component={App}>
12
+ </Route>
13
+ </Router>
14
+ );
15
+
16
+ $(document).on("ready page:load", function() {
17
+ ReactDOM.render(router, document.getElementById("react-wrapper"));
18
+ });
@@ -0,0 +1,20 @@
1
+ {
2
+ "private": true,
3
+ "dependencies": {
4
+ "babel-core": "^6.18.2",
5
+ "babel-loader": "^6.2.7",
6
+ "babel-preset-es2017": "^1.4.0",
7
+ "babel-preset-react-hmre": "^1.1.1",
8
+ "babel-preset-react": "^6.16.0",
9
+ "babel-plugin-add-module-exports": "~0.2.1",
10
+ "babel-plugin-transform-class-properties": "~6.19.0",
11
+ "material-ui": "^0.16.0",
12
+ "react": "^15.4.0",
13
+ "react-addons-update": "^15.4.0",
14
+ "react-dom": "^15.4.0",
15
+ "react-router": "^3.0.0",
16
+ "react-tap-event-plugin": "^2.0.0",
17
+ "react-toastr": "^2.8.0",
18
+ "webpack": "~1.13.3"
19
+ }
20
+ }
@@ -0,0 +1,34 @@
1
+ var webpack = require("webpack");
2
+
3
+ const paths = {
4
+ js: "./app/assets/javascripts/",
5
+ jsx: "./app/jsx/",
6
+ }
7
+
8
+ var alias = {
9
+ "react/lib/CSSPropertyOperations": "react-dom/lib/CSSPropertyOperations"
10
+ };
11
+
12
+ module.exports = {
13
+ entry: paths.jsx + "bootstrap.jsx",
14
+ output: {
15
+ path: paths.js,
16
+ filename: "react-app.js",
17
+ },
18
+ resolve: {
19
+ extensions: ['', '.js', '.jsx'],
20
+ alias: alias,
21
+ },
22
+ module: {
23
+ loaders: [{
24
+ test: /\.jsx?$/,
25
+ loaders: ['babel?cacheDirectory'],
26
+ }]
27
+ },
28
+ plugins: [
29
+ new webpack.ProvidePlugin({
30
+ React: "react",
31
+ mui: "material-ui",
32
+ })
33
+ ],
34
+ }
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react-rails-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bach Van Ngoc
@@ -41,6 +41,14 @@ extra_rdoc_files: []
41
41
  files:
42
42
  - bin/react-rails
43
43
  - lib/generators/init_react.rb
44
+ - lib/templates/.babelrc
45
+ - lib/templates/controllers/react_app_controller.rb
46
+ - lib/templates/jsx/CallAPI/BaseAPI.js
47
+ - lib/templates/jsx/CallAPI/index.jsx
48
+ - lib/templates/jsx/app.jsx
49
+ - lib/templates/jsx/bootstrap.jsx
50
+ - lib/templates/package.json
51
+ - lib/templates/webpack.config.js
44
52
  homepage: https://github.com/NeverSmileK57CLC/react-rails-generator
45
53
  licenses:
46
54
  - MIT
@@ -61,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
69
  version: '0'
62
70
  requirements: []
63
71
  rubyforge_project:
64
- rubygems_version: 2.6.12
72
+ rubygems_version: 2.5.1
65
73
  signing_key:
66
74
  specification_version: 4
67
75
  summary: React Rails generator
metadata.gz.sig CHANGED
Binary file