hot-glue 0.4.5 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +71 -0
  3. data/.github/FUNDING.yml +2 -2
  4. data/.gitignore +4 -1
  5. data/Gemfile +5 -1
  6. data/Gemfile.lock +16 -16
  7. data/README.md +340 -251
  8. data/README2.md +79 -0
  9. data/config/database.yml +8 -83
  10. data/db/schema.rb +1 -0
  11. data/lib/generators/hot_glue/install_generator.rb +0 -1
  12. data/lib/generators/hot_glue/layout/builder.rb +51 -33
  13. data/lib/generators/hot_glue/markup_templates/erb.rb +97 -88
  14. data/lib/generators/hot_glue/scaffold_generator.rb +292 -91
  15. data/lib/generators/hot_glue/templates/controller.rb.erb +51 -47
  16. data/lib/generators/hot_glue/templates/erb/_form.erb +3 -2
  17. data/lib/generators/hot_glue/templates/erb/_line.erb +1 -1
  18. data/lib/generators/hot_glue/templates/erb/_list.erb +31 -21
  19. data/lib/generators/hot_glue/templates/erb/_new_button.erb +1 -1
  20. data/lib/generators/hot_glue/templates/erb/_new_form.erb +4 -3
  21. data/lib/generators/hot_glue/templates/erb/_show.erb +10 -6
  22. data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +4 -4
  23. data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +2 -2
  24. data/lib/generators/hot_glue/templates/erb/edit.erb +2 -2
  25. data/lib/generators/hot_glue/templates/erb/index.erb +1 -1
  26. data/lib/generators/hot_glue/templates/erb/new.erb +1 -1
  27. data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +2 -2
  28. data/lib/hotglue/version.rb +3 -1
  29. metadata +6 -20
  30. data/db/schema.rb +0 -60
  31. data/lib/generators/hot_glue/markup_templates/haml.rb +0 -243
  32. data/lib/generators/hot_glue/markup_templates/slim.rb +0 -9
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
1
 
