b4um_generators 0.2.11 → 0.2.14
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 +127 -1
- data/README.md +126 -1
- 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/help/help_generator.rb +100 -3
- 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/image_lightbox_controller.js +29 -0
- 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/trix/trix_generator.rb +104 -6
- metadata +25 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b1f1050f028cad2eefaf3b2643268bd1e55267aefd8029a8c286e56a5f64b27d
|
|
4
|
+
data.tar.gz: be01b49c59c57796e2f9d83ae1d0f065119edc374a2addd64166063a17c6bc15
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 107f73e822050fbe81d7a9e12419a988478d63ba929215e6aad778fcc4e8b37a93695b778b95b881b3476eda91c5dec04b497648ad6f1038c011971bfcb89bcf
|
|
7
|
+
data.tar.gz: 94552c06de7aba5a9aa211f576447fa8a85dc45fb5eaee2158278d57f1ab8e3cc21727e94d21d2fac36fc356155cba4c2c07bbd7bed55f39cc9a6b4db369e05d
|
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.
|
|
@@ -690,6 +732,90 @@ Bestehende b4um-Comments-Controller werden automatisch erweitert.
|
|
|
690
732
|
Unbekannte benutzerdefinierte Comments-Controller bleiben unverändert und führen dazu, dass der Generator abbricht,
|
|
691
733
|
anstatt eigenen Code zu überschreiben.
|
|
692
734
|
|
|
735
|
+
## In-place Editing
|
|
736
|
+
|
|
737
|
+
Füge Feldern einer bestehenden b4um-Ressource eine direkte Bearbeitung hinzu:
|
|
738
|
+
|
|
739
|
+
```bash
|
|
740
|
+
bin/rails generate b4um:in_place MODEL FIELD [FIELD ...]
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
Beispiel für ein einzelnes Feld:
|
|
744
|
+
|
|
745
|
+
```bash
|
|
746
|
+
bin/rails generate b4um:in_place Product name
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
Mehrere Felder können in einem Durchlauf hinzugefügt werden:
|
|
750
|
+
|
|
751
|
+
```bash
|
|
752
|
+
bin/rails generate b4um:in_place Product name price status
|
|
753
|
+
```
|
|
754
|
+
|
|
755
|
+
Modell, Controller und Resource-Routen müssen bereits vorhanden sein.
|
|
756
|
+
|
|
757
|
+
Der Generator erkennt die vorhandenen Feldtypen automatisch und erstellt die passenden Editoren.
|
|
758
|
+
|
|
759
|
+
Unterstützte Felder sind:
|
|
760
|
+
|
|
761
|
+
- String- und Text-Felder
|
|
762
|
+
- Numerische und Decimal-Felder
|
|
763
|
+
- Boolean-Felder
|
|
764
|
+
- Action-Text-Rich-Text-Felder
|
|
765
|
+
- Einzelne Active-Storage-Bild-Attachments
|
|
766
|
+
- Mehrere Active-Storage-Bild-Attachments
|
|
767
|
+
|
|
768
|
+
### Select-Felder
|
|
769
|
+
|
|
770
|
+
Ein Feld kann mit `--select` als Auswahlliste dargestellt werden:
|
|
771
|
+
|
|
772
|
+
```bash
|
|
773
|
+
bin/rails generate b4um:in_place Product status --select='status:Active=Aktiv,Inactive=Inaktiv'
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
Der Wert vor `=` wird in der Datenbank gespeichert. Der optionale Wert nach `=` wird als sichtbare Beschriftung
|
|
777
|
+
verwendet.
|
|
778
|
+
|
|
779
|
+
Zum Beispiel speichert `Active=Aktiv` den Wert `Active`, während `Aktiv` angezeigt wird.
|
|
780
|
+
|
|
781
|
+
### Radio-Felder
|
|
782
|
+
|
|
783
|
+
Ein Feld kann mit `--radio` als Gruppe von Radio-Buttons dargestellt werden:
|
|
784
|
+
|
|
785
|
+
```bash
|
|
786
|
+
bin/rails generate b4um:in_place Product condition --radio='condition:new=Neu,used=Gebraucht,refurbished=Generalüberholt'
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
Für Radio-Felder gilt dieselbe Wert- und Beschriftungssyntax wie für `--select`.
|
|
790
|
+
|
|
791
|
+
### Verhalten der In-place-Bearbeitung
|
|
792
|
+
|
|
793
|
+
Die generierte In-place-Bearbeitung bietet:
|
|
794
|
+
|
|
795
|
+
- Bearbeitung mit Turbo Frames ohne zusätzliches In-place-Editing-Gem
|
|
796
|
+
- Direkte Bearbeitung innerhalb des bestehenden Ressourcen-Layouts
|
|
797
|
+
- Speichern von Text- und Rich-Text-Feldern beim Klick außerhalb des Editors
|
|
798
|
+
- Sofortiges Speichern von Select-, Radio- und Boolean-Feldern
|
|
799
|
+
- Bearbeitung einzelner und mehrerer Bild-Attachments
|
|
800
|
+
- Entfernen vorhandener Bild-Attachments
|
|
801
|
+
- Validierungsfehler direkt im Editor
|
|
802
|
+
- Sofortige Aktualisierung der Flash-Meldung nach erfolgreicher Änderung
|
|
803
|
+
- Mehrere Felder in einem Generator-Durchlauf
|
|
804
|
+
- Nachträgliches Hinzufügen weiterer Felder
|
|
805
|
+
- Sichere wiederholte Ausführung des Generators
|
|
806
|
+
|
|
807
|
+
### Authentifizierung
|
|
808
|
+
|
|
809
|
+
Die In-place-Bearbeitung integriert sich automatisch in die b4um-Authentifizierung.
|
|
810
|
+
|
|
811
|
+
Ohne Authentifizierung können die generierten In-place-Felder bearbeitet werden.
|
|
812
|
+
|
|
813
|
+
Wenn die b4um-Authentifizierung installiert ist, wird die In-place-Bearbeitung auf angemeldete Benutzer beschränkt und
|
|
814
|
+
die zugehörigen Controller-Actions werden mit `require_login` geschützt.
|
|
815
|
+
|
|
816
|
+
Die Authentifizierung kann vor oder nach der In-place-Bearbeitung installiert werden. Die Generatoren aktualisieren die
|
|
817
|
+
Integration in beiden Installationsreihenfolgen automatisch.
|
|
818
|
+
|
|
693
819
|
## Trix und Rich Text
|
|
694
820
|
|
|
695
821
|
Füge einer bestehenden b4um-Ressource Rails Action Text mit Trix hinzu:
|
|
@@ -978,7 +1104,7 @@ wird.
|
|
|
978
1104
|
|
|
979
1105
|
## Version
|
|
980
1106
|
|
|
981
|
-
Aktuelle Version: `0.2.
|
|
1107
|
+
Aktuelle Version: `0.2.14`
|
|
982
1108
|
|
|
983
1109
|
## Autor
|
|
984
1110
|
|
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.
|
|
@@ -685,6 +727,89 @@ Existing b4um comments controllers are extended automatically.
|
|
|
685
727
|
Unknown custom comments controllers are left unchanged and cause the generator to stop instead of overwriting custom
|
|
686
728
|
code.
|
|
687
729
|
|
|
730
|
+
## In-place Editing
|
|
731
|
+
|
|
732
|
+
Add in-place editing to fields of an existing b4um resource:
|
|
733
|
+
|
|
734
|
+
```bash
|
|
735
|
+
bin/rails generate b4um:in_place MODEL FIELD [FIELD ...]
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
Example for a single field:
|
|
739
|
+
|
|
740
|
+
```bash
|
|
741
|
+
bin/rails generate b4um:in_place Product name
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
Multiple fields can be added in one run:
|
|
745
|
+
|
|
746
|
+
```bash
|
|
747
|
+
bin/rails generate b4um:in_place Product name price status
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
The model, controller and resource routes must already exist.
|
|
751
|
+
|
|
752
|
+
The generator detects the existing field types and creates the appropriate editors.
|
|
753
|
+
|
|
754
|
+
Supported fields include:
|
|
755
|
+
|
|
756
|
+
- String and text fields
|
|
757
|
+
- Numeric and decimal fields
|
|
758
|
+
- Boolean fields
|
|
759
|
+
- Action Text rich-text fields
|
|
760
|
+
- Active Storage single image attachments
|
|
761
|
+
- Active Storage multiple image attachments
|
|
762
|
+
|
|
763
|
+
### Select Fields
|
|
764
|
+
|
|
765
|
+
A field can be rendered as a select list with `--select`:
|
|
766
|
+
|
|
767
|
+
```bash
|
|
768
|
+
bin/rails generate b4um:in_place Product status --select='status:Active=Aktiv,Inactive=Inaktiv'
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
The value before `=` is stored in the database. The optional value after `=` is used as the displayed label.
|
|
772
|
+
|
|
773
|
+
For example, `Active=Aktiv` stores `Active` while displaying `Aktiv`.
|
|
774
|
+
|
|
775
|
+
### Radio Fields
|
|
776
|
+
|
|
777
|
+
A field can be rendered as radio buttons with `--radio`:
|
|
778
|
+
|
|
779
|
+
```bash
|
|
780
|
+
bin/rails generate b4um:in_place Product condition --radio='condition:new=Neu,used=Gebraucht,refurbished=Generalüberholt'
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
The same value and label syntax used by `--select` applies to radio fields.
|
|
784
|
+
|
|
785
|
+
### In-place Editing Behavior
|
|
786
|
+
|
|
787
|
+
Generated in-place editing provides:
|
|
788
|
+
|
|
789
|
+
- Turbo Frame based editing without an additional in-place editing gem
|
|
790
|
+
- Editing directly inside the existing resource layout
|
|
791
|
+
- Outside-click saving for text and rich-text fields
|
|
792
|
+
- Immediate saving for select, radio and boolean fields
|
|
793
|
+
- Single and multiple image attachment editing
|
|
794
|
+
- Removal of existing image attachments
|
|
795
|
+
- Inline validation errors
|
|
796
|
+
- Immediate flash-message updates after successful changes
|
|
797
|
+
- Multiple fields in one generator run
|
|
798
|
+
- Additional fields in later generator runs
|
|
799
|
+
- Safe repeated generator runs
|
|
800
|
+
|
|
801
|
+
### Authentication
|
|
802
|
+
|
|
803
|
+
In-place editing integrates automatically with b4um authentication.
|
|
804
|
+
|
|
805
|
+
Without authentication, generated in-place fields are editable.
|
|
806
|
+
|
|
807
|
+
When b4um authentication is installed, in-place editing is restricted to logged-in users and the corresponding
|
|
808
|
+
controller actions are protected with `require_login`.
|
|
809
|
+
|
|
810
|
+
Authentication can be installed either before or after in-place editing. The generators update the integration
|
|
811
|
+
automatically in both installation orders.
|
|
812
|
+
|
|
688
813
|
## Trix and Rich Text
|
|
689
814
|
|
|
690
815
|
Add Rails Action Text with Trix to an existing b4um resource:
|
|
@@ -970,7 +1095,7 @@ The gem can be tested locally by referencing the repository with `path:` from a
|
|
|
970
1095
|
|
|
971
1096
|
## Version
|
|
972
1097
|
|
|
973
|
-
Current version: `0.2.
|
|
1098
|
+
Current version: `0.2.14`
|
|
974
1099
|
|
|
975
1100
|
## Author
|
|
976
1101
|
|
|
@@ -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
|
|
|
@@ -149,6 +149,69 @@ module B4um
|
|
|
149
149
|
end
|
|
150
150
|
end
|
|
151
151
|
|
|
152
|
+
def update_in_place_helper
|
|
153
|
+
helper_path = "app/helpers/b4um_in_place_helper.rb"
|
|
154
|
+
|
|
155
|
+
full_helper_path = File.join(
|
|
156
|
+
destination_root,
|
|
157
|
+
helper_path
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
return unless File.exist?(full_helper_path)
|
|
161
|
+
|
|
162
|
+
helper = File.read(full_helper_path)
|
|
163
|
+
|
|
164
|
+
return if helper.include?(
|
|
165
|
+
"def b4um_in_place_editing_allowed?\n logged_in?"
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
gsub_file(
|
|
169
|
+
helper_path,
|
|
170
|
+
"def b4um_in_place_editing_allowed?\n true",
|
|
171
|
+
"def b4um_in_place_editing_allowed?\n logged_in?"
|
|
172
|
+
)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def protect_in_place_controllers
|
|
176
|
+
controllers_path = File.join(
|
|
177
|
+
destination_root,
|
|
178
|
+
"app/controllers"
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
return unless Dir.exist?(controllers_path)
|
|
182
|
+
|
|
183
|
+
Dir.glob(
|
|
184
|
+
File.join(controllers_path, "*_controller.rb")
|
|
185
|
+
).each do |full_controller_path|
|
|
186
|
+
controller = File.read(full_controller_path)
|
|
187
|
+
|
|
188
|
+
next unless controller.include?("IN_PLACE_FIELDS")
|
|
189
|
+
|
|
190
|
+
controller_name =
|
|
191
|
+
File
|
|
192
|
+
.basename(full_controller_path, "_controller.rb")
|
|
193
|
+
|
|
194
|
+
protect_index_actions_for(controller_name)
|
|
195
|
+
protect_show_actions_for(controller_name)
|
|
196
|
+
|
|
197
|
+
callback =
|
|
198
|
+
"before_action :require_login, except: [:index, :show]"
|
|
199
|
+
|
|
200
|
+
next if controller.include?(callback)
|
|
201
|
+
|
|
202
|
+
controller_path = full_controller_path.delete_prefix(
|
|
203
|
+
"#{destination_root}/"
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
inject_into_file(
|
|
207
|
+
controller_path,
|
|
208
|
+
after: /^class .*Controller < ApplicationController\s*$/
|
|
209
|
+
) do
|
|
210
|
+
"\n #{callback}"
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
152
215
|
def add_session_routes
|
|
153
216
|
routes_path = "config/routes.rb"
|
|
154
217
|
full_routes_path = File.join(destination_root, routes_path)
|