common_core_js 0.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3d0247921834b019942e6b3539e5f55f8575c0137ca6004cd730298591dfcea
4
- data.tar.gz: 57003617eefa913a505f2f2435ba0b61c516d31e07831788f3c96b8907f768dc
3
+ metadata.gz: 944f8bb60dd7454749b17dfb671d4c4eee78dea8511674ee15c9f12aed759fd8
4
+ data.tar.gz: 412fa01b88bb1747100fb3a81ceb3f0aee9b19fa606168475d48738a8a8d879b
5
5
  SHA512:
6
- metadata.gz: 737d442f6cfbdf272e7a2b6c5a5aa690df884994c93429f4fac14e739e0a39064b4b5ab5dbf378756314cab506adcd8fd1f38c689ad7f300ef58043c9ea1c7b3
7
- data.tar.gz: e5c8cf0b226a216c735c001dfebedcebb457524dff18f21ee6b988d795ed73f787d92b7fdf864178a6fff3a3d35e3e1fe9393e82ddbb979d6b73e89ba7af3804
6
+ metadata.gz: 6f03ba9c9154c8cdaea309c2458ef24a9270a0533415fe0cc4a7ac0c69f45f87936e0e09a3277fd185e163f5cbba37ff15e54f496c80a3a29217fd8cb945dfc6
7
+ data.tar.gz: ae43c5c4c7c26791a259194dd4c93b8ca3cc65659114a39d2099285c36d3f3b849b654b029cffc60f743b07af1856d50a7dd1acec6ae92db0b62e7e093d0db62
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Reorder generators
5
+ 2. Remove generators
6
+ 3. Add installed generators
7
+ To add new installed generators automatically delete this file and reload the project.
8
+ --><GeneratorsGroup><Generator name="controller" /><Generator name="integration_test" /><Generator name="mailer" /><Generator name="migration" /><Generator name="model" /><Generator name="observer" /><Generator name="plugin" /><Generator name="resource" /><Generator name="scaffold" /><Generator name="session_migration" /></GeneratorsGroup></Settings>
@@ -0,0 +1,14 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/db/*.sqlite3-*
7
+ test/dummy/log/*.log
8
+ test/dummy/storage/
9
+ test/dummy/tmp/
10
+ .byebug_history
11
+
12
+ .idea/
13
+ *.gem
14
+ .DS_Store
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in common_core_js.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
13
+
14
+ # To use a debugger
15
+ # gem 'byebug', group: [:development, :test]
@@ -0,0 +1,175 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ common_core_js (0.1.1)
5
+ haml-rails
6
+ kaminari
7
+ rails
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actioncable (6.0.3.2)
13
+ actionpack (= 6.0.3.2)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (6.0.3.2)
17
+ actionpack (= 6.0.3.2)
18
+ activejob (= 6.0.3.2)
19
+ activerecord (= 6.0.3.2)
20
+ activestorage (= 6.0.3.2)
21
+ activesupport (= 6.0.3.2)
22
+ mail (>= 2.7.1)
23
+ actionmailer (6.0.3.2)
24
+ actionpack (= 6.0.3.2)
25
+ actionview (= 6.0.3.2)
26
+ activejob (= 6.0.3.2)
27
+ mail (~> 2.5, >= 2.5.4)
28
+ rails-dom-testing (~> 2.0)
29
+ actionpack (6.0.3.2)
30
+ actionview (= 6.0.3.2)
31
+ activesupport (= 6.0.3.2)
32
+ rack (~> 2.0, >= 2.0.8)
33
+ rack-test (>= 0.6.3)
34
+ rails-dom-testing (~> 2.0)
35
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
+ actiontext (6.0.3.2)
37
+ actionpack (= 6.0.3.2)
38
+ activerecord (= 6.0.3.2)
39
+ activestorage (= 6.0.3.2)
40
+ activesupport (= 6.0.3.2)
41
+ nokogiri (>= 1.8.5)
42
+ actionview (6.0.3.2)
43
+ activesupport (= 6.0.3.2)
44
+ builder (~> 3.1)
45
+ erubi (~> 1.4)
46
+ rails-dom-testing (~> 2.0)
47
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
+ activejob (6.0.3.2)
49
+ activesupport (= 6.0.3.2)
50
+ globalid (>= 0.3.6)
51
+ activemodel (6.0.3.2)
52
+ activesupport (= 6.0.3.2)
53
+ activerecord (6.0.3.2)
54
+ activemodel (= 6.0.3.2)
55
+ activesupport (= 6.0.3.2)
56
+ activestorage (6.0.3.2)
57
+ actionpack (= 6.0.3.2)
58
+ activejob (= 6.0.3.2)
59
+ activerecord (= 6.0.3.2)
60
+ marcel (~> 0.3.1)
61
+ activesupport (6.0.3.2)
62
+ concurrent-ruby (~> 1.0, >= 1.0.2)
63
+ i18n (>= 0.7, < 2)
64
+ minitest (~> 5.1)
65
+ tzinfo (~> 1.1)
66
+ zeitwerk (~> 2.2, >= 2.2.2)
67
+ builder (3.2.4)
68
+ concurrent-ruby (1.1.6)
69
+ crass (1.0.6)
70
+ erubi (1.9.0)
71
+ erubis (2.7.0)
72
+ globalid (0.4.2)
73
+ activesupport (>= 4.2.0)
74
+ haml (5.1.2)
75
+ temple (>= 0.8.0)
76
+ tilt
77
+ haml-rails (2.0.1)
78
+ actionpack (>= 5.1)
79
+ activesupport (>= 5.1)
80
+ haml (>= 4.0.6, < 6.0)
81
+ html2haml (>= 1.0.1)
82
+ railties (>= 5.1)
83
+ html2haml (2.2.0)
84
+ erubis (~> 2.7.0)
85
+ haml (>= 4.0, < 6)
86
+ nokogiri (>= 1.6.0)
87
+ ruby_parser (~> 3.5)
88
+ i18n (1.8.3)
89
+ concurrent-ruby (~> 1.0)
90
+ kaminari (1.2.1)
91
+ activesupport (>= 4.1.0)
92
+ kaminari-actionview (= 1.2.1)
93
+ kaminari-activerecord (= 1.2.1)
94
+ kaminari-core (= 1.2.1)
95
+ kaminari-actionview (1.2.1)
96
+ actionview
97
+ kaminari-core (= 1.2.1)
98
+ kaminari-activerecord (1.2.1)
99
+ activerecord
100
+ kaminari-core (= 1.2.1)
101
+ kaminari-core (1.2.1)
102
+ loofah (2.6.0)
103
+ crass (~> 1.0.2)
104
+ nokogiri (>= 1.5.9)
105
+ mail (2.7.1)
106
+ mini_mime (>= 0.1.1)
107
+ marcel (0.3.3)
108
+ mimemagic (~> 0.3.2)
109
+ method_source (1.0.0)
110
+ mimemagic (0.3.5)
111
+ mini_mime (1.0.2)
112
+ mini_portile2 (2.4.0)
113
+ minitest (5.14.1)
114
+ nio4r (2.5.2)
115
+ nokogiri (1.10.9)
116
+ mini_portile2 (~> 2.4.0)
117
+ rack (2.2.3)
118
+ rack-test (1.1.0)
119
+ rack (>= 1.0, < 3)
120
+ rails (6.0.3.2)
121
+ actioncable (= 6.0.3.2)
122
+ actionmailbox (= 6.0.3.2)
123
+ actionmailer (= 6.0.3.2)
124
+ actionpack (= 6.0.3.2)
125
+ actiontext (= 6.0.3.2)
126
+ actionview (= 6.0.3.2)
127
+ activejob (= 6.0.3.2)
128
+ activemodel (= 6.0.3.2)
129
+ activerecord (= 6.0.3.2)
130
+ activestorage (= 6.0.3.2)
131
+ activesupport (= 6.0.3.2)
132
+ bundler (>= 1.3.0)
133
+ railties (= 6.0.3.2)
134
+ sprockets-rails (>= 2.0.0)
135
+ rails-dom-testing (2.0.3)
136
+ activesupport (>= 4.2.0)
137
+ nokogiri (>= 1.6)
138
+ rails-html-sanitizer (1.3.0)
139
+ loofah (~> 2.3)
140
+ railties (6.0.3.2)
141
+ actionpack (= 6.0.3.2)
142
+ activesupport (= 6.0.3.2)
143
+ method_source
144
+ rake (>= 0.8.7)
145
+ thor (>= 0.20.3, < 2.0)
146
+ rake (13.0.1)
147
+ ruby_parser (3.14.2)
148
+ sexp_processor (~> 4.9)
149
+ sexp_processor (4.15.0)
150
+ sprockets (4.0.2)
151
+ concurrent-ruby (~> 1.0)
152
+ rack (> 1, < 3)
153
+ sprockets-rails (3.2.1)
154
+ actionpack (>= 4.0)
155
+ activesupport (>= 4.0)
156
+ sprockets (>= 3.0.0)
157
+ temple (0.8.2)
158
+ thor (1.0.1)
159
+ thread_safe (0.3.6)
160
+ tilt (2.0.10)
161
+ tzinfo (1.2.7)
162
+ thread_safe (~> 0.1)
163
+ websocket-driver (0.7.2)
164
+ websocket-extensions (>= 0.1.0)
165
+ websocket-extensions (0.1.5)
166
+ zeitwerk (2.3.1)
167
+
168
+ PLATFORMS
169
+ ruby
170
+
171
+ DEPENDENCIES
172
+ common_core_js!
173
+
174
+ BUNDLED WITH
175
+ 2.1.4
data/README.md CHANGED
@@ -8,10 +8,37 @@ Yes, it's opinionated. Yes, it's metaprogramming. A lot of metaprogramming. Ruby
8
8
  No, I would not use this to build an intricate app. Yes, it's a great tool for prototyping. Yes, I think prototyping is a lost art.
9
9
 
10
10
 
11
+ = THE SALES PITCH:
12
+ * Build plug-and-play scaffolding mixing HAML with jQuery-based Javascript
13
+ * Automatically Reads Your Models (make them before building your scaffolding!)
14
+ * Excellent for CRUD, lists with pagination, searching, sorting.
15
+ * Wonderful for prototyping.
16
+ * Plays nicely with Devise, Kaminari, Haml-Rails, Rspec.
17
+ * Create specs autoamatically along with the controllers.
18
+ * Nest your routes model-by-model for built-in poor man's authentication
19
+ * Throw the scaffolding away when your app is ready to graduate to its next phase.
20
+
21
+
22
+ = HOW EASY?
23
+
24
+
11
25
  ```
12
26
  rails generate common_core:scaffold Thing
13
27
  ```
14
28
 
29
+ = TO INSTALL
30
+
31
+ - Add common_core_js to your Gemfile
32
+
33
+ - Install jQuery (required)
34
+
35
+ - Install Bootstrap (optional)
36
+
37
+ - Install Devise or implement your own authentication
38
+
39
+ - Unless you want to bypass specs, you'll also want Rspec (rspec-rails), factory_bot_rails, and shoulda-matchers
40
+
41
+
15
42
  ## Options
16
43
 
17
44
  Note that the arguments are not preceeded by dashes and are followed by equal sign and the input you are giving.
@@ -22,54 +49,80 @@ Flags take two dashes (--) and do not take any value.
22
49
 
23
50
  TitleCase class name of the thing you want to build a scaffoling for.
24
51
 
25
- ### namespace=
52
+ ### `namespace=`
26
53
 
27
54
  pass `namespace=` as a flag to denote a namespace to apply to the Rails path helpers
28
55
 
29
56
 
30
- `rails generate common_core:scaffold GetEmailsRule namespace=dashboard`
57
+ `rails generate common_core:scaffold Thing namespace=dashboard`
58
+
59
+ This produces several views at `app/views/dashboard/things/` and a controller at`app/controllers/dashboard/things_controller.rb`
60
+
61
+ The controller looks like so:
31
62
 
32
- ### nest=
63
+ ```
64
+ class Dashboard::ThingsController < ApplicationController
65
+ before_action :authenticate_user!
66
+ before_action :load_thing, only: [:show, :edit, :update, :destroy]
67
+ def load_thing
68
+ @thing = current_user.things.find(params[:id])
69
+ end
70
+ ...
71
+ end
72
+
73
+ ```
74
+
75
+
76
+ ### `nest=`
33
77
 
34
78
  pass `nest=` as a flag to denote a nested resources
35
79
 
36
80
 
37
- `rails generate common_core:scaffold Lineitem nest=invoice`
81
+ `rails generate common_core:scaffold Line nest=invoice`
82
+
83
+ In this example, it is presumed that the current user has_many :invoices, and that invoices have many :lines
84
+
38
85
 
39
86
  For multi-level nesting use slashes to separate your levels of nesting. Remember, you should match what you have in your routes.rb file.
40
87
 
88
+ ```
41
89
  resources :invoices do
42
90
  resources :lines do
43
- resources :charges
91
+ resources :charge
44
92
  end
45
93
  end
46
94
 
95
+ ```
96
+ In this example, it is presumed that the current user has_many :invoices, and that invoices have many :lines, and that lines have many :charges
97
+
47
98
 
99
+ To generate scaffold:
48
100
  `rails generate common_core:scaffold Charge nest=invoice/line`
101
+
49
102
  The order of the nest should match the nested resources you have in your own app. In particular, you auth root will be used as the starting point when loading the objects from the URL:
50
103
 
51
104
  In the example above, @invoice will be loaded from
52
105
 
53
- @invoice = current_user.invoices.find(params[:invoice_id])
106
+ `@invoice = current_user.invoices.find(params[:invoice_id])`
54
107
 
55
108
  Then, @line will be loaded
56
109
 
57
- @line = @invoice.lines.find(params[:line_id])
110
+ `@line = @invoice.lines.find(params[:line_id])`
58
111
 
59
- Then finally the @charge will be loaded
112
+ Then, finally the @charge will be loaded
60
113
 
61
- @charge = @line.charges.find(params[:id])
114
+ `@charge = @line.charges.find(params[:id])`
62
115
 
63
- It's called "poor man's auth" because if a user attempts to hack the URL by passing ids for objects they don't own--- which Rails makes relatively easy with its default URL pattern-- they will hit ActiveRecord not found errros because the objects will not be found in the assocaited relationships.
116
+ It's called "poor man's auth" because if a user attempts to hack the URL by passing ids for objects they don't own--- which Rails makes relatively easy with its default URL pattern-- they will hit ActiveRecord not found errors (the objects they don't own won't be found in the associated relationship).
64
117
 
65
118
  It works, but it isn't granular. As well, it isn't appropriate for a large app with any level of intricacy to access control (that is, having roles).
66
119
 
67
- Your customers can delete their own objects by default (may be a good idea or a bay idea for you). If you don't want that, you should strip out the delete actions off the controllers.
120
+ Your customers can delete their own objects by default (may be a good idea or a bad idea for you). If you don't want that, you should strip out the delete actions off the controllers.
68
121
 
69
122
 
70
- ### auth=
123
+ ### `auth=`
71
124
 
72
- By default, it will be assumed you have a `current_user` for your user authentication. This will be treated as the "authentication root" for what is fundamentally "poor man's auth."
125
+ By default, it will be assumed you have a `current_user` for your user authentication. This will be treated as the "authentication root" for the "poor man's auth" explained above.
73
126
 
74
127
  The poor man's auth presumes that object graphs have only one natural way to traverse them (that is, one primary way to traverse them), and that all relationships infer that a set of things or their descendants are granted access to me for reading, writing, updating, and deleting.
75
128
 
@@ -92,38 +145,74 @@ If you supply nesting (see below), your nest chain will automatically begin with
92
145
 
93
146
 
94
147
 
95
- ### auth_identifier=
148
+ ### `auth_identifier=`
96
149
 
97
- Your controller will call a method authenticate_ (AUTH IDNETIFIER) bang, like:
150
+ Your controller will call a method authenticate_ (AUTH IDENTIFIER) bang, like:
98
151
 
99
- authenticate_user!
152
+ `authenticate_user!`
100
153
 
101
154
  Before all of the controller actions. If you leave this blank, it will default to using the variable name supplied by auth with "current_" stripped away.
102
155
  (This is setup for devise.)
103
156
 
104
- Leave blank for default, which is to match the auth.
157
+ Be sure to implement the following method in your ApplicationController or some other method. Here's a quick example using Devise. You will note in the code below, user_signed_in? is implemented when you add Devise methods to your User table.
158
+
159
+ As well, the `after_sign_in_path_for(user)` here is a hook for Devise also that provides you with after login redirect to the page where the user first intended to go.
160
+
161
+ ```
162
+ def authenticate_user!
163
+ if ! user_signed_in?
164
+ session['user_return_to'] = request.path
165
+ redirect_to new_user_registration_path
166
+ end
167
+ end
168
+
169
+ def after_sign_in_path_for(user)
170
+ session['user_return_to'] || account_url(user)
171
+ end
172
+ ```
173
+
174
+
175
+ The default (do not pass `auth_identifier=`) will match the `auth` (So if you use 'account' as the auth, `authenticate_account!` will get invoked from your generated controller; the default is always 'user', so you can leave both auth and auth_identifier off if you want 'user')
176
+
105
177
 
106
178
  `rails generate common_core:scaffold Thing auth=current_account auth_identifier=login`
107
- In this example, the controller produced with have:
179
+ In this example, the controller produced with:
180
+ ```
108
181
  before_action :authenticate_login!
182
+ ```
183
+ However, the object graph anchors would continue to start from current_account. That is,
184
+ ```
185
+ @thing = current_account.things.find(params[:id])
186
+ ```
109
187
 
110
-
111
- Use empty string to turn this method off:
188
+ Use empty string to **turn this method off**:
112
189
  `rails generate common_core:scaffold Thing auth=current_account auth_identifier=''`
113
190
 
191
+ In this case a controller would be generated that would have NO before_action to authenticate the account, but it would still treat the current_account as the auth root for the purpose of loading the objects.
114
192
 
115
- ### plural=
193
+ Please note that this example would product non-functional code, so you would need to manually fix your controllers to make sure `current_account` is available to the controller.
194
+
195
+
196
+ ### `plural=`
116
197
 
117
198
  You don't need this if the pluralized version is just + "s" of the singular version. Only use for non-standard plurlizations, and be sure to pass it as TitleCase (as if you pluralized the model name)
118
199
 
119
200
 
120
- ### --god
201
+ ### `--god`
121
202
 
122
203
  Use this flag to create controllers with no root authentication. You can still use an auth_identifier, which can be useful for a meta-leval authentication to the controoler.
123
204
 
124
205
  For example, FOR ADMIN CONTROLLERS ONLY, supply a auth_identifier and use --god flag
125
206
 
126
- ### --with-index
207
+ In God mode, the objects are loaded directly from the base class (these controllers have full access)
208
+ ```
209
+ def load_thing
210
+ @thing = Thing.find(params[:id])
211
+ end
212
+
213
+ ```
214
+
215
+ ### `--with-index`
127
216
 
128
217
  By default no master index views get produced. Use this flag to produce an index view.
129
218
 
@@ -131,38 +220,60 @@ The index views simply include the _list partial but pass them a query to use:
131
220
 
132
221
  `= render partial: "list", locals: {things: Thing.order("created_at DESC").page(1)}`
133
222
 
223
+ You will note that unlike other scaffold you may have seen, the "all" view is found at
224
+ ```
225
+ all.haml
226
+ ```
134
227
 
228
+ Common core generate ONLY this top-level (non-partial) HAML file, relying on Rails partials to do the rest. This lets us get little fancy with reloading and re-rendering, and provides for a smooth consistent starting point for you to customize the views.
135
229
 
230
+ The intention is that you DO NOT generate any all.haml views, because you will probably be building a dashboard that composites several different tables into a single page.
136
231
 
232
+ When you do that, load the list views from the build scaffolding to define the different sections of your page
137
233
 
234
+ ```
235
+ = render partial: "dashboard/things/list", locals: {things: current_user.things.order("created_at DESC").page(1)}
236
+ ```
138
237
 
238
+ Because it's rare that you actually want to build a page that is just a list of one table, the index views are not generate by default.
139
239
 
140
240
 
141
- # TROUBLESHOOTING
241
+ ### `--specs-only`
142
242
 
143
- ## NoMethodError in HellosController#index undefined method `authenticate_user!' for #<HellosController:0x00007fcc2decf828> Did you mean? authenticate_with_http_digest
144
-
145
-
146
- --> Install Devise
243
+ Produces ONLY the controller spec file, nothing else.
147
244
 
148
245
 
246
+ ### `--no-specs`
247
+
248
+ Produces all the files except the spec file.
149
249
 
150
- ## Uncaught ReferenceError: $ is not defined
151
-
152
- --> Install Jquery. Here's a good link: https://www.botreetechnologies.com/blog/introducing-jquery-in-rails-6-using-webpacker
153
250
 
154
- Be sure to 1) add with Yark, 2) Modify environment.js, 3) Modify application.js
155
251
 
156
252
 
157
253
 
158
- ## Nothing happens after you install jQuery
254
+ # TROUBLESHOOTING
255
+
256
+ ## NoMethodError in HellosController#index undefined method `authenticate_user!' for #<HellosController:0x00007fcc2decf828> Did you mean? authenticate_with_http_digest
257
+
258
+ --> Install Devise or implement current_user method on your controller or use with auth= and/or auth_identifier= to specify how you want to authenticate your user.
259
+
159
260
 
160
- --> Install Rails UJS
261
+ ## Uncaught ReferenceError: $ is not defined
262
+
263
+ --> Install Jquery + Rails UJS
264
+ `yarn add jquery`
161
265
  `yarn add @rails/ujs`
162
266
 
267
+ Add to application.js
268
+ ```
269
+ require("jquery")
270
+ ```
271
+
163
272
  And add to config/webpack/environment.js
164
273
 
165
274
  ```
275
+ const { environment } = require('@rails/webpacker')
276
+
166
277
  const webpack = require('webpack')
167
278
  environment.plugins.prepend('Provide',
168
279
  new webpack.ProvidePlugin({
@@ -171,5 +282,7 @@ environment.plugins.prepend('Provide',
171
282
  Rails: ['@rails/ujs']
172
283
  })
173
284
  )
285
+
174
286
  module.exports = environment
287
+
175
288
  ```