2
- [![Build Status](https://app.travis-ci.com/jasonfb/hot-glue.svg?branch=main)](https://travis-ci.com/jasonfb/hot-glue)
3
-
2
+ [![Hot Glue](https://circleci.com/gh/jasonfb/hot-glue.svg?style=shield)](https://circleci.com/gh/jasonfb/hot-glue)
4
3
 
5
4
  Hot Glue is a Rails scaffold builder for the Turbo era. It is an evolution of the admin-interface style scaffolding systems of the 2010s ([activeadmin](https://github.com/activeadmin/activeadmin), [rails_admin](https://github.com/sferik/rails_admin), and [active_scaffold](https://github.com/activescaffold/active_scaffold)).
6
5
 
7
-
8
6
  Using Turbo-Rails and Hotwire (default in Rails 7) you get a lightning-fast out-of-the-box CRUD building experience.
9
7
 
10
8
  Every page displays only a list view: new and edit operations happen as 'edit-in-place', so the user never leaves the page.
@@ -19,18 +17,20 @@ By default, it generates code that gives users full control over objects they 'o
19
17
 
20
18
  Hot Glue generates functionality that's quick and dirty. It lets you be crafty. As with a real hot glue gun, use with caution.
21
19
 
22
- * Build plug-and-play scaffolding mixing generated ERB or HAML with the power of Hotwire and Turbo-Rails
23
- * Everything edits-in-place (unless you use --big-edit, then it won't)
24
- * Automatically Reads Your Models (make them before building your scaffolding!)
20
+ * Build plug-and-play scaffolding mixing generated ERB with the power of Hotwire and Turbo-Rails
21
+ * Everything edits-in-place (unless you use `--big-edit`, then it won't)
22
+ * Automatically Reads Your Models (make them AND migrate your DB before building your scaffolding!)
25
23
  * Excellent for CREATE-READ-UPDATE-DELETE (CRUD), lists with pagination (coming soon: searching & sorting)
26
24
  * Great for prototyping, but you should learn Rails fundamentals first.
27
25
  * 'Packaged' with Devise, Kaminari, Rspec, FontAwesome
28
- * Create system specs automatically along with the generated code.
26
+ * Create system specs automatically along with the generated code.
29
27
  * Nest your routes model-by-model for built-in poor man's authentication.
30
28
  * Throw the scaffolding away when your app is ready to graduate to its next phase.
31
29
 
32
- # Hot Glue Tutorial 
33
- ## [GET THE COURSE TODAY (includes Hot Glue License)](https://jfb.teachable.com/courses/hot-glue-in-depth-tutorial/?utm_source=github.com&utm_campaign=github_hot_glue_readme_page) **only $60 USD!**
30
+
31
+ # Get Hot Glue
32
+ ## [Licence Only Option Now Available](https://heliosdev.shop/p/hot-glue/?utm_source=github.com&utm_campaign=github_hot_glue_readme_page) **only $50 USD!**
33
+ ## [GET THE COURSE TODAY (includes Licence)](https://jfbcodes.com/courses/hot-glue-in-depth-tutorial/?utm_source=github.com&utm_campaign=github_hot_glue_readme_page) **only $60 USD!**
34
34
 
35
35
  | | |
36
36
  | ------------- | ------------- |
@@ -55,44 +55,39 @@ Instantly get a simple CRUD interface
55
55
 
56
56
  # Getting Started
57
57
 
58
- _If you are on Rails 6, skip to section Rails 6 Setup and complete those steps FIRST._
58
+ _If you are on Rails 6, see [LEGACY SETUP FOR RAILS 6](https://github.com/jasonfb/hot-glue/README2.md) and complete those steps FIRST._
59
59
 
60
60
 
61
- ## 1. ADD RSPEC, FACTORY-BOT, AND FFAKER
61
+ ## 1. Rails 7 New App
62
62
 
63
- add these 3 gems to your gemfile **inside a group for both :development and :test*. Do not add these gems to only the :test group or else your will have problems with the generators.
64
- ```
65
- gem 'rspec-rails'
66
- gem 'factory_bot_rails'
67
- gem 'ffaker'
68
- ```
63
+ There are two ways to create new apps on Rails 7: With or without ImportMap. These instructions prefer the **without Importmap** method, but to help you choose [see this post](https://jasonfleetwoodboldt.com/courses/stepping-up-rails/rails-7-do-i-need-importmap-rails/)
69
64
 
70
- - run `rails generate rspec:install`
65
+ `rails new --css=bootstrap --javascript=webpack --database=postgresql`
71
66
 
72
- - replace `application.css` with a new file (delete old contents) `application.scss`
67
+ Confirm that both Stimulus and Turbo are working.
73
68
 
74
- THIS FILE CAN BE EMPTY, BUT WILL BE USED BY THEME INSTALLER
69
+ **If using JSBundling, make sure to use the new `bin/dev rails` instead of the old `rails server` or else your Webpack will not compile.**
75
70
 
76
- ## 2. ADD BOOTSTRAP (OPTIONAL)
71
+ For the quick step-by-step to help you confirm that both Stimulus and Turbo are working for your new JSBundling-Rails/CSSBunlding-Rails setup [see this post](https://jasonfleetwoodboldt.com/courses/stepping-up-rails/rails-7-new-app-with-js-bundling-css-bundling/).
77
72
 
78
- _BOOTSTRAP IS NO LONGER NEEDED_, but I recommend it.
73
+ (Note that Bootstrap is optional for Hot Glue. Here, I am just showing you the default isntallation for simplicity.)
79
74
 
80
- IF you are using `--layout=bootstrap` (step 3), you must install Bootstrap here.
75
+ For the old method of installing Bootstrap [see this post](https://jasonfleetwoodboldt.com/courses/stepping-up-rails/rails-7-bootstrap/)
81
76
 
82
- Bootstrap with Webpacker is no longer in Rails 7 by default. (For that see ________TBD________)
77
+ Remember, for Rails 6 you must go through the [LEGACY SETUP FOR RAILS 6](https://github.com/jasonfb/hot-glue/README2.md) before continuing.
83
78
 
84
- For Bootstrap with Sprockets (recommended by Rails team), see https://github.com/twbs/bootstrap-rubygem
79
+ ## 2. ADD RSPEC, FACTORY-BOT, AND FFAKER
85
80
 
86
- If going the the Bootstrap with Sprockets route, note the gem is
81
+ add these 3 gems to your gemfile **inside a group for both :development and :test*. Do not add these gems to only the :test group or else your will have problems with the generators.
87
82
  ```
88
- gem 'bootstrap', '~> 5.1.3'
83
+ gem 'rspec-rails'
84
+ gem 'factory_bot_rails'
85
+ gem 'ffaker'
89
86
  ```
90
87
 
91
- Then, all you need to do is add to `app/assets/stylesheets/application.scss`
88
+ - run `rails generate rspec:install`
89
+
92
90
 
93
- ```
94
- @import "bootstrap";
95
- ```
96
91
 
97
92
  ## 3. HOTGLUE INSTALLER
98
93
  Add `gem 'hot-glue'` to your Gemfile & `bundle install`
@@ -101,22 +96,14 @@ Purchase a license at https://heliosdev.shop/hot-glue-license
101
96
 
102
97
  During in installation, you MUST supply a `--layout` flag.
103
98
 
104
- ### `--layout` flag
105
- Here you will set up and install Hot Glue for the first time. It will install a config file that will save two preferences: layout (hotglue or bootstrap) and markup (erb or haml or slim).
106
-
107
- Once you run the installer, the installer will save what you set it to in `config/hot_glue.yml`. Newly generated scaffolds will use these two settings, but you can modify them just by modifying the config file (you don't need to re-run the installer)
99
+ ### `--layout` flag (NOTE: haml and slim are no longer supported at this time)
100
+ Here you will set up and install Hot Glue for the first time.
108
101
 
109
- If you do NOT specify `--layout=bootstrap`, then `hotglue` will be assumed. When constructing scaffold with bootstrap layout (at this time Hot Glue peeks into config/hot_glue.yml to see what you've set there), your views come out with divs that have classes like .container-fluid, .row, and .col. You'll need to install Bootstrap separately, any way you like, but jQuery is not required as Hot Glue does not rely on jQuery-dependant Bootstrap features.
102
+ It will install a config file that will save two preferences: layout (`hotglue` or `bootstrap`)
110
103
 
104
+ The installer will create `config/hot_glue.yml`.
111
105
 
112
- If instead you install Hot Glue (or switch the setting) using the default layout mode (`--layout=hotglue`),
113
- your scaffolding will be built using no-Bootstrap syntax: It has its own syntax with classes like
114
- `.scaffold-container`,
115
- `.scaffold-list`,
116
- `.scaffold-row`, and
117
- `.scaffold-cell`
118
-
119
- During the installation, if your `--layout` flag is left unspecified or set to `hotglue` you must also pass `--theme` flag.
106
+ During the installation, if your `--layout` flag is set to `hotglue` you must also pass `--theme` flag.
120
107
 
121
108
  the themes are:
122
109
  • like_mountain_view (Google)
@@ -124,30 +111,76 @@ the themes are:
124
111
  • like_bootstrap (bootstrap 4 copy)
125
112
  • dark_knight (_The Dark Night_ (2008) inspired)
126
113
  • like_cupertino (modern Apple-UX inspired)
127
- • gradeschool (spiral bound/lined notebook inspired)
128
-
129
- Please note that the scaffold is ** built with different market up for boostrap**, so you cannot switch between the Bootstrap and Hotglue layouts without rebuilding the scaffold.
130
-
131
- (On the other hand, if you build within the Hotglue layout, all of the Hotglue theme files CAN be swapped out without rebuilding the scaffold.)
132
-
133
- The themes are just SCSS files installed into app/assets/stylesheets. You can tweak or modify or remove them after they get installed.
134
-
135
114
 
136
115
  ### `--markup` flag
137
116
 
138
- default is `erb`
117
+ default is `erb`. IMPORTANT: As of right now, HAML and SLIM are not currently supported.
139
118
 
140
119
 
141
- ## 3. RUN HOT-GLUE INSTALL:
142
120
  ### example installing ERB using Bootstrap layout:
143
121
  `rails generate hot_glue:install --markup=erb --layout=bootstrap`
144
122
 
145
123
  ### Example installing HAML using Hot Glue layout and the 'like_mountain_view' (Gmail-inspired) theme:
146
124
  `rails generate hot_glue:install --markup=erb --layout=hotglue --theme=like_mountain_view`
147
125
 
126
+ The Hot Glue installer did several things for you in this step. Examine the git diffs or see 'Hot Glue Installer Notes' below.
127
+
128
+
129
+ ## 4. install font-awesome (optional)
130
+
131
+ I recommend
132
+ https://github.com/tomkra/font_awesome5_rails
133
+ or
134
+ https://github.com/FortAwesome/font-awesome-sass
135
+
136
+
137
+ ## 5. Devise
138
+
139
+ (or only use --gd mode, see below)
140
+
141
+ Add to your Gemfile
142
+
143
+ As of 2022-01-26 Devise for Rails 7 is still not released so you must use **main branch**, like so:
144
+
145
+ `gem 'devise', branch: 'main', git: 'https://github.com/heartcombo/devise.git'`
146
+
147
+ (If you are on Rails 6, you must do ALL of the steps in the Legacy Setup steps. Be sure not to skip **Legacy Step #5** (below))
148
+
149
+ For Rails 7, be sure you are on the main branch of devise above and your logins should work. (The previously necessary step of disabling turbo shown in Legacy Step #5 is no longer needed. )
150
+
151
+ You MUST run the installer FIRST or else you will put your app into a non-workable state:
152
+ ```
153
+ rails generate devise:install
154
+ ```
155
+
156
+ IMPORTANT: Follow the instructions the Devise installer gives you, *Except Step 3*, you can skip this step:
157
+ ```
158
+ 3. Ensure you have flash messages in app/views/layouts/application.html.erb.
159
+ For example:
160
+
161
+ <p class="notice"><%= notice %></p>
162
+ <p class="alert"><%= alert %></p>
163
+
164
+ ```
165
+
166
+ Be sure to create primary auth model with:
167
+
168
+ `rails generate devise User name:string`
169
+
170
+ Remember, you don't need to tell Devise that your User has an email, an encrypted password, a reset token, and a 'remember me' flag to let the user stay logged in.
171
+
172
+ Those features come by default with Devise, and you'll find the fields for them in the newly generated migration file.
173
+
174
+ In this example above, you are creating all of those fields along with a simple 'name' (string) field for your User table.
175
+
176
+
177
+
148
178
 
149
- ## 3(B). Modify `application.html.erb`
150
- (THIS WAS AUTOMATICALLY DONE BY THE HOT GLUE INSTALLATION -- CONFIRM CHANGES ONLY)
179
+ ### Hot Glue Installer Notes
180
+
181
+ These things were **done for you** in Step #3 (above). You don't need to think about them but if you are familiar with Capybara and/or adding Hot Glue to an existing app, you may want to:
182
+
183
+ #### Hot Glue modified `application.html.erb`
151
184
  Note: if you have some kind of non-standard application layout, like one at a different file
152
185
  or if you have modified your opening <body> tag, this may not have been automatically applied by the installer.
153
186
 
@@ -156,8 +189,7 @@ or if you have modified your opening <body> tag, this may not have been automati
156
189
  <%= render partial: 'layouts/flash_notices' %>
157
190
  ```
158
191
 
159
- ## 3(C). Modify `rails_helper.rb`
160
- (THIS WAS AUTOMATICALLY DONE BY THE HOT GLUE INSTALLATION)
192
+ #### Hot Glue modified `rails_helper.rb`
161
193
  Note: if you have some kind of non-standard rails_helper.rb, like one that does not use the standard ` do |config|` syntax after your `RSpec.configure`
162
194
  this may not have been automatically applied by the installer.
163
195
 
@@ -170,8 +202,7 @@ this may not have been automatically applied by the installer.
170
202
  ```
171
203
 
172
204
 
173
- ## 3(D) CAPYBARA: SWITCH FROM RACK-TEST TO HEADLESS CHROME
174
- (THIS WAS AUTOMATICALLY DONE BY THE HOT GLUE INSTALLATION)
205
+ #### Hot Glue switched Capybara from RACK-TEST to HEADLESS CHROME
175
206
 
176
207
  - By default Capybara is installed with :rack_test as its driver.
177
208
  - This does not support Javascript, and the code from Hot Glue IS NOT fallback compatible-- it will not work on non-Javascript browsers.
@@ -192,7 +223,7 @@ By default, the installer should have added this option to your `rails_helper.rb
192
223
  Capybara.default_driver = :selenium_chrome_headless
193
224
  ```
194
225
 
195
- Alternatively, can define your own driver like so:
226
+ Alternatively, you can define your own driver like so:
196
227
 
197
228
  ```
198
229
  Capybara.register_driver :my_headless_chrome_desktop do |app|
@@ -211,8 +242,7 @@ Alternatively, can define your own driver like so:
211
242
 
212
243
  ```
213
244
 
214
-
215
- (THIS WAS ALSO AUTOMATICALLY DONE BY THE HOT GLUE INSTALLATION)
245
+ #### Hot Glue Added a Quick (Old-School) Capybara Login For Devise
216
246
 
217
247
  - for a quick Capybara login, create a support helper in `spec/support/` and log-in as your user
218
248
  - in the default code, the devise login would be for an object called account and lives at the route `/accounts/sign_in`
@@ -228,148 +258,12 @@ Alternatively, can define your own driver like so:
228
258
  end
229
259
  ```
230
260
 
231
-
232
- ## 4. install font-awesome (optional)
233
-
234
- I recommend
235
- https://github.com/tomkra/font_awesome5_rails
236
- or
237
- https://github.com/FortAwesome/font-awesome-sass
238
-
239
-
240
- ## 5. Devise
241
-
242
- (or only use --gd mode, see below)
243
-
244
- Add to your Gemfile
245
-
246
- As of 2021-12-28 Devise for Rails 7 is still not released so you must use main branch, like so:
247
- `gem 'devise', branch: 'main', git: 'https://github.com/heartcombo/devise.git'`
248
-
249
- If on Rails 6 **or** Rails 7, you must do the steps in **Legacy Step #5** (below).
250
-
251
- (If you are on Rails 6, you must do ALL of the steps in the Legacy Setup steps.)
252
-
253
- To be clear: You CAN use Devise with Rails 7, but you must still do the Legacy Step #5 described below for your login to work.
254
-
255
- ```
256
- rails generate devise:install
257
- ```
258
-
259
- IMPORTANT: Follow the instructions the Devise installer gives you, *Except Step 3*, you can skip this step:
260
- ```
261
- 3. Ensure you have flash messages in app/views/layouts/application.html.erb.
262
- For example:
263
-
264
- <p class="notice"><%= notice %></p>
265
- <p class="alert"><%= alert %></p>
266
-
267
- ```
268
-
269
-
270
- As described in Legacy Step #5, **you cannot** skip Devise installer Step 4, even though the installer tells you it is optional:
271
- ```
272
- 4. You can copy Devise views (for customization) to your app by running:
273
-
274
- rails g devise:views
275
-
276
- ```
277
- Once you copy the files, you must modify the Devise views to disable Turbo as described in Legacy Step #5.
278
-
279
-
280
- ## LEGACY SETUP FOR RAILS 6
281
-
282
- (Note Legacy Step #5 is necessary for BOTH Rails 6 and Rails 7.)
283
-
284
-
285
- ## Legacy Step #1. ADD HOTWIRE
286
- (RAILS 6 ONLY— SKIP THIS STEP FOR RAILS 7)
287
- ```
288
- yarn add @hotwired/turbo-rails
289
- ```
290
- or `npm install @hotwired/turbo-rails`
291
-
292
-
293
- ## Legacy Step #2. SWITCH FROM TurblLinks to Turbo-Rails
294
- (RAILS 6 ONLY — SKIP FOR RAILS 7)
295
- (THIS WAS AUTOMATICALLY DONE BY THE HOT GLUE INSTALLATION -- CONFIRM CHANGES ONLY)
296
- - Add `gem 'turbo-rails'` to your Gemfile & `bundle install`
297
- - Then install it with `rails turbo:install`
298
- - The Turbo install has switched your action cable settings from 'async' to Redis, so be sure to start a redis server
299
- - in `app/javascript/packs/application.js` remove this line
300
- ```
301
- import Turbolinks from "turbolinks"
302
- ```
303
- and replace it with
304
- ```
305
- import { Turbo } from "@hotwired/turbo-rails"
306
- ```
307
-
308
-
309
- Also replace
310
- ```
311
- Turbolinks.start()
312
- ```
313
- with:
314
- ```
315
- Turbo.start()
316
- ```
317
-
318
-
319
- ## Legacy Step #3. INSTALL WEBPACKER
320
- (_SKIP FOR RAILS 7_ unless you want to use Webpacker with Rails 7)
321
-
322
- ** For webpacker, you must be using Node version ^12.13.0 || ^14.15.0 || >=16 **
323
-
324
- I recommend Node Version Manager (NVM) to switch between nodes. You will not be able to get through the following command with a Node version that does not match above.
325
-
326
- Check your node version with `node -v`
327
-
328
- ```
329
- `yarn add @rails/webpacker`
330
- ```
331
-
332
-
333
- rails webpacker:install
334
-
335
- ## Legacy Step #4: ENUM Support
336
- For Enum support, I recommend activerecord-pg_enum
337
- Instructions for Rails 6 are here:
338
- https://jasonfleetwoodboldt.com/courses/stepping-up-rails/enumerated-types-in-rails-and-postgres/
339
-
340
- _This functionality is now built-in to Rails 7._
341
-
342
-
343
- ## Legacy Step #5-- Fix Devise if adding Turbo To Your Project
344
- ## IMPORTANT: Devise currently has serious compatibility issues with Turbo Rails. In particular, your log-in screens do not work out of the box. Follow the next step to fix them.
345
-
346
- Manually port the Devise views into your app with
347
-
348
- `rails generate devise:views`
349
-
350
- Edit `devise/registrations/new`, `devise/sessions/new`, `devise/passwords/new` and `devise/confirmations/new` modifying all four templates like so:
351
-
352
- form_for(resource, as: resource_name, url: session_path(resource_name) ) do |f|
353
-
354
-
355
-
356
- add the data-turbo false option in the html key:
357
-
358
-
359
- form_for(resource, as: resource_name, **html: {'data-turbo' => "false"},** url: session_path(resource_name) ) do |f|
360
-
361
-
362
-
363
- This tells Devise to fall back to non-Turbo interaction for the log-in and registration. For the rest of the app, we will use Turbo Rails interactions.
364
-
365
-
366
261
  ---
367
262
  ---
368
263
 
369
264
 
370
265
  # HOT GLUE DOCS
371
266
 
372
-
373
267
  ## First Argument
374
268
  (no double slash)
375
269
 
@@ -404,33 +298,54 @@ end
404
298
  ```
405
299
 
406
300
 
407
- ### `--nest=`
301
+ ### `--nested=`
302
+
303
+ This object is nested within another tree of objects, and there is a nested route in your `routes.rb` file. When specifying the parent(s), be sure to use **singular case**.
304
+
305
+ #### Example #1: One-level Nesting
306
+ Invoice `has_many :lines` and a Line `belongs_to :invoice`
408
307
 
409
- pass `--nest=` to denote a nested resources
308
+ ```
309
+ resources :invoices do
310
+ resource :lines do
311
+ end
312
+ ```
410
313
 
314
+ `rails generate hot_glue:scaffold Invoice`
411
315
 
412
- `rails generate hot_glue:scaffold Line --nest=invoice`
316
+ `rails generate hot_glue:scaffold Line --nested=invoice`
413
317
 
414
- In this example, it is presumed that the current user has_many :invoices, and that invoices have many :lines
415
318
 
319
+ Remember, nested should match how the hierarchy of nesting is in your `routes.rb` file. (Which Hot Glue does not create or edit for you.)
416
320
 
417
- For multi-level nesting use slashes to separate your levels of nesting. Remember, you should match what you have in your routes.rb file.
321
+ #### Example #2: Two-level Nesting
418
322
 
323
+ Invoice `has_many :lines` and a Line `belongs_to :invoice`
324
+ Line `has_many :charges` and Charge `belongs_to :line`
325
+
326
+ **config/routes.rb**
419
327
  ```
420
328
  resources :invoices do
421
329
  resources :lines do
422
330
  resources :charge
423
331
  end
424
332
  end
425
-
426
333
  ```
427
- 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
428
334
 
429
335
 
430
- To generate scaffold:
431
- `rails generate hot_glue:scaffold Charge --nest=invoice/line`
336
+ _For multi-level nesting use slashes to separate your levels of nesting._
337
+
338
+ `rails generate hot_glue:scaffold Invoice`
339
+
340
+ `rails generate hot_glue:scaffold Line --nested=invoice`
432
341
 
433
- 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:
342
+ `rails generate hot_glue:scaffold Charge --nested=invoice/line`
343
+
344
+
345
+
346
+ For non-Gd controllers, your auth root will be used as the starting point when loading the objects from the URL if this object is nested.
347
+
348
+ (For Gd controllers the root object will be loaded directly from the ActiveRecord object.)
434
349
 
435
350
  In the example above, @invoice will be loaded from
436
351
 
@@ -444,13 +359,37 @@ Then, finally the @charge will be loaded
444
359
 
445
360
  `@charge = @line.charges.find(params[:id])`
446
361
 
447
- It's called "poor man's access control" 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).
362
+ This is "starfish access control" or "poor man's access control." It works when the current user has several things they can manage, and by extension can manage children of those things.
363
+
448
364
 
449
- 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).
365
+ #### Optionalized Nested Parents
450
366
 
451
- 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.
367
+ Add `~` in front of any nested parameter (any parent in the `--nest` list) you want to make optional. This creates a two-headed controller: It can operate with or without that optionalized parameter.
452
368
 
369
+ This is an advanced feature is to use **two duplicative routes to the same controller**. You can only use this feature with Gd controller.
453
370
 
371
+ Specify your controller *twice* in your routes.rb. Then, in your `--nest` setting, add `~` to any nested parent you want to **make optional**. "Make optional" means the controller will behave as-if it exists in two places: once, at the normal nest level. Then the same controller will 'exist' again one-level up in your routes. **If the route has sub-routes, you'll need to re-specify the entire subtree also**.
372
+ ```
373
+ namespace :admin
374
+ resources :users do
375
+ resources :invoices
376
+ end
377
+ resources :invoices
378
+ end
379
+ ```
380
+
381
+ Even though we have two routes pointed to invoices, both will go to the same controller (`invoices_controller.rb`)
382
+
383
+ ```
384
+ rails generate hot_glue:scaffold User --namespace=admin --gd --downnest=invoices
385
+ rails generate hot_glue:scaffold Invoice --namespace=admin --gd --nest=~users
386
+ ```
387
+ Notice for the Invoice build, the parent user is *optionalized* (not 'optional'-- optionalized: to be made so it can be made optional).
388
+
389
+ The Invoices controller, which is a Gd controller, will load the User if a user is specified in the route (`/admin/users/:user_id/invoices/`). It will ALSO work at `/admin/invoices` and will switch back into loading directly from the base class when routed this way.
390
+
391
+
392
+
454
393
  ### `--auth=`
455
394
 
456
395
  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.
@@ -474,8 +413,6 @@ It is also presumed that when viewing their own dashboard of things, the user wi
474
413
  If you supply nesting (see below), your nest chain will automatically begin with your auth root object (see nesting)
475
414
 
476
415
 
477
-
478
-
479
416
  ### `--auth_identifier=`
480
417
 
481
418
  Your controller will call a method authenticate_ (AUTH IDENTIFIER) bang, like:
@@ -549,22 +486,79 @@ If you specify an include list, it will be treated as a whitelist: no fields wil
549
486
 
550
487
  `rails generate hot_glue:scaffold Account --include=first_name,last_name,company_name,created_at,kyc_verified_at`
551
488
 
552
- Separate COLUMNS by a COLON
489
+ You may not specify both include and exclude.
490
+
491
+ Include setting is affected by both specified grouping and smarty layouts, explained below.
492
+
493
+
494
+ #### Specified Grouping Mode
495
+
496
+ To specify grouped columns, separate COLUMNS by a COLON, then separate fields with commas. Specified groupings work like smart layouts (see below), except you drive which groupings make up the columns.
497
+
498
+ (Smarty layouts, below, achieves the same effect but automatically groups your fields into a smart number of columns. )
499
+
553
500
  If you want to group up fields together into columns, use a COLON (`:`) character to specify columns.
554
- Your input may have a COLON at the end of it, but otherwise your columns will made flush left.
555
501
 
556
- Without colons, no group will happen, so these two fields would display in two columns:
502
+ Your input **may** have a COLON at the end of it, but otherwise your columns will made **flush left**.
503
+
504
+ Without specified grouping (and not using smart layout), no group will happen, so these two fields would display in two columns:
557
505
  `--include=api_id,api_key`
558
506
 
559
- With a trailing colon, you're telling Hot Glue to make the two fields into column #1. (Here, there is no other column.)
507
+ With a trailing colon you would be specifying the grouping. You're telling Hot Glue to make the two fields into column #1. (There is no other column.)
560
508
  `--include=api_id,api_key:`
561
509
 
510
+
562
511
  If, for example, you wanted to put the `name` field into column #1 and then the api_id and api_key into column #2, you would use:
563
512
  `--include=name:api_id,api_key`
564
513
 
565
- Specifying any colon in your include syntax switches the builder into 12-column mode, whereas without you might create more than 12 columns if there are too many feilds for the available columns on the layout.
566
514
 
567
- You may not specify both include and exclude.
515
+
516
+ Specifying any colon in your include syntax switches the builder into specified grouping mode. The effect will be that the fields will be stacked together into nicely fit columns. (This will look confusing if your user expect an Excel-like interface.)
517
+
518
+ With Bootstrap in specified grouping or smart layout mode, it automatically attempts to fit everything into 12-columns.
519
+
520
+ Using Bootstrap with neither specified grouping nor smart layouts may make 12 columns, which will produce strange result. (Bootstrap is not designed to work with, for example, a 13-column layout.)
521
+
522
+ You should typically either specify your grouping or use smart layouts when building with Bootstrap, but if your use case does not fit the stacking feature you can specify neither flag and then you may then have to deal with the over-stuffed layouts as explained.
523
+
524
+
525
+
526
+ ### `--smart-layout` mode (automatic grouping) (default: false)
527
+
528
+ Smart layouts are like specified grouping but Hot Glue does the work of figuring out how many fields you want in each column.
529
+
530
+ It will concatinate your fields into groups that will fit into the Bootstrap's 12-column grid.
531
+
532
+ The effect will be that the fields will be stacked together into nicely fit columns.
533
+
534
+ **Some people expect each field to be a column and think this looks strange.**
535
+
536
+ **If your customer is used to Excel, this feature will confuse them.**
537
+
538
+ Also, this feature will **probably not** be supported by the SORTING (not yet implemented; TBD). I'm not really sure it makes sense to build a non-columnar layout with sorting, so I think I **probably won't support smart layouts** if you want sorting. (You will be forced to choose between the two which I think makes sense.)
539
+
540
+ The layout builder works from right-to-left and starts with 12, the number of Bootstrap's columns.
541
+
542
+ It reserves 2 columns for the default buttons. Then +1 additional column for **each magic button** you have specified.
543
+
544
+ Then it takes 4 columns for **each downnested portal**.
545
+
546
+ If you're keeping track, that means we may have used 6 to 8 out of our Bootstrap columns already if we have buttons & portals. (With no portals and no magic buttons you have a nice even 10 columns to work with.)
547
+
548
+ If we have 2 downnested portals and only the default buttons, that uses 10 out of 12 Bootstrap columns, leaving only 2 bootstrap columns for the fields.
549
+
550
+ The layout builder takes the number of columns left and then distributes the feilds 'evenly' among them. However, note that order specified translates to up-to-down within the column, and then left-to-right across the columns, like so:
551
+
552
+ A D G
553
+
554
+ B E H
555
+
556
+ C F I
557
+
558
+ This is what would happen if 9 fields, specified in the order A,B,C,D,E,F,G,H,I, were distributed across 3 columns.
559
+
560
+ (If you had a number of fields that wasn't easily divisible by the number of columns, it would leave the final column a few fields short of the others.)
561
+
568
562
 
569
563
 
570
564
  ### `--show-only=`
@@ -619,9 +613,14 @@ For more information see Example 5 in the Tutorial
619
613
  ### `--downnest`
620
614
 
621
615
  Automatically create subviews down your object tree. This should be the name of a has_many relationship based from the current object.
622
- You will need to build scaffolding with the same name for the related object as well.
623
- On the list view, the object you are currently building will be built with a sub-view list of the objects related from the given line.
616
+ You will need to build scaffolding with the same name for the related object as well. On the list view, the object you are currently building will be built with a sub-view list of the objects related from the given line.
617
+
618
+ The downnested child table (not to be confused with this object's `--nested` setting, where you are specifying this object's _parents_) is called a **child portal**. When you create a record in the child portal, the related record is automatically set to be owned by its parent (as specified by `--nested`). For an example, see the [v0.4.7 release notes](https://github.com/jasonfb/hot-glue/releases/tag/v0.4.7).
624
619
 
620
+ Can now be created with more space (wider) by adding a `+` to the end of the downnest name
621
+ - e.g. `--downnest=abc+,xyz`
622
+
623
+ The 'Abcs' portal will display as 5 bootstrap columns instead of the typical 4. (You may use multiple ++ to keep making it wider but the inverse with minus is not supported
625
624
 
626
625
 
627
626
 
@@ -661,6 +660,18 @@ Omits pagination. (All list views have pagination by default.)
661
660
 
662
661
  Omits list action. Only makes sense to use this if you are create a view where you only want the create button you want to navigate to the update screen alternative ways.
663
662
 
663
+
664
+ ### `--no-list-labels`
665
+
666
+ Omits list labels at the top of the list.
667
+
668
+ ### `--no-list-heading`
669
+
670
+ Omits the list heading.
671
+
672
+ (Note that on a per model basis, you can also globally omit the heading or set a unique value using
673
+ `@@table_label_singular` and `@@table_label_plural` on your model objects.)
674
+
664
675
  ### `--no-create`
665
676
 
666
677
  Omits create action.
@@ -681,7 +692,6 @@ Sometimes you might want to redisplay the entire list after you make an update (
681
692
 
682
693
  To do this, use flag `--display_list_after_update`. The update will behave like delete and re-fetch all the records in the result and tell Turbo to swap out the entire list.
683
694
 
684
- ### `--smart-layout` (default: false)
685
695
 
686
696
 
687
697
 
@@ -692,26 +702,96 @@ HotGlue will copy a file named base_controller.rb to the same folder where it tr
692
702
 
693
703
  Obviously, the created controller will always have this base controller as its subclass. In this way, you are encouraged to implement functionality common to the *namespace* (shared between the controllers in the namespace), using this technique.
694
704
 
695
- ## Field Types Supported
705
+ ## Special Table Labels
706
+
707
+ If your object is very wordy (like MyGreatHook) and you want it to display in the UI as something shorter,
708
+ add `@@table_label_plural = "The Things"` and `@@table_label_singular = "The Things"`.
709
+
710
+ Hot Glue will use this as the listing heading label and New record label. This affects only the UI only.
711
+
712
+ You can also set these to `nil` to omit the labels completely.
713
+
714
+ Child portals have the headings omitted automatically (there is a heading identifying them already on the parent view where they get included), or you can use the `--no-list-heading` on any specific build.
696
715
 
697
- - Integers that don't end with `_id`, they will be displayed as text fields.
698
- - Integers that do end with `_id` will be treated automatically as associations. You should have a Rails association defined. (Hot Glue will warn you if it can't find one.)
699
- - String*
700
- - Text*
701
- - Float*
702
- - Datetime
703
- - Date
704
- - Time
705
- - Boolean
706
- - Enum - will display as a value list populated from the enum list defined on your model. see https://jasonfleetwoodboldt.com/courses/stepping-up-rails/enumerated-types-in-rails-and-postgres/
707
716
 
708
- * shows in a size-aware container, i.e. in a bigger box if the field allows for more content
717
+ ## Field Types Supported
709
718
 
719
+ - Integers that don't end with `_id`: displayed as input fields with type="number"
720
+ - Foreign keys: Integers that do end with `_id` will be treated automatically as associations. You should have a Rails association defined. (Hot Glue will warn you if it can't find one.)
721
+ - Note: if your foreign key has a nonusual class name, it should be using the `class_name:` in the model definition
722
+ - String: displayed as small input box
723
+ - Text: displayed as large textarea
724
+ - Float: displayed as input box
725
+ - Datetime: displayed as HTML5 datetime picker
726
+ - Date: displayed as HTML5 date picker
727
+ - Time: displayed as HTML5 time picker
728
+ - Boolean: displayed radio buttons yes/ no
729
+ - Enum - displayed as a drop-down list (defined the enum values on your model). For Rails 6 see https://jasonfleetwoodboldt.com/courses/stepping-up-rails/enumerated-types-in-rails-and-postgres/
710
730
 
711
731
 
712
732
  # VERSION HISTORY
713
733
 
714
- #### 2022-01-01 - v0.4.3 and 0.4.4 - adding fully email based license; no activation codes required
734
+ #### 2022-02-14 - v0.4.9
735
+ • Fixed issue building models with namespaced class names (e.g. `Fruits::Apple` and `Fruits::Bannana`).
736
+ You can now build against these kinds of models natively (be sure to pass the full model name, with double-colon syntax).
737
+
738
+ • Also fixes issues when associations themselves were namespaced models.
739
+
740
+ • The N+1 Killer (!!!)
741
+ - N+1 queries for _any association_ built by the list are now automagically killed by the list controllers.
742
+ - Thanks to the work done back in Rails 5.2, Rails smartly uses either two queries to glob up the data OR one query with a LEFT OUTER JOIN if that's faster. You don't have to think about it. **Thanks Rails 5.2!**
743
+ - Hot Glue now adds `.includes(...)` if it is including an association when it loads the list view to eliminate the N+1s
744
+ - Bullet is still the best way to identify, find, & fix your N+1 queries is still highly recommended. https://github.com/flyerhzm/bullet
745
+
746
+ • Downnest children (portals) can now be created with more space (made wider) by adding one or more `+` to the end of the downnest name, denoting add 1 bootstrap column.
747
+ - e.g. `--downnest=abc+,xyz`
748
+
749
+ The "Abc" portal will take up 5 bootstrap columns and the Xyz portal will take up 4 columns. (++ to indicate 6, `+++` for 7, etc)
750
+
751
+ • Now that you can expand the downnest child portal width, you can easily give them too much width taking up more than 12 bootstrap columns.
752
+ The builder stops you from building if you have taken up too many bootstrap columns, are in _either_ **Smart Layout mode** or **Specified Grouping mode**.
753
+ However, this check is not in place if you are in neither mode, in which case you should watch out for building more than 12 bootstrap columns.
754
+
755
+ • To give a special label to a model, add `@@table_label_plural = "The Things"` and `@@table_label_singular = "The Thing"`.
756
+ This model will now have a list heading of "The Things" instead of its usual name.
757
+ For 'create buttons' and the 'New' screen, the builder will use the singular setting.
758
+ This affects all builds against that model and affects the UI (display) only.
759
+ All route names, table names, and variables are unaffected by this.
760
+
761
+ • You can also use `@@table_label_plural = nil` to set these tables to **omit** the label headings, or use the new flag...
762
+
763
+ • `--no-list-heading` (defaults to false but note several conditions when list headings are now hidden)
764
+
765
+ Omits the list heading. Note that the listing heading is omitted:
766
+ 1) if there is no list,
767
+ 2) if you set the `--no-list-heading` flag,
768
+ 3) if the model has `@@table_label_plural = nil`, or
769
+ 4) if you are constructing a nested child portal with only non-optionalized parents.
770
+
771
+
772
+
773
+ #### 2022-02-09 - v0.4.8.1 - Issue with Installer for v0.4.8
774
+ - There was an issue for the installer for v0.4.8. This new version v0.4.8.1 correts it.
775
+
776
+
777
+ #### 2022-02-07 - v0.4.8 Optionalized Nested Parents
778
+ - optionalized nested parents. to use add `~` in front of any nested parameter you want to make optional
779
+
780
+
781
+ #### 2022-01-26 - v0.4.7 `--nest` has been renamed to `--nested`; please use `--nested` moving forward
782
+ - `--alt-controller-name` feature from the last release has been removed, I have something better coming soon
783
+ - significant improvements to how child portals are handled, including setting the owner (parent) object when creating new records from a child portal
784
+ - improvements to how 'self-auth' is handled, i.e., when a controller is built using an authentication identifier (e.g. `current_user`) that is the same as the controller's object
785
+ - note that when building a self-auth controller, the list view still behaves as-if it is a list but controller only has access to the auth object (e.g. `current_user`). You would really only need this for the edge case of a user updating their own record, or, as in the example, to use as the starting point for building the child portals.
786
+ - another edge case in here that has been fixed involved creating a 'no field' form-- in the example, invoices are created using the "new" button and "save" button, even though the form has no editable fields for the user to input. In these edge cases, an invisible form field is inserted to make the form submission work correctly. This only happens for an action that has no inputable fields.
787
+ - cleaner code for the `_form` output and also the `controller` output
788
+
789
+ #### 2022-01-23 - v0.4.6 - `--no-list-labels` (flag; defaults false)
790
+ (additional features in this release have been subsequently removed)
791
+
792
+ #### 2022-01-11 - v0.4.5 - buttons on smart layouts take up 1 bootstrap column each; fixes confirmation alert for delete buttons
793
+
794
+ #### 2022-01-01 - v0.4.3 and 0.4.4 - adding fully email-based license, no activation codes required.
715
795
 
716
796
  #### 2022-12-30 - v0.4.2 -- Smart layouts introduced
717
797
 
@@ -724,7 +804,7 @@ Obviously, the created controller will always have this base controller as its s
724
804
  #### 2021-12-11 - v0.3.5 - Downnesting
725
805
 
726
806
 
727
- #### 2021-11-27 - v0.2.9E — EXPERIMENTAL
807
+ #### 2021-11-27 - v0.2.9E (experimental)
728
808
  - Downnesting
729
809
  - Adds spec coverage support for enums
730
810
  - Several more fixes; this is preparation for forthcoming release.
@@ -732,7 +812,6 @@ Obviously, the created controller will always have this base controller as its s
732
812
 
733
813
  #### 2021-10-11 - v0.2.6 - many additional automatic fixes for default Rails installation 6 or 7 for the generate hot_glue:install command
734
814
 
735
-
736
815
  #### 2021-10-10 - v0.2.5 - this version is all about developer happyness:
737
816
  - significant fixes for the behavioral (system) specs. they now create new & update interactions
738
817
  for (almost) all field types
@@ -746,9 +825,9 @@ Obviously, the created controller will always have this base controller as its s
746
825
 
747
826
  #### 2021-09-30 - v0.2.3 - fixes ERB output for show-only fields; fixes flash_notices for erb or haml; adds @stimulus_syntax flag for delete confirmations with stimulus
748
827
 
749
- #### 2021-09-27 - v0.2.2 - Fixes some issues with related fields; unlocks Rails 7 in Gemspec file
828
+ #### 2021-09-27 - v0.2.2 - Fixes some issues with related fields; unlocks Rails 7 in Gemspec file
750
829
 
751
- #### 2021-09-20 - v0.2.1 - Fixes nesting behavior when using gd option
830
+ #### 2021-09-20 - v0.2.1 - Fixes nesting behavior when using gd option
752
831
 
753
832
  #### 2021-09-06 - v0.2.0 - ERB or HAML; use the option --markup=erb or --markup=haml (default is now erb)
754
833
 
@@ -776,9 +855,6 @@ Obviously, the created controller will always have this base controller as its s
776
855
 
777
856
 
778
857
 
779
-
780
-
781
-
782
858
  # HOW THIS GEM IS TESTED
783
859
 
784
860
  SETUP:
@@ -796,16 +872,29 @@ The DUMMY testing DOES NOT test the actual functionality of the output code (it
796
872
 
797
873
 
798
874
  # DATABASE
875
+ being able to run `rake spec` at the root of this repo is achieved using
876
+ ```
877
+ ln -s spec/dummy/db/schema.rb db/schema.rb
878
+ ```
879
+
880
+
881
+
882
+ Run rspec as
883
+ ```
884
+ rake spec
885
+ ```
886
+ Or with test coverage report:
887
+
888
+ ```
889
+ COVERGE=on rake spec
799
890
 
800
- `cd spec/dummy`
801
- `rails db:drop`
802
- `rails db:create`
803
- `rails db:migrate`
804
- `RAILS_ENV=test rails db:migrate`
891
+ ```
805
892
 
806
- `cd ../..`
893
+ --
894
+ --
895
+
896
+ Test coverage as of 2022-02-14 (v0.4.9)
807
897
 
808
- take note that when running the spec at the root of the repo you are initializing the Dummy app, which will use the
809
- SQLite database in spec/dummy/database/
898
+ ![Screen Shot 2022-02-14 at 8 33 29 PM](https://user-images.githubusercontent.com/59002/153975911-30fa9c84-c8d8-49e7-bd5c-e2b958d6f10e.png)
810
899
 
811
900