b4um_generators 0.2.11 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/README.de.md +165 -8
- data/README.md +162 -8
- data/lib/b4um_generators/version.rb +1 -1
- data/lib/generators/b4um/attachment/attachment_generator.rb +83 -23
- data/lib/generators/b4um/authentication/authentication_generator.rb +63 -0
- data/lib/generators/b4um/bento/bento_generator.rb +24 -0
- data/lib/generators/b4um/help/help_generator.rb +148 -11
- data/lib/generators/b4um/in_place/in_place_generator.rb +1231 -0
- data/lib/generators/b4um/in_place/templates/_flash.html.erb +15 -0
- data/lib/generators/b4um/in_place/templates/b4um_in_place_helper.rb +7 -0
- data/lib/generators/b4um/in_place/templates/display_attachment.html.erb.tt +154 -0
- data/lib/generators/b4um/in_place/templates/display_attachments.html.erb.tt +165 -0
- data/lib/generators/b4um/in_place/templates/display_boolean.html.erb.tt +18 -0
- data/lib/generators/b4um/in_place/templates/display_number.html.erb.tt +18 -0
- data/lib/generators/b4um/in_place/templates/display_radio.html.erb.tt +23 -0
- data/lib/generators/b4um/in_place/templates/display_rich_text.html.erb.tt +123 -0
- data/lib/generators/b4um/in_place/templates/display_select.html.erb.tt +23 -0
- data/lib/generators/b4um/in_place/templates/display_text.html.erb.tt +18 -0
- data/lib/generators/b4um/in_place/templates/edit_attachment.html.erb.tt +83 -0
- data/lib/generators/b4um/in_place/templates/edit_attachments.html.erb.tt +65 -0
- data/lib/generators/b4um/in_place/templates/edit_boolean.html.erb.tt +32 -0
- data/lib/generators/b4um/in_place/templates/edit_number.html.erb.tt +26 -0
- data/lib/generators/b4um/in_place/templates/edit_radio.html.erb.tt +32 -0
- data/lib/generators/b4um/in_place/templates/edit_rich_text.html.erb.tt +25 -0
- data/lib/generators/b4um/in_place/templates/edit_select.html.erb.tt +28 -0
- data/lib/generators/b4um/in_place/templates/edit_text.html.erb.tt +25 -0
- data/lib/generators/b4um/in_place/templates/in_place.css +935 -0
- data/lib/generators/b4um/in_place/templates/in_place_controller.js +115 -0
- data/lib/generators/b4um/install/install_generator.rb +18 -13
- data/lib/generators/b4um/install/templates/_flash.html.erb +15 -0
- data/lib/generators/b4um/install/templates/_footer.html.erb +6 -1
- data/lib/generators/b4um/install/templates/b4um/forms.css +127 -0
- data/lib/generators/b4um/install/templates/b4um/tables.css +49 -0
- data/lib/generators/b4um/install/templates/image_lightbox_controller.js +34 -1
- data/lib/generators/b4um/install/templates/rich_text_controller.js +22 -0
- data/lib/generators/b4um/install/templates/scroll_to_top_controller.js +12 -0
- data/lib/generators/b4um/scaffold/scaffold_generator.rb +106 -0
- data/lib/generators/b4um/scaffold/templates/_form.html.erb.tt +29 -0
- data/lib/generators/b4um/scaffold/templates/_resource.html.erb.tt +35 -0
- data/lib/generators/b4um/scaffold/templates/_table.html.erb.tt +31 -0
- data/lib/generators/b4um/table/table_generator.rb +187 -5
- data/lib/generators/b4um/table/templates/_table.html.erb.tt +286 -0
- data/lib/generators/b4um/trix/trix_generator.rb +104 -6
- metadata +27 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3872ce0dc22b0119d636611c3948c941da818ed3c8ee65301da95c0570ba677d
|
|
4
|
+
data.tar.gz: 77a2d8228dddbb5852325b81c1e1cc65482dc429912629884cf7c580438dac4e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e44802b32dc4e9ee22c7bd2b4507a34a692777ca0a940b904f0403223b0d36b7bbd9c403579a13cd2fe9409d76f86fd21cc487022d13b4abd7de0ef600f4e6a
|
|
7
|
+
data.tar.gz: 1a20c4ba742c086c788c5426085724d3bea2a3a01e30229ea1dc0f190b6ad4d2819a5c5609e326dd95fdfc4b70beb728260ded64a26416d0725322144e7f6b1b
|
data/.rubocop.yml
CHANGED
|
@@ -15,14 +15,14 @@ Style/StringLiteralsInInterpolation:
|
|
|
15
15
|
EnforcedStyle: double_quotes
|
|
16
16
|
|
|
17
17
|
Metrics/MethodLength:
|
|
18
|
-
Max:
|
|
18
|
+
Max: 1050
|
|
19
19
|
|
|
20
20
|
Metrics/BlockLength:
|
|
21
21
|
Exclude:
|
|
22
22
|
- 'spec/**/*'
|
|
23
23
|
|
|
24
24
|
Metrics/ClassLength:
|
|
25
|
-
Max:
|
|
25
|
+
Max: 1050
|
|
26
26
|
|
|
27
27
|
Metrics/AbcSize:
|
|
28
28
|
Max: 100
|
data/README.de.md
CHANGED
|
@@ -82,6 +82,7 @@ b4um:pagination
|
|
|
82
82
|
b4um:infinite_scroll
|
|
83
83
|
b4um:search
|
|
84
84
|
b4um:comments
|
|
85
|
+
b4um:in_place
|
|
85
86
|
b4um:authentication
|
|
86
87
|
b4um:trix
|
|
87
88
|
b4um:readable
|
|
@@ -114,6 +115,8 @@ Der Scaffold-Generator bietet:
|
|
|
114
115
|
- Index-, Show-, New- und Edit-Views
|
|
115
116
|
- Standardmäßig ein Bento-Index-Layout
|
|
116
117
|
- Optionales Tabellen-Index-Layout
|
|
118
|
+
- Select-Felder mit eigenen Anzeigebezeichnungen
|
|
119
|
+
- Radio-Felder mit eigenen Anzeigebezeichnungen
|
|
117
120
|
- Automatischen Navigationseintrag
|
|
118
121
|
- Aktiven Navigationszustand
|
|
119
122
|
- Anzeige von Formular-Validierungsfehlern
|
|
@@ -121,6 +124,45 @@ Der Scaffold-Generator bietet:
|
|
|
121
124
|
- Unterstützung für Passwortfelder
|
|
122
125
|
- Optionale lesbare URL-Parameter
|
|
123
126
|
|
|
127
|
+
### Select- und Radio-Felder
|
|
128
|
+
|
|
129
|
+
Der Scaffold-Generator kann String-Attribute als Select- oder Radio-Felder mit eigenen Anzeigebezeichnungen erzeugen.
|
|
130
|
+
|
|
131
|
+
Für ein Select-Feld verwende:
|
|
132
|
+
|
|
133
|
+
```text
|
|
134
|
+
--select='FIELD:VALUE=LABEL,VALUE=LABEL'
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Beispiel:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
bin/rails generate b4um:scaffold Product name:string status:string --select='status:Active=Aktiv,Inactive=Inaktiv'
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Für Radio-Buttons verwende:
|
|
144
|
+
|
|
145
|
+
```text
|
|
146
|
+
--radio='FIELD:VALUE=LABEL,VALUE=LABEL'
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Beispiel:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
bin/rails generate b4um:scaffold Product name:string condition:string --radio='condition:new=Neu,used=Gebraucht,refurbished=Generalüberholt'
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Beide Optionen können für unterschiedliche Felder miteinander kombiniert werden:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
bin/rails generate b4um:scaffold Product name:string status:string condition:string --select='status:Active=Aktiv,Inactive=Inaktiv' --radio='condition:new=Neu,used=Gebraucht'
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Die konfigurierten Werte werden in der Datenbank gespeichert. In Formularen, Ressourcen-Views und Tabellen-Layouts
|
|
162
|
+
werden dagegen die zugehörigen Anzeigebezeichnungen dargestellt.
|
|
163
|
+
|
|
164
|
+
Dasselbe Feld kann nicht gleichzeitig `--select` und `--radio` verwenden.
|
|
165
|
+
|
|
124
166
|
### Bento-Index
|
|
125
167
|
|
|
126
168
|
Der standardmäßige Scaffold-Index verwendet das responsive b4um-Bento-Kartenlayout.
|
|
@@ -260,16 +302,34 @@ Das Partial verwendet eine lokale Collection und kann daher auch mit einer ander
|
|
|
260
302
|
Erzeuge eine wiederverwendbare b4um-Tabelle für ein bestehendes Modell:
|
|
261
303
|
|
|
262
304
|
```bash
|
|
263
|
-
bin/rails generate b4um:table MODEL FIELDS
|
|
305
|
+
bin/rails generate b4um:table MODEL [FIELDS]
|
|
264
306
|
```
|
|
265
307
|
|
|
266
|
-
|
|
308
|
+
Das Modell muss bereits vorhanden sein.
|
|
309
|
+
|
|
310
|
+
Die Felder sind optional. Werden keine Felder angegeben, erkennt der Generator automatisch die Datenbankfelder des
|
|
311
|
+
Modells, Action-Text-Felder und Active-Storage-Anhänge. `id`, `created_at` und `updated_at` werden automatisch
|
|
312
|
+
ausgeschlossen.
|
|
313
|
+
|
|
314
|
+
Empfohlen:
|
|
267
315
|
|
|
268
316
|
```bash
|
|
269
|
-
bin/rails generate b4um:table Product
|
|
317
|
+
bin/rails generate b4um:table Product
|
|
270
318
|
```
|
|
271
319
|
|
|
272
|
-
|
|
320
|
+
Felder können weiterhin ausdrücklich angegeben werden:
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
bin/rails generate b4um:table Product name price status
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Konfigurierte Select- und Radio-Werte können mit ihren Beschriftungen dargestellt werden:
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
bin/rails generate b4um:table Product \
|
|
330
|
+
--select="status:active=Aktiv,inactive=Inaktiv" \
|
|
331
|
+
--radio="condition:new=Neu,used=Gebraucht"
|
|
332
|
+
```
|
|
273
333
|
|
|
274
334
|
Für ein `Product`-Modell wird das generierte Partial hier gespeichert:
|
|
275
335
|
|
|
@@ -279,20 +339,33 @@ app/views/products/_table.html.erb
|
|
|
279
339
|
|
|
280
340
|
Die generierte Tabelle bietet:
|
|
281
341
|
|
|
342
|
+
- Automatische Felderkennung aus dem bestehenden Modell
|
|
282
343
|
- Responsives Tabellenlayout
|
|
283
|
-
-
|
|
344
|
+
- Erkennung der tatsächlichen Feldtypen des Modells
|
|
284
345
|
- Kürzung von Textfeldern auf 100 Zeichen
|
|
346
|
+
- Formatierung von Dezimalwerten mit zwei Nachkommastellen
|
|
285
347
|
- Darstellung von Statusfeldern als b4um-Badges
|
|
348
|
+
- Beschriftungen für konfigurierte `--select`- und `--radio`-Werte
|
|
349
|
+
- Action-Text-/Trix-Inhalte
|
|
350
|
+
- Lightbox für Bilder innerhalb von Rich Text
|
|
351
|
+
- Übernahme von Trix-Bildbeschriftungen in die Lightbox
|
|
352
|
+
- Active-Storage-`has_one_attached`-Bilder
|
|
353
|
+
- Active-Storage-`has_many_attached`-Galerien
|
|
354
|
+
- Vorschaubilder, Lightbox-Navigation und Ziehen/Wischen
|
|
286
355
|
- Aktionsspalte mit Show-Button
|
|
287
356
|
- Empty-State-Darstellung
|
|
288
357
|
|
|
289
|
-
|
|
358
|
+
Beim Aufruf des Tabellen-Generators wird eine vorhandene b4um-Index-Ansicht automatisch auf das Tabellen-Partial
|
|
359
|
+
umgestellt:
|
|
290
360
|
|
|
291
361
|
```erb
|
|
292
362
|
<%= render "table", products: @products %>
|
|
293
363
|
```
|
|
294
364
|
|
|
295
|
-
|
|
365
|
+
Wird später `b4um:bento Product` ausgeführt, stellt der Generator den Index wieder auf das Bento-Partial zurück. Das
|
|
366
|
+
gilt auch für die Bento-Layouts `grid`, `list` und `alternating`.
|
|
367
|
+
|
|
368
|
+
Das Tabellen-Partial kann auch mit einer anderen Collection verwendet werden:
|
|
296
369
|
|
|
297
370
|
```erb
|
|
298
371
|
<%= render "products/table", products: @featured_products %>
|
|
@@ -690,6 +763,90 @@ Bestehende b4um-Comments-Controller werden automatisch erweitert.
|
|
|
690
763
|
Unbekannte benutzerdefinierte Comments-Controller bleiben unverändert und führen dazu, dass der Generator abbricht,
|
|
691
764
|
anstatt eigenen Code zu überschreiben.
|
|
692
765
|
|
|
766
|
+
## In-place Editing
|
|
767
|
+
|
|
768
|
+
Füge Feldern einer bestehenden b4um-Ressource eine direkte Bearbeitung hinzu:
|
|
769
|
+
|
|
770
|
+
```bash
|
|
771
|
+
bin/rails generate b4um:in_place MODEL FIELD [FIELD ...]
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
Beispiel für ein einzelnes Feld:
|
|
775
|
+
|
|
776
|
+
```bash
|
|
777
|
+
bin/rails generate b4um:in_place Product name
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
Mehrere Felder können in einem Durchlauf hinzugefügt werden:
|
|
781
|
+
|
|
782
|
+
```bash
|
|
783
|
+
bin/rails generate b4um:in_place Product name price status
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
Modell, Controller und Resource-Routen müssen bereits vorhanden sein.
|
|
787
|
+
|
|
788
|
+
Der Generator erkennt die vorhandenen Feldtypen automatisch und erstellt die passenden Editoren.
|
|
789
|
+
|
|
790
|
+
Unterstützte Felder sind:
|
|
791
|
+
|
|
792
|
+
- String- und Text-Felder
|
|
793
|
+
- Numerische und Decimal-Felder
|
|
794
|
+
- Boolean-Felder
|
|
795
|
+
- Action-Text-Rich-Text-Felder
|
|
796
|
+
- Einzelne Active-Storage-Bild-Attachments
|
|
797
|
+
- Mehrere Active-Storage-Bild-Attachments
|
|
798
|
+
|
|
799
|
+
### Select-Felder
|
|
800
|
+
|
|
801
|
+
Ein Feld kann mit `--select` als Auswahlliste dargestellt werden:
|
|
802
|
+
|
|
803
|
+
```bash
|
|
804
|
+
bin/rails generate b4um:in_place Product status --select='status:Active=Aktiv,Inactive=Inaktiv'
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
Der Wert vor `=` wird in der Datenbank gespeichert. Der optionale Wert nach `=` wird als sichtbare Beschriftung
|
|
808
|
+
verwendet.
|
|
809
|
+
|
|
810
|
+
Zum Beispiel speichert `Active=Aktiv` den Wert `Active`, während `Aktiv` angezeigt wird.
|
|
811
|
+
|
|
812
|
+
### Radio-Felder
|
|
813
|
+
|
|
814
|
+
Ein Feld kann mit `--radio` als Gruppe von Radio-Buttons dargestellt werden:
|
|
815
|
+
|
|
816
|
+
```bash
|
|
817
|
+
bin/rails generate b4um:in_place Product condition --radio='condition:new=Neu,used=Gebraucht,refurbished=Generalüberholt'
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
Für Radio-Felder gilt dieselbe Wert- und Beschriftungssyntax wie für `--select`.
|
|
821
|
+
|
|
822
|
+
### Verhalten der In-place-Bearbeitung
|
|
823
|
+
|
|
824
|
+
Die generierte In-place-Bearbeitung bietet:
|
|
825
|
+
|
|
826
|
+
- Bearbeitung mit Turbo Frames ohne zusätzliches In-place-Editing-Gem
|
|
827
|
+
- Direkte Bearbeitung innerhalb des bestehenden Ressourcen-Layouts
|
|
828
|
+
- Speichern von Text- und Rich-Text-Feldern beim Klick außerhalb des Editors
|
|
829
|
+
- Sofortiges Speichern von Select-, Radio- und Boolean-Feldern
|
|
830
|
+
- Bearbeitung einzelner und mehrerer Bild-Attachments
|
|
831
|
+
- Entfernen vorhandener Bild-Attachments
|
|
832
|
+
- Validierungsfehler direkt im Editor
|
|
833
|
+
- Sofortige Aktualisierung der Flash-Meldung nach erfolgreicher Änderung
|
|
834
|
+
- Mehrere Felder in einem Generator-Durchlauf
|
|
835
|
+
- Nachträgliches Hinzufügen weiterer Felder
|
|
836
|
+
- Sichere wiederholte Ausführung des Generators
|
|
837
|
+
|
|
838
|
+
### Authentifizierung
|
|
839
|
+
|
|
840
|
+
Die In-place-Bearbeitung integriert sich automatisch in die b4um-Authentifizierung.
|
|
841
|
+
|
|
842
|
+
Ohne Authentifizierung können die generierten In-place-Felder bearbeitet werden.
|
|
843
|
+
|
|
844
|
+
Wenn die b4um-Authentifizierung installiert ist, wird die In-place-Bearbeitung auf angemeldete Benutzer beschränkt und
|
|
845
|
+
die zugehörigen Controller-Actions werden mit `require_login` geschützt.
|
|
846
|
+
|
|
847
|
+
Die Authentifizierung kann vor oder nach der In-place-Bearbeitung installiert werden. Die Generatoren aktualisieren die
|
|
848
|
+
Integration in beiden Installationsreihenfolgen automatisch.
|
|
849
|
+
|
|
693
850
|
## Trix und Rich Text
|
|
694
851
|
|
|
695
852
|
Füge einer bestehenden b4um-Ressource Rails Action Text mit Trix hinzu:
|
|
@@ -978,7 +1135,7 @@ wird.
|
|
|
978
1135
|
|
|
979
1136
|
## Version
|
|
980
1137
|
|
|
981
|
-
Aktuelle Version: `0.2.
|
|
1138
|
+
Aktuelle Version: `0.2.16`
|
|
982
1139
|
|
|
983
1140
|
## Autor
|
|
984
1141
|
|
data/README.md
CHANGED
|
@@ -80,6 +80,7 @@ b4um:pagination
|
|
|
80
80
|
b4um:infinite_scroll
|
|
81
81
|
b4um:search
|
|
82
82
|
b4um:comments
|
|
83
|
+
b4um:in_place
|
|
83
84
|
b4um:authentication
|
|
84
85
|
b4um:trix
|
|
85
86
|
b4um:readable
|
|
@@ -112,6 +113,8 @@ The scaffold generator provides:
|
|
|
112
113
|
- Index, show, new and edit views
|
|
113
114
|
- Bento index layout by default
|
|
114
115
|
- Optional table index layout
|
|
116
|
+
- Select fields with custom labels
|
|
117
|
+
- Radio fields with custom labels
|
|
115
118
|
- Automatic navigation entry
|
|
116
119
|
- Active navigation state
|
|
117
120
|
- Form validation errors
|
|
@@ -119,6 +122,45 @@ The scaffold generator provides:
|
|
|
119
122
|
- Password field support
|
|
120
123
|
- Optional readable URL parameters
|
|
121
124
|
|
|
125
|
+
### Select and Radio Fields
|
|
126
|
+
|
|
127
|
+
The scaffold generator can render string attributes as select or radio fields with custom display labels.
|
|
128
|
+
|
|
129
|
+
For a select field, use:
|
|
130
|
+
|
|
131
|
+
```text
|
|
132
|
+
--select='FIELD:VALUE=LABEL,VALUE=LABEL'
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Example:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
bin/rails generate b4um:scaffold Product name:string status:string --select='status:Active=Aktiv,Inactive=Inaktiv'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
For radio buttons, use:
|
|
142
|
+
|
|
143
|
+
```text
|
|
144
|
+
--radio='FIELD:VALUE=LABEL,VALUE=LABEL'
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Example:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
bin/rails generate b4um:scaffold Product name:string condition:string --radio='condition:new=Neu,used=Gebraucht,refurbished=Generalüberholt'
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Both options can be combined for different fields:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
bin/rails generate b4um:scaffold Product name:string status:string condition:string --select='status:Active=Aktiv,Inactive=Inaktiv' --radio='condition:new=Neu,used=Gebraucht'
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
The configured values are stored in the database, while the labels are displayed in forms, resource views and table
|
|
160
|
+
layouts.
|
|
161
|
+
|
|
162
|
+
A field cannot use both `--select` and `--radio`.
|
|
163
|
+
|
|
122
164
|
### Bento Index
|
|
123
165
|
|
|
124
166
|
The default scaffold index uses the responsive b4um Bento card layout.
|
|
@@ -257,16 +299,33 @@ The partial uses a local collection and can therefore also be reused with anothe
|
|
|
257
299
|
Generate a reusable b4um table for an existing model:
|
|
258
300
|
|
|
259
301
|
```bash
|
|
260
|
-
bin/rails generate b4um:table MODEL FIELDS
|
|
302
|
+
bin/rails generate b4um:table MODEL [FIELDS]
|
|
261
303
|
```
|
|
262
304
|
|
|
263
|
-
|
|
305
|
+
The model must already exist.
|
|
306
|
+
|
|
307
|
+
Fields are optional. If no fields are supplied, the generator automatically detects the model's database fields, Action
|
|
308
|
+
Text fields and Active Storage attachments. `id`, `created_at` and `updated_at` are excluded automatically.
|
|
309
|
+
|
|
310
|
+
Recommended:
|
|
264
311
|
|
|
265
312
|
```bash
|
|
266
|
-
bin/rails generate b4um:table Product
|
|
313
|
+
bin/rails generate b4um:table Product
|
|
267
314
|
```
|
|
268
315
|
|
|
269
|
-
|
|
316
|
+
Fields can also be specified explicitly:
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
bin/rails generate b4um:table Product name price status
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Configured select and radio values can be displayed using their labels:
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
bin/rails generate b4um:table Product \
|
|
326
|
+
--select="status:active=Active,inactive=Inactive" \
|
|
327
|
+
--radio="condition:new=New,used=Used"
|
|
328
|
+
```
|
|
270
329
|
|
|
271
330
|
For a `Product` model, the generated partial is stored at:
|
|
272
331
|
|
|
@@ -276,20 +335,32 @@ app/views/products/_table.html.erb
|
|
|
276
335
|
|
|
277
336
|
The generated table provides:
|
|
278
337
|
|
|
338
|
+
- Automatic field detection from the existing model
|
|
279
339
|
- Responsive table layout
|
|
280
|
-
-
|
|
340
|
+
- Model-aware field types
|
|
281
341
|
- Text fields shortened to 100 characters
|
|
342
|
+
- Decimal values formatted with two decimal places
|
|
282
343
|
- Status fields displayed as b4um badges
|
|
344
|
+
- Labels for configured `--select` and `--radio` values
|
|
345
|
+
- Action Text / Trix content
|
|
346
|
+
- Lightbox support for images embedded in rich text
|
|
347
|
+
- Trix image captions in the Lightbox
|
|
348
|
+
- Active Storage `has_one_attached` images
|
|
349
|
+
- Active Storage `has_many_attached` galleries
|
|
350
|
+
- Thumbnails, Lightbox navigation and drag/swipe support
|
|
283
351
|
- Actions column with a Show button
|
|
284
352
|
- Empty-state handling
|
|
285
353
|
|
|
286
|
-
|
|
354
|
+
Running the Table generator automatically switches an existing b4um index view to the table partial:
|
|
287
355
|
|
|
288
356
|
```erb
|
|
289
357
|
<%= render "table", products: @products %>
|
|
290
358
|
```
|
|
291
359
|
|
|
292
|
-
|
|
360
|
+
Running `b4um:bento Product` later switches the index back to the Bento partial. This also applies to the `grid`, `list`
|
|
361
|
+
and `alternating` Bento layouts.
|
|
362
|
+
|
|
363
|
+
The table partial can also be reused with another collection:
|
|
293
364
|
|
|
294
365
|
```erb
|
|
295
366
|
<%= render "products/table", products: @featured_products %>
|
|
@@ -685,6 +756,89 @@ Existing b4um comments controllers are extended automatically.
|
|
|
685
756
|
Unknown custom comments controllers are left unchanged and cause the generator to stop instead of overwriting custom
|
|
686
757
|
code.
|
|
687
758
|
|
|
759
|
+
## In-place Editing
|
|
760
|
+
|
|
761
|
+
Add in-place editing to fields of an existing b4um resource:
|
|
762
|
+
|
|
763
|
+
```bash
|
|
764
|
+
bin/rails generate b4um:in_place MODEL FIELD [FIELD ...]
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
Example for a single field:
|
|
768
|
+
|
|
769
|
+
```bash
|
|
770
|
+
bin/rails generate b4um:in_place Product name
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
Multiple fields can be added in one run:
|
|
774
|
+
|
|
775
|
+
```bash
|
|
776
|
+
bin/rails generate b4um:in_place Product name price status
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
The model, controller and resource routes must already exist.
|
|
780
|
+
|
|
781
|
+
The generator detects the existing field types and creates the appropriate editors.
|
|
782
|
+
|
|
783
|
+
Supported fields include:
|
|
784
|
+
|
|
785
|
+
- String and text fields
|
|
786
|
+
- Numeric and decimal fields
|
|
787
|
+
- Boolean fields
|
|
788
|
+
- Action Text rich-text fields
|
|
789
|
+
- Active Storage single image attachments
|
|
790
|
+
- Active Storage multiple image attachments
|
|
791
|
+
|
|
792
|
+
### Select Fields
|
|
793
|
+
|
|
794
|
+
A field can be rendered as a select list with `--select`:
|
|
795
|
+
|
|
796
|
+
```bash
|
|
797
|
+
bin/rails generate b4um:in_place Product status --select='status:Active=Aktiv,Inactive=Inaktiv'
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
The value before `=` is stored in the database. The optional value after `=` is used as the displayed label.
|
|
801
|
+
|
|
802
|
+
For example, `Active=Aktiv` stores `Active` while displaying `Aktiv`.
|
|
803
|
+
|
|
804
|
+
### Radio Fields
|
|
805
|
+
|
|
806
|
+
A field can be rendered as radio buttons with `--radio`:
|
|
807
|
+
|
|
808
|
+
```bash
|
|
809
|
+
bin/rails generate b4um:in_place Product condition --radio='condition:new=Neu,used=Gebraucht,refurbished=Generalüberholt'
|
|
810
|
+
```
|
|
811
|
+
|
|
812
|
+
The same value and label syntax used by `--select` applies to radio fields.
|
|
813
|
+
|
|
814
|
+
### In-place Editing Behavior
|
|
815
|
+
|
|
816
|
+
Generated in-place editing provides:
|
|
817
|
+
|
|
818
|
+
- Turbo Frame based editing without an additional in-place editing gem
|
|
819
|
+
- Editing directly inside the existing resource layout
|
|
820
|
+
- Outside-click saving for text and rich-text fields
|
|
821
|
+
- Immediate saving for select, radio and boolean fields
|
|
822
|
+
- Single and multiple image attachment editing
|
|
823
|
+
- Removal of existing image attachments
|
|
824
|
+
- Inline validation errors
|
|
825
|
+
- Immediate flash-message updates after successful changes
|
|
826
|
+
- Multiple fields in one generator run
|
|
827
|
+
- Additional fields in later generator runs
|
|
828
|
+
- Safe repeated generator runs
|
|
829
|
+
|
|
830
|
+
### Authentication
|
|
831
|
+
|
|
832
|
+
In-place editing integrates automatically with b4um authentication.
|
|
833
|
+
|
|
834
|
+
Without authentication, generated in-place fields are editable.
|
|
835
|
+
|
|
836
|
+
When b4um authentication is installed, in-place editing is restricted to logged-in users and the corresponding
|
|
837
|
+
controller actions are protected with `require_login`.
|
|
838
|
+
|
|
839
|
+
Authentication can be installed either before or after in-place editing. The generators update the integration
|
|
840
|
+
automatically in both installation orders.
|
|
841
|
+
|
|
688
842
|
## Trix and Rich Text
|
|
689
843
|
|
|
690
844
|
Add Rails Action Text with Trix to an existing b4um resource:
|
|
@@ -970,7 +1124,7 @@ The gem can be tested locally by referencing the repository with `path:` from a
|
|
|
970
1124
|
|
|
971
1125
|
## Version
|
|
972
1126
|
|
|
973
|
-
Current version: `0.2.
|
|
1127
|
+
Current version: `0.2.16`
|
|
974
1128
|
|
|
975
1129
|
## Author
|
|
976
1130
|
|
|
@@ -134,19 +134,24 @@ module B4um
|
|
|
134
134
|
|
|
135
135
|
insertion = ":#{attachment}, :remove_#{attachment}"
|
|
136
136
|
|
|
137
|
+
normalized_attributes =
|
|
138
|
+
attributes
|
|
139
|
+
.strip
|
|
140
|
+
.gsub(/\s+,/, ",")
|
|
141
|
+
|
|
137
142
|
updated_attributes =
|
|
138
|
-
if
|
|
139
|
-
|
|
143
|
+
if normalized_attributes.match?(/\w+:\s*\[/)
|
|
144
|
+
normalized_attributes.sub(
|
|
140
145
|
/(?=\w+:\s*\[)/,
|
|
141
146
|
"#{insertion}, "
|
|
142
147
|
)
|
|
143
148
|
else
|
|
144
|
-
"#{
|
|
149
|
+
"#{normalized_attributes}, #{insertion}"
|
|
145
150
|
end
|
|
146
151
|
|
|
147
152
|
match.sub(
|
|
148
153
|
attributes,
|
|
149
|
-
updated_attributes
|
|
154
|
+
" #{updated_attributes} "
|
|
150
155
|
)
|
|
151
156
|
end
|
|
152
157
|
end
|
|
@@ -220,23 +225,59 @@ module B4um
|
|
|
220
225
|
def update_multiple_permitted_params(content)
|
|
221
226
|
return if multiple_attachment_permitted?(content)
|
|
222
227
|
|
|
223
|
-
|
|
228
|
+
params_method_pattern = /
|
|
229
|
+
def\s+#{Regexp.escape(file_name)}_params
|
|
230
|
+
(?<body>.*?)
|
|
231
|
+
^\s*end
|
|
232
|
+
/mx
|
|
233
|
+
|
|
234
|
+
params_method = content[params_method_pattern, 0]
|
|
235
|
+
|
|
236
|
+
unless params_method
|
|
237
|
+
raise Thor::Error,
|
|
238
|
+
"Could not find #{file_name}_params in #{controller_path}"
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
expect_pattern = /
|
|
224
242
|
params\.expect\(
|
|
225
243
|
#{Regexp.escape(file_name)}:\s*
|
|
226
244
|
\[
|
|
227
|
-
(?<attributes
|
|
245
|
+
(?<attributes>.*)
|
|
228
246
|
\]
|
|
229
247
|
\)
|
|
230
248
|
/mx
|
|
231
249
|
|
|
232
|
-
|
|
250
|
+
match_data = expect_pattern.match(params_method)
|
|
233
251
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
", #{attachment}: [], remove_#{attachment}_ids: []])"
|
|
238
|
-
)
|
|
252
|
+
unless match_data
|
|
253
|
+
raise Thor::Error,
|
|
254
|
+
"Could not find params.expect for #{file_name} in #{controller_path}"
|
|
239
255
|
end
|
|
256
|
+
|
|
257
|
+
normalized_attributes =
|
|
258
|
+
match_data[:attributes]
|
|
259
|
+
.strip
|
|
260
|
+
.gsub(/\s+,/, ",")
|
|
261
|
+
|
|
262
|
+
updated_attributes =
|
|
263
|
+
"#{normalized_attributes}, " \
|
|
264
|
+
"#{attachment}: [], " \
|
|
265
|
+
"remove_#{attachment}_ids: []"
|
|
266
|
+
|
|
267
|
+
updated_params_method =
|
|
268
|
+
params_method.sub(
|
|
269
|
+
match_data[0],
|
|
270
|
+
match_data[0].sub(
|
|
271
|
+
match_data[:attributes],
|
|
272
|
+
" #{updated_attributes} "
|
|
273
|
+
)
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
gsub_file(
|
|
277
|
+
controller_path,
|
|
278
|
+
params_method,
|
|
279
|
+
updated_params_method
|
|
280
|
+
)
|
|
240
281
|
end
|
|
241
282
|
|
|
242
283
|
def multiple_attachment_permitted?(content)
|
|
@@ -252,24 +293,43 @@ module B4um
|
|
|
252
293
|
"new_#{attachment} = update_params.delete(\"#{attachment}\")"
|
|
253
294
|
)
|
|
254
295
|
|
|
296
|
+
unless content.include?(" update_params = #{file_name}_params\n")
|
|
297
|
+
gsub_file(
|
|
298
|
+
controller_path,
|
|
299
|
+
" def update\n respond_to do |format|\n",
|
|
300
|
+
[
|
|
301
|
+
" def update",
|
|
302
|
+
" update_params = #{file_name}_params",
|
|
303
|
+
"",
|
|
304
|
+
" respond_to do |format|",
|
|
305
|
+
""
|
|
306
|
+
].join("\n")
|
|
307
|
+
)
|
|
308
|
+
end
|
|
309
|
+
|
|
255
310
|
setup = [
|
|
256
|
-
" def update",
|
|
257
|
-
" update_params = #{file_name}_params",
|
|
258
311
|
" new_#{attachment} = update_params.delete(\"#{attachment}\")",
|
|
259
312
|
" remove_#{attachment}_ids = update_params.delete(\"remove_#{attachment}_ids\")",
|
|
260
|
-
"",
|
|
261
|
-
" respond_to do |format|",
|
|
262
313
|
""
|
|
263
314
|
].join("\n")
|
|
264
315
|
|
|
265
|
-
|
|
316
|
+
insert_into_file(
|
|
266
317
|
controller_path,
|
|
267
|
-
|
|
268
|
-
|
|
318
|
+
setup,
|
|
319
|
+
after: " update_params = #{file_name}_params\n"
|
|
269
320
|
)
|
|
270
321
|
|
|
322
|
+
content = File.read(controller_path)
|
|
323
|
+
|
|
324
|
+
unless content.include?(" if @#{file_name}.update(update_params)\n")
|
|
325
|
+
gsub_file(
|
|
326
|
+
controller_path,
|
|
327
|
+
" if @#{file_name}.update(#{file_name}_params)\n",
|
|
328
|
+
" if @#{file_name}.update(update_params)\n"
|
|
329
|
+
)
|
|
330
|
+
end
|
|
331
|
+
|
|
271
332
|
attachment_handling = [
|
|
272
|
-
" if @#{file_name}.update(update_params)",
|
|
273
333
|
" @#{file_name}.#{attachment}.attach(new_#{attachment}) if new_#{attachment}.present?",
|
|
274
334
|
"",
|
|
275
335
|
" if remove_#{attachment}_ids.present?",
|
|
@@ -280,10 +340,10 @@ module B4um
|
|
|
280
340
|
""
|
|
281
341
|
].join("\n")
|
|
282
342
|
|
|
283
|
-
|
|
343
|
+
insert_into_file(
|
|
284
344
|
controller_path,
|
|
285
|
-
|
|
286
|
-
|
|
345
|
+
attachment_handling,
|
|
346
|
+
after: " if @#{file_name}.update(update_params)\n"
|
|
287
347
|
)
|
|
288
348
|
end
|
|
289
349
|
|