hot-glue 0.2.9E → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -2
- data/Gemfile.lock +3 -3
- data/LICENCE +11 -4
- data/README.md +0 -698
- data/app/helpers/hot_glue/controller_helper.rb +2 -1
- data/lib/generators/hot_glue/install_generator.rb +121 -33
- data/lib/generators/hot_glue/markup_templates/erb.rb +41 -28
- data/lib/generators/hot_glue/markup_templates/haml.rb +3 -1
- data/lib/generators/hot_glue/scaffold_generator.rb +159 -35
- data/lib/generators/hot_glue/templates/controller.rb.erb +34 -20
- data/lib/generators/hot_glue/templates/erb/_form.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/_line.erb +3 -2
- data/lib/generators/hot_glue/templates/erb/_list.erb +29 -14
- data/lib/generators/hot_glue/templates/erb/_new_button.erb +3 -1
- data/lib/generators/hot_glue/templates/erb/_show.erb +17 -9
- data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +2 -2
- data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +2 -2
- data/lib/generators/hot_glue/templates/erb/edit.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/index.erb +11 -8
- data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +1 -1
- data/lib/generators/hot_glue/templates/haml/_list.haml +2 -2
- data/lib/generators/hot_glue/templates/haml/index.haml +1 -1
- data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_dark_knight.scss +158 -0
- data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_bootstrap.scss +154 -0
- data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_los_gatos.scss +182 -0
- data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_mountain_view.scss +179 -0
- data/lib/hotglue/version.rb +1 -1
- metadata +14 -20
data/README.md
CHANGED
@@ -1,698 +0,0 @@
|
|
1
|
-
|
2
|
-
[![Build Status](https://app.travis-ci.com/jasonfb/hot-glue.svg?branch=main)](https://travis-ci.com/jasonfb/hot-glue)
|
3
|
-
|
4
|
-
|
5
|
-
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
|
-
|
7
|
-
|
8
|
-
Using Turbo-Rails and Hotwire (default in Rails 7) you get a lightning-fast out-of-the-box CRUD building experience.
|
9
|
-
|
10
|
-
Every page displays only a list view: new and edit operations happen as 'edit-in-place', so the user never leaves the page.
|
11
|
-
|
12
|
-
Because all page navigation is Turbo's responsibilty, everything plugs & plays nicely into a Turbo-backed Rails app.
|
13
|
-
|
14
|
-
Alternatively, you can use this tool to create a Turbo-backed *section* of your Rails app-- like an admin interface -- while still treating the rest of the Rails app as an API or building out other features by hand.
|
15
|
-
|
16
|
-
It will read your relationships and field types to generate your code for you, leaving you with a 'sourdough starter' to work from. If you modify the generated code, you're on your own if you want to preserve your changes and also re-generate scaffold after adding fields.
|
17
|
-
|
18
|
-
By default, it generates code that gives users full control over objects they 'own' and by default it spits out functionality giving access to all fields.
|
19
|
-
|
20
|
-
Hot Glue generates functionality that's quick and dirty. It let's you be crafty. As with a real hot glue gun, use with caution.
|
21
|
-
|
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!)
|
25
|
-
* Excellent for CREATE-READ-UPDATE-DELETE (CRUD), lists with pagination (coming soon: searching & sorting)
|
26
|
-
* Great for prototyping, but you should learn Rails fundamentals first.
|
27
|
-
* 'Packaged' with Devise, Kaminari, Rspec, FontAwesome
|
28
|
-
* Create system specs automatically along with the generated code.
|
29
|
-
* Nest your routes model-by-model for built-in poor man's authentication.
|
30
|
-
* Throw the scaffolding away when your app is ready to graduate to its next phase.
|
31
|
-
|
32
|
-
## QUICK START
|
33
|
-
|
34
|
-
If you like tutorials, try https://jasonfleetwoodboldt.com/hot-glue
|
35
|
-
|
36
|
-
## HOW EASY?
|
37
|
-
|
38
|
-
```
|
39
|
-
rails generate hot_glue:scaffold Thing
|
40
|
-
```
|
41
|
-
|
42
|
-
Generate a quick scaffold to manage a table called `pronouns`
|
43
|
-
![hot-glue-3](https://user-images.githubusercontent.com/59002/116405509-bdee2f00-a7fd-11eb-9723-4c6e22f81bd3.gif)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
Instantly get a simple CRUD interface
|
48
|
-
|
49
|
-
![hot-glue-4](https://user-images.githubusercontent.com/59002/116405517-c2b2e300-a7fd-11eb-8423-d43e3afc9fa6.gif)
|
50
|
-
|
51
|
-
# Getting Started
|
52
|
-
|
53
|
-
## 1. ADD HOTWIRE
|
54
|
-
(RAILS 6 ONLY— SKIP THIS STEP FOR RAILS 7)
|
55
|
-
```
|
56
|
-
yarn add @hotwired/turbo-rails
|
57
|
-
```
|
58
|
-
or `npm install @hotwired/turbo-rails`
|
59
|
-
|
60
|
-
|
61
|
-
## 2. SWITCH FROM TurblLinks to Turbo-Rails
|
62
|
-
(RAILS 6 ONLY— SKIP THIS STEP FOR RAILS 7)
|
63
|
-
(THIS WAS AUTOMATICALLY DONE BY THE HOT GLUE INSTALLATION -- CONFIRM CHANGES ONLY)
|
64
|
-
- Add `gem 'turbo-rails'` to your Gemfile & `bundle install`
|
65
|
-
- Then install it with `rails turbo:install`
|
66
|
-
- The Turbo install has switched your action cable settings from 'async' to Redis, so be sure to start a redis server
|
67
|
-
- in `app/javascript/packs/application.js` remove this line
|
68
|
-
```
|
69
|
-
import Turbolinks from "turbolinks"
|
70
|
-
```
|
71
|
-
and replace it with
|
72
|
-
```
|
73
|
-
import { Turbo } from "@hotwired/turbo-rails"
|
74
|
-
```
|
75
|
-
|
76
|
-
|
77
|
-
Also replace
|
78
|
-
```
|
79
|
-
Turbolinks.start()
|
80
|
-
```
|
81
|
-
with:
|
82
|
-
```
|
83
|
-
Turbo.start()
|
84
|
-
```
|
85
|
-
|
86
|
-
|
87
|
-
## 3. ADD HOT-GLUE GEM
|
88
|
-
- Add `gem 'hot-glue', '~> 0.2.6'` to your Gemfile & `bundle install`
|
89
|
-
|
90
|
-
(TODO: figure out why bundler seems to install the yanked version 0.0.0 if you don't specify the hot glue version)
|
91
|
-
|
92
|
-
## 4. ADD RSPEC, FACTORY-BOT, AND FFAKER
|
93
|
-
|
94
|
-
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.
|
95
|
-
```
|
96
|
-
gem 'rspec-rails'
|
97
|
-
gem 'factory_bot_rails'
|
98
|
-
gem 'ffaker'
|
99
|
-
```
|
100
|
-
|
101
|
-
- run `rails generate rspec:install`
|
102
|
-
|
103
|
-
## 5(A). RUN HOT-GLUE INSTALL
|
104
|
-
### FOR ERB:
|
105
|
-
`rails generate hot_glue:install --markup=erb`
|
106
|
-
|
107
|
-
### FOR HAML:
|
108
|
-
`rails generate hot_glue:install --markup=haml`
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
## 5(B). Modify `application.html.erb`
|
115
|
-
(THIS WAS AUTOMATICALLY DONE BY THE HOT GLUE INSTALLATION -- CONFIRM CHANGES ONLY)
|
116
|
-
Note: if you have some kind of non-standard application layout, like one at a different file
|
117
|
-
or if you have modified your opening <body> tag, this may not have been automatically applied by the installer.
|
118
|
-
|
119
|
-
- This was added to your `application.html.erb`
|
120
|
-
```
|
121
|
-
<%= render partial: 'layouts/flash_notices' %>
|
122
|
-
```
|
123
|
-
|
124
|
-
## 5(C). Modify `rails_helper.rb`
|
125
|
-
(THIS WAS AUTOMATICALLY DONE BY THE HOT GLUE INSTALLATION)
|
126
|
-
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`
|
127
|
-
this may not have been automatically applied by the installer.
|
128
|
-
|
129
|
-
- configure Rspec to work with Factory Bot inside of `rails_helper.rb`
|
130
|
-
```
|
131
|
-
RSpec.configure do |config|
|
132
|
-
// ... more rspec configuration (not shown)
|
133
|
-
config.include FactoryBot::Syntax::Methods
|
134
|
-
end
|
135
|
-
```
|
136
|
-
|
137
|
-
|
138
|
-
## 5(D) CAPYBARA: SWITCH FROM RACK-TEST TO HEADLESS CHROME
|
139
|
-
(THIS WAS AUTOMATICALLY DONE BY THE HOT GLUE INSTALLATION)
|
140
|
-
|
141
|
-
- By default Capybara is installed with :rack_test as its driver.
|
142
|
-
- This does not support Javascript, and the code from Hot Glue IS NOT fallback compatible-- it will not work on non-Javascript browsers.
|
143
|
-
- From the [Capybara docs](https://github.com/teamcapybara/capybara#drivers):
|
144
|
-
```
|
145
|
-
By default, Capybara uses the :rack_test driver, which is fast but limited: it does not support JavaScript
|
146
|
-
```
|
147
|
-
|
148
|
-
- To fix this, you must switch to a Javascript-supporting Capybara driver. You can choose one of:
|
149
|
-
|
150
|
-
`Capybara.default_driver = :selenium`
|
151
|
-
`Capybara.default_driver = :selenium_chrome`
|
152
|
-
`Capybara.default_driver = :selenium_chrome_headless`
|
153
|
-
|
154
|
-
By default, the installer should have added this option to your `rails_helper.rb` file:
|
155
|
-
|
156
|
-
```
|
157
|
-
Capybara.default_driver = :selenium_chrome_headless
|
158
|
-
```
|
159
|
-
|
160
|
-
Alternatively, can define your own driver like so:
|
161
|
-
|
162
|
-
```
|
163
|
-
Capybara.register_driver :my_headless_chrome_desktop do |app|
|
164
|
-
options = Selenium::WebDriver::Chrome::Options.new
|
165
|
-
options.add_argument('--headless')
|
166
|
-
options.add_argument('--disable-gpu')
|
167
|
-
options.add_argument('--window-size=1280,1200')
|
168
|
-
|
169
|
-
driver = Capybara::Selenium::Driver.new(app,
|
170
|
-
browser: :chrome,
|
171
|
-
options: options)
|
172
|
-
|
173
|
-
driver
|
174
|
-
end
|
175
|
-
Capybara.default_driver = :my_headless_chrome_desktop
|
176
|
-
|
177
|
-
```
|
178
|
-
|
179
|
-
|
180
|
-
### 6(A) Bootstrap with Webpack:
|
181
|
-
DO EIETHER 6(A) OR 6(B)
|
182
|
-
- add to Gemfile
|
183
|
-
- `gem 'bootstrap', '~> 5.1.3'`
|
184
|
-
- completely delete the file `app/assets/application.css`
|
185
|
-
- create new file where it was `app/assets/application.scss` with this contents (do not keep the contents of the old application.css file):
|
186
|
-
```
|
187
|
-
// Custom bootstrap variables must be set or imported *before* bootstrap.
|
188
|
-
@import "bootstrap";
|
189
|
-
```
|
190
|
-
|
191
|
-
* You do not need jQuery for HotGlue to work *
|
192
|
-
|
193
|
-
### Hook your Bootstrap into your global application scss
|
194
|
-
- change `stylesheet_link_tag` to `stylesheet_pack_tag` in your application layout
|
195
|
-
- run `yarn add bootstrap`
|
196
|
-
- create a new file at `app/javascript/require_bootstrap.scss` with this content
|
197
|
-
```
|
198
|
-
@import "~bootstrap/scss/bootstrap.scss";
|
199
|
-
```
|
200
|
-
|
201
|
-
- add to `app/javascript/packs/application.js`
|
202
|
-
```
|
203
|
-
import 'require_bootstrap'
|
204
|
-
```
|
205
|
-
|
206
|
-
|
207
|
-
## 6(B) Install Bootstrap using Sprockets
|
208
|
-
(IMPORTANT: YOU DO NOT NEED JQUERY)
|
209
|
-
DO EIETHER 6(A) OR 6(B)
|
210
|
-
|
211
|
-
Bootstrap with Sprockets for Rails 5 or 7 default — Rails 6 custom
|
212
|
-
- add `gem 'bootstrap-rubygem'` to your gemfile
|
213
|
-
- replace `application.css` with a new file (delete old contents) `application.scss`
|
214
|
-
```
|
215
|
-
@import "bootstrap";
|
216
|
-
```
|
217
|
-
- see README at github.com/twbs/bootstrap-rubygem to install
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
## 7. install font-awesome
|
223
|
-
|
224
|
-
I recommend https://github.com/tomkra/font_awesome5_rails
|
225
|
-
or https://github.com/FortAwesome/font-awesome-sass
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
## 8. For Enum support, I recommend activerecord-pg_enum
|
230
|
-
|
231
|
-
Instructions for Rails are here:
|
232
|
-
https://jasonfleetwoodboldt.com/courses/stepping-up-rails/enumerated-types-in-rails-and-postgres/
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
## 9. Devise
|
237
|
-
(or only use --gd mode, see below)
|
238
|
-
|
239
|
-
Add to your Gemfile `gem 'devise'`
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
```
|
244
|
-
rails generate devise:install
|
245
|
-
```
|
246
|
-
|
247
|
-
IMPORTANT: Follow the instructions the Devise installer gives you, *Except Step 3*, you can skip this step:
|
248
|
-
```
|
249
|
-
3. Ensure you have flash messages in app/views/layouts/application.html.erb.
|
250
|
-
For example:
|
251
|
-
|
252
|
-
<p class="notice"><%= notice %></p>
|
253
|
-
<p class="alert"><%= alert %></p>
|
254
|
-
|
255
|
-
```
|
256
|
-
|
257
|
-
|
258
|
-
You can also skip Devise installer Step 4, which is optional:
|
259
|
-
```
|
260
|
-
4. You can copy Devise views (for customization) to your app by running:
|
261
|
-
|
262
|
-
rails g devise:views
|
263
|
-
|
264
|
-
* Not required *
|
265
|
-
```
|
266
|
-
|
267
|
-
|
268
|
-
## 9(B) Devise & Capybara - Add User Authentication if you are using Access Control
|
269
|
-
(THIS WAS AUTOMATICALLY DONE BY THE HOT GLUE INSTALLATION)
|
270
|
-
|
271
|
-
- for a quick Capybara login, create a support helper in `spec/support/` and log-in as your user
|
272
|
-
- in the default code, the devise login would be for an object called account and lives at the route `/accounts/sign_in`
|
273
|
-
- modify the generated code (it was installed by the installed) for your devise login
|
274
|
-
```
|
275
|
-
def login_as(account)
|
276
|
-
visit '/accounts/sign_in'
|
277
|
-
within("#new_account") do
|
278
|
-
fill_in 'Email', with: account.email
|
279
|
-
fill_in 'Password', with: 'password'
|
280
|
-
end
|
281
|
-
click_button 'Log in'
|
282
|
-
end
|
283
|
-
```
|
284
|
-
|
285
|
-
|
286
|
-
## RAILS 7: Devise is not yet supported on Rails 7 unless you use the master branch of devise
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
# HOT GLUE DOCS
|
291
|
-
|
292
|
-
|
293
|
-
## First Argument
|
294
|
-
(no double slash)
|
295
|
-
|
296
|
-
TitleCase class name of the thing you want to build a scaffoling for.
|
297
|
-
|
298
|
-
|
299
|
-
## Options With Arguments
|
300
|
-
|
301
|
-
All options two dashes (--) and these take an `=` and a value
|
302
|
-
|
303
|
-
### `--namespace=`
|
304
|
-
|
305
|
-
pass `--namespace=` as an option to denote a namespace to apply to the Rails path helpers
|
306
|
-
|
307
|
-
|
308
|
-
`rails generate hot_glue:scaffold Thing --namespace=dashboard`
|
309
|
-
|
310
|
-
This produces several views at `app/views/dashboard/things/` and a controller at`app/controllers/dashboard/things_controller.rb`
|
311
|
-
|
312
|
-
The controller looks like so:
|
313
|
-
|
314
|
-
```
|
315
|
-
class Dashboard::ThingsController < ApplicationController
|
316
|
-
before_action :authenticate_user!
|
317
|
-
before_action :load_thing, only: [:show, :edit, :update, :destroy]
|
318
|
-
def load_thing
|
319
|
-
@thing = current_user.things.find(params[:id])
|
320
|
-
end
|
321
|
-
...
|
322
|
-
end
|
323
|
-
|
324
|
-
```
|
325
|
-
|
326
|
-
|
327
|
-
### `--nest=`
|
328
|
-
|
329
|
-
pass `--nest=` to denote a nested resources
|
330
|
-
|
331
|
-
|
332
|
-
`rails generate hot_glue:scaffold Line --nest=invoice`
|
333
|
-
|
334
|
-
In this example, it is presumed that the current user has_many :invoices, and that invoices have many :lines
|
335
|
-
|
336
|
-
|
337
|
-
For multi-level nesting use slashes to separate your levels of nesting. Remember, you should match what you have in your routes.rb file.
|
338
|
-
|
339
|
-
```
|
340
|
-
resources :invoices do
|
341
|
-
resources :lines do
|
342
|
-
resources :charge
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
```
|
347
|
-
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
|
348
|
-
|
349
|
-
|
350
|
-
To generate scaffold:
|
351
|
-
`rails generate hot_glue:scaffold Charge --nest=invoice/line`
|
352
|
-
|
353
|
-
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:
|
354
|
-
|
355
|
-
In the example above, @invoice will be loaded from
|
356
|
-
|
357
|
-
`@invoice = current_user.invoices.find(params[:invoice_id])`
|
358
|
-
|
359
|
-
Then, @line will be loaded
|
360
|
-
|
361
|
-
`@line = @invoice.lines.find(params[:line_id])`
|
362
|
-
|
363
|
-
Then, finally the @charge will be loaded
|
364
|
-
|
365
|
-
`@charge = @line.charges.find(params[:id])`
|
366
|
-
|
367
|
-
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).
|
368
|
-
|
369
|
-
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).
|
370
|
-
|
371
|
-
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.
|
372
|
-
|
373
|
-
|
374
|
-
### `--auth=`
|
375
|
-
|
376
|
-
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.
|
377
|
-
|
378
|
-
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.
|
379
|
-
|
380
|
-
Of course this is a sloppy way to do access control, and can easily leave open endpoints your real users shouldn't have access to.
|
381
|
-
|
382
|
-
When you display anything built with the scaffolding, we assume the `current_user` will have `has_many` association that matches the pluralized name of the scaffold. In the case of nesting, we will automatically find the nested objects first, then continue down the nest chain to find the target object. In this way, we know that all object are 'anchored' to the logged-in user.
|
383
|
-
|
384
|
-
If you use Devise, you probably already have a `current_user` method available in your controllers. If you don't use Devise, you can implement it in your ApplicationController.
|
385
|
-
|
386
|
-
If you use a different object other than "User" for authentication, override using the `auth` option.
|
387
|
-
|
388
|
-
`rails generate hot_glue:scaffold Thing --auth=current_account`
|
389
|
-
|
390
|
-
You will note that in this example it is presumed that the Account object will have an association for `things`
|
391
|
-
|
392
|
-
It is also presumed that when viewing their own dashboard of things, the user will want to see ALL of their associated things.
|
393
|
-
|
394
|
-
If you supply nesting (see below), your nest chain will automatically begin with your auth root object (see nesting)
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
### `--auth_identifier=`
|
400
|
-
|
401
|
-
Your controller will call a method authenticate_ (AUTH IDENTIFIER) bang, like:
|
402
|
-
|
403
|
-
`authenticate_user!`
|
404
|
-
|
405
|
-
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.
|
406
|
-
(This is setup for devise.)
|
407
|
-
|
408
|
-
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.
|
409
|
-
|
410
|
-
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.
|
411
|
-
|
412
|
-
```
|
413
|
-
def authenticate_user!
|
414
|
-
if ! user_signed_in?
|
415
|
-
session['user_return_to'] = request.path
|
416
|
-
redirect_to new_user_registration_path
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
def after_sign_in_path_for(user)
|
421
|
-
session['user_return_to'] || account_url(user)
|
422
|
-
end
|
423
|
-
```
|
424
|
-
|
425
|
-
|
426
|
-
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')
|
427
|
-
|
428
|
-
|
429
|
-
`rails generate hot_glue:scaffold Thing --auth=current_account --auth_identifier=login`
|
430
|
-
In this example, the controller produced with:
|
431
|
-
```
|
432
|
-
before_action :authenticate_login!
|
433
|
-
```
|
434
|
-
However, the object graph anchors would continue to start from current_account. That is,
|
435
|
-
```
|
436
|
-
@thing = current_account.things.find(params[:id])
|
437
|
-
```
|
438
|
-
|
439
|
-
Use empty string to **turn this method off**:
|
440
|
-
`rails generate hot_glue:scaffold Thing --auth=current_account --auth_identifier=''`
|
441
|
-
|
442
|
-
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.
|
443
|
-
|
444
|
-
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.
|
445
|
-
|
446
|
-
|
447
|
-
### `--plural=`
|
448
|
-
|
449
|
-
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 which is non-standard for Rails)
|
450
|
-
|
451
|
-
|
452
|
-
### `--exclude=`
|
453
|
-
(separate field names by COMMA)
|
454
|
-
|
455
|
-
By default, all fields are included unless they are on the exclude list. (The default for the exclude list is `id`, `created_at`, and `updated_at` so you don't need to exclude those-- they are added.)
|
456
|
-
|
457
|
-
If you specify an exclude list, those and the default excluded list will be excluded.
|
458
|
-
|
459
|
-
|
460
|
-
`rails generate hot_glue:scaffold Account --exclude=password`
|
461
|
-
|
462
|
-
(The default excluded list is: :id, :created_at, :updated_at, :encrypted_password, :reset_password_token, :reset_password_sent_at, :remember_created_at, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email. If you want to edit any fields with the same name, you must use the include flag instead.)
|
463
|
-
|
464
|
-
|
465
|
-
### `--include=`
|
466
|
-
(separate field names by COMMA)
|
467
|
-
|
468
|
-
You may not specify both include and exclude. If you specify an include list, it will be treated as a whitelist: no fields will be included unless specified on the include list.
|
469
|
-
|
470
|
-
`rails generate hot_glue:scaffold Account --include=first_name,last_name,company_name,created_at,kyc_verified_at`
|
471
|
-
|
472
|
-
|
473
|
-
### `--show-only=`
|
474
|
-
(separate field names by COMMA)
|
475
|
-
|
476
|
-
Any fields only the 'show-only' list will appear as non-editable on the generate form. (visible only)
|
477
|
-
|
478
|
-
IMPORTANT: By default, all fields that begin with an underscore (`_`) are automatically show-only.
|
479
|
-
|
480
|
-
I would recommend this for fields you want globally non-editable by users in your app. For example, a counter cache or other field set only by a backend mechanism.
|
481
|
-
|
482
|
-
### `--stimulus_syntax=true` or `--stimulus_syntax=false`
|
483
|
-
(for Rails <=6, default is false. For Rails 7, default is true.)
|
484
|
-
|
485
|
-
Stimulus is only used for the delete button's confirmation dialog.
|
486
|
-
|
487
|
-
If you don't have stimulus syntax enabled, your delete buttons have this. This will confirm the delete with a simple alert if you have UJS enabled.
|
488
|
-
|
489
|
-
```
|
490
|
-
{confirm: 'Are you sure?'}
|
491
|
-
```
|
492
|
-
|
493
|
-
If you do have Stimulus syntax enabled, your delete buttons will look like so:
|
494
|
-
```
|
495
|
-
<%= button_to "Delete <i class='fa fa-1x fa-remove'></i>".html_safe,
|
496
|
-
thing_path(branch), method: :delete,
|
497
|
-
data: {
|
498
|
-
'controller: 'confirmable',
|
499
|
-
'confirm-message': 'Are you sure you want to delete Thing?',
|
500
|
-
'action': 'confirmation#confirm'
|
501
|
-
},
|
502
|
-
disable_with: "Loading...", class: "delete-branch-button btn btn-primary " %>
|
503
|
-
```
|
504
|
-
|
505
|
-
Your install script will output an additional stimulus controller:
|
506
|
-
|
507
|
-
```
|
508
|
-
|
509
|
-
```
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
### `--markup` (default: 'erb')
|
514
|
-
|
515
|
-
ERB is default. For HAML, `--markup=haml`.
|
516
|
-
|
517
|
-
|
518
|
-
## FLAGS (Options with no values)
|
519
|
-
These options (flags) also uses `--` syntax but do not take any values. Everything is assumed (default) to be false unless specified.
|
520
|
-
|
521
|
-
### `--god` or `--gd`
|
522
|
-
|
523
|
-
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 controller.
|
524
|
-
|
525
|
-
For example, FOR ADMIN CONTROLLERS ONLY, supply a auth_identifier and use `--god` flag.
|
526
|
-
|
527
|
-
In Gd mode, the objects are loaded directly from the base class (these controllers have full access)
|
528
|
-
```
|
529
|
-
def load_thing
|
530
|
-
@thing = Thing.find(params[:id])
|
531
|
-
end
|
532
|
-
|
533
|
-
```
|
534
|
-
|
535
|
-
|
536
|
-
### `--specs-only`
|
537
|
-
|
538
|
-
Produces ONLY the controller spec file, nothing else.
|
539
|
-
|
540
|
-
|
541
|
-
### `--no-specs`
|
542
|
-
|
543
|
-
Produces all the files except the spec file.
|
544
|
-
|
545
|
-
|
546
|
-
### `--no-paginate`
|
547
|
-
|
548
|
-
Omits pagination. (All list views have pagination by default.)
|
549
|
-
|
550
|
-
|
551
|
-
### `--no-create`
|
552
|
-
|
553
|
-
Omits create action.
|
554
|
-
|
555
|
-
### `--no-delete`
|
556
|
-
|
557
|
-
Omits delete action.
|
558
|
-
|
559
|
-
### `--big-edit`
|
560
|
-
|
561
|
-
If you do not want inline editing of your list items but instead to fall back to full page style behavior for your edit views, use `--big-edit`. Turbo still handles the page interactions, but the user is taken to a full-screen edit page instead of an edit-in-place interaction.
|
562
|
-
|
563
|
-
### `--display-list-after-update` (default: false)
|
564
|
-
|
565
|
-
After an update-in-place normally only the edit view is swapped out for the show view of the record you just edited.
|
566
|
-
|
567
|
-
Sometimes you might want to redisplay the entire list after you make an update (for example, if your action removes that record from the result set).
|
568
|
-
|
569
|
-
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.
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
### `--downnest`
|
574
|
-
(2021-11-23 - WIP)
|
575
|
-
|
576
|
-
Automatically create subviews down your object tree. This should be the name of a has_many relationship based from the current object.
|
577
|
-
You will need to build scaffolding with the same name for the related object as well.
|
578
|
-
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.
|
579
|
-
|
580
|
-
### `--nestable` (default: false)
|
581
|
-
(2021-11-23 - WIP)
|
582
|
-
When creating a controller that you will use a another controllers downnest (that is, you will display related records-- like a portal-- from the parent within each row of the parent's list view), set nestable to true.
|
583
|
-
|
584
|
-
If the cooresponding Rails route contains nesting and this controller is downnested by someone else, you'll want to set nestable to true.
|
585
|
-
|
586
|
-
If the cooresponding Rails route is not nested and the controller sits a the root of the namespace, set nestable to false.
|
587
|
-
|
588
|
-
|
589
|
-
## Automatic Base Controller
|
590
|
-
|
591
|
-
HotGlue will copy a file named base_controller.rb to the same folder where it tries to create any controller, unless such a file exists there already.
|
592
|
-
|
593
|
-
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.
|
594
|
-
|
595
|
-
## Field Types Supported
|
596
|
-
|
597
|
-
- Integers that don't end with `_id`, they will be displayed as text fields.
|
598
|
-
- 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.)
|
599
|
-
- String*
|
600
|
-
- Text*
|
601
|
-
- Float*
|
602
|
-
- Datetime
|
603
|
-
- Date
|
604
|
-
- Time
|
605
|
-
- Boolean
|
606
|
-
- 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/
|
607
|
-
|
608
|
-
* shows in a size-aware container, i.e. in a bigger box if the field allows for more content
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
# VERSION HISTORY
|
613
|
-
|
614
|
-
#### 2021-11-27 - v0.2.9E — EXPERIMENTAL
|
615
|
-
- Downnesting
|
616
|
-
- Adds spec coverage support for enums
|
617
|
-
- Several more fixes; this is preparation for forthcoming release.
|
618
|
-
- Some parts still experimental. Use with caution.
|
619
|
-
|
620
|
-
#### 2021-10-11 - v0.2.6 - many additional automatic fixes for default Rails installation 6 or 7 for the generate hot_glue:install command
|
621
|
-
|
622
|
-
|
623
|
-
#### 2021-10-10 - v0.2.5 - this version is all about developer happyness:
|
624
|
-
- significant fixes for the behavioral (system) specs. they now create new & update interactions
|
625
|
-
for (almost) all field types
|
626
|
-
- the install generator now checks your layouts/application.html.erb for `render partial: 'layouts/flash_messages' ` and adds it if it isn't there already
|
627
|
-
- the install generator also checks your spec/rails_helper for `config.include FactoryBot::Syntax::Methods` and adds it at the top of the Rspec configure block if it isn't there
|
628
|
-
|
629
|
-
#### 2021-10-07 - v0.2.4 - removes erroneous icons display in delete buttos (these don't work inside of button_to);
|
630
|
-
- adds support for ENUM types direclty on your field types
|
631
|
-
- you must use activerecord-pgenum
|
632
|
-
- see my blog post at https://jasonfleetwoodboldt.com/courses/stepping-up-rails/enumerated-types-in-rails-and-postgres/
|
633
|
-
|
634
|
-
#### 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
|
635
|
-
|
636
|
-
#### 2021-09-27 - v0.2.2 - Fixes some issues with related fields; unlocks Rails 7 in Gemspec file
|
637
|
-
|
638
|
-
#### 2021-09-20 - v0.2.1 - Fixes nesting behavior when using gd option
|
639
|
-
|
640
|
-
#### 2021-09-06 - v0.2.0 - ERB or HAML; use the option --markup=erb or --markup=haml (default is now erb)
|
641
|
-
|
642
|
-
#### 2021-06-28 - v0.1.2 - fixes problem with namespaces on path helpers
|
643
|
-
|
644
|
-
#### 2021-05-09 (yanked) - v0.1.1 - add cancellation buttons
|
645
|
-
|
646
|
-
#### 2021-04-28 - v0.1.0 - Very pleased to introduce full behavior specs, found in specs/system/, generated by default on all build code; also many fixes involving nesting and authentication"
|
647
|
-
|
648
|
-
#### 2021-03-24 - v0.0.9 - fixes in the automatic field label detection; cleans up junk in spec output
|
649
|
-
|
650
|
-
#### 2021-03-21 - v0.0.8 - show only flag; more specific spec coverage in generator spec
|
651
|
-
|
652
|
-
#### 2021-03-20 - v0.0.7 - adds lots of spec coverage; cleans up generated cruft code on each run; adds no-delete, no-create; a working --big-edit with basic data-turbo false to disable inline editing
|
653
|
-
|
654
|
-
#### 2021-03-06 - v0.0.6 - internal specs test the error catches and cover basic code generation (dummy testing only)
|
655
|
-
|
656
|
-
#### 2021-03-01 - v0.0.5 - Validation magic; refactors the options to the correct Rails::Generators syntax
|
657
|
-
|
658
|
-
#### (yanked) - v0.0.4
|
659
|
-
|
660
|
-
#### 2021-02-27 - v0.0.3 - several fixes for namespaces; adds pagination; adds exclude list to fields
|
661
|
-
|
662
|
-
#### 2021-02-25 - v0.0.2 - bootstrapy
|
663
|
-
|
664
|
-
#### 2021-02-24 - v0.0.1 - first proof of concept release -- basic CRUD works
|
665
|
-
|
666
|
-
#### 2021-02-23 - v0.0.0 - Port of my prior work from github.com/jasonfb/common_core_js
|
667
|
-
|
668
|
-
# PROBLEMS
|
669
|
-
|
670
|
-
Here are some defeciencies to note
|
671
|
-
|
672
|
-
- [ ] the ERB output has a necessary gsub that makes it so that every file always kicks the "Overwrite?" even when it has not changed. Unfortunately because of the meta programming involved in the ERB, I do not see a way around this although I would like to eventually fix it or match the AR generator internals to fix this problem.
|
673
|
-
|
674
|
-
- [ ] the system_spec that is generated (system/*_spec.rb) works most of the time but obviously you must run it to confirm it passes correclty. still working out bugs in this area for special cases.
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
- [ ] Note that the specs use FFaker data and random numbers, so if you have model-level validations and out-of-bounds choices are made, your specs might fail *intermittently*.
|
679
|
-
---> I know I hate intermittent failing specs, and if I had any in my app I would surely refactor them out. I'm not sure how I feel about *randomized* data-- or this much randomized data-- in specs. It's kind of fun but it also is tempting fate somewhat, and hopefully encouraging/forcing you to refactor them to be meaningful to your models and model-level validations.
|
680
|
-
|
681
|
-
- [ ] The specs themselves and some generated code is particularly ugly-- especially, formated inconsistently. Sorry about this, will clean this up soon. It is there to encourage you to read the generated code and lint or rubocop it before you check it in. I know the indentation is off and very ugly.
|
682
|
-
|
683
|
-
|
684
|
-
# HOW THIS GEM IS TESTED
|
685
|
-
|
686
|
-
SETUP:
|
687
|
-
• Run bundle install
|
688
|
-
• if you can't get through see https://stackoverflow.com/questions/68050807/gem-install-mimemagic-v-0-3-10-fails-to-install-on-big-sur/68170982#68170982
|
689
|
-
|
690
|
-
|
691
|
-
The dummy sandbox is found at `spec/dummy`
|
692
|
-
|
693
|
-
The dummy sandbox lives as mostly checked- into the repository, **except** the folders where the generated code goes (`spec/dummy/app/views/`, `spec/dummy/app/controllers/`, `spec/dummy/specs/` are excluded from Git)
|
694
|
-
|
695
|
-
When you run the **internal specs**, which you can do **at the root of this repo** using the command `rspec`, a set of specs will run to assert the generators are erroring when they are supposed to and producing code when they are supposed to.
|
696
|
-
|
697
|
-
The DUMMY testing DOES NOT test the actual functionality of the output code (it just tests the functionality of the generation process).
|
698
|
-
|