b4um_generators 0.2.10 → 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 +190 -29
- 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 +27 -3
|
@@ -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)
|
|
@@ -362,6 +362,8 @@ module B4um
|
|
|
362
362
|
- b4um index, show, new and edit views
|
|
363
363
|
- Bento index layout by default
|
|
364
364
|
- Optional table index layout
|
|
365
|
+
- Select fields with custom labels
|
|
366
|
+
- Radio fields with custom labels
|
|
365
367
|
- Automatic navigation entry
|
|
366
368
|
- Active navigation state
|
|
367
369
|
- Form validation errors
|
|
@@ -369,6 +371,34 @@ module B4um
|
|
|
369
371
|
- Password field support
|
|
370
372
|
- Optional readable URL parameters
|
|
371
373
|
|
|
374
|
+
Select fields can be generated with:
|
|
375
|
+
|
|
376
|
+
--select='FIELD:VALUE=LABEL,VALUE=LABEL'
|
|
377
|
+
|
|
378
|
+
Example:
|
|
379
|
+
|
|
380
|
+
bin/rails generate b4um:scaffold Product name:string status:string --select='status:Active=Aktiv,Inactive=Inaktiv'
|
|
381
|
+
|
|
382
|
+
Radio fields use the same value and label syntax:
|
|
383
|
+
|
|
384
|
+
--radio='FIELD:VALUE=LABEL,VALUE=LABEL'
|
|
385
|
+
|
|
386
|
+
Example:
|
|
387
|
+
|
|
388
|
+
bin/rails generate b4um:scaffold Product name:string condition:string --radio='condition:new=Neu,used=Gebraucht,refurbished=Generalüberholt'
|
|
389
|
+
|
|
390
|
+
The configured values are stored in the database. The labels
|
|
391
|
+
are displayed in forms, resource views and table layouts.
|
|
392
|
+
|
|
393
|
+
Select and radio options can be used together for different
|
|
394
|
+
fields.
|
|
395
|
+
|
|
396
|
+
Example:
|
|
397
|
+
|
|
398
|
+
bin/rails generate b4um:scaffold Product name:string status:string condition:string --select='status:Active=Aktiv,Inactive=Inaktiv' --radio='condition:new=Neu,used=Gebraucht'
|
|
399
|
+
|
|
400
|
+
The same field cannot use both --select and --radio.
|
|
401
|
+
|
|
372
402
|
The default index uses the b4um Bento card layout.
|
|
373
403
|
|
|
374
404
|
To generate a table index instead, use:
|
|
@@ -905,6 +935,67 @@ module B4um
|
|
|
905
935
|
the generator to stop with an error.
|
|
906
936
|
|
|
907
937
|
|
|
938
|
+
IN-PLACE EDITING
|
|
939
|
+
|
|
940
|
+
bin/rails generate b4um:in_place MODEL FIELD [FIELD ...]
|
|
941
|
+
|
|
942
|
+
Adds in-place editing to fields of an existing b4um resource.
|
|
943
|
+
|
|
944
|
+
Examples:
|
|
945
|
+
|
|
946
|
+
bin/rails generate b4um:in_place Product name
|
|
947
|
+
bin/rails generate b4um:in_place Product name price status
|
|
948
|
+
|
|
949
|
+
The model, controller and resource routes must already exist.
|
|
950
|
+
|
|
951
|
+
The generator detects the field type automatically and creates
|
|
952
|
+
the appropriate in-place editor.
|
|
953
|
+
|
|
954
|
+
Supported fields include:
|
|
955
|
+
|
|
956
|
+
- String and text fields
|
|
957
|
+
- Numeric and decimal fields
|
|
958
|
+
- Boolean fields
|
|
959
|
+
- Action Text rich text fields
|
|
960
|
+
- Active Storage single image attachments
|
|
961
|
+
- Active Storage multiple image attachments
|
|
962
|
+
|
|
963
|
+
Select fields can be configured with --select:
|
|
964
|
+
|
|
965
|
+
bin/rails generate b4um:in_place Product status --select='status:Active=Aktiv,Inactive=Inaktiv'
|
|
966
|
+
|
|
967
|
+
Radio buttons can be configured with --radio:
|
|
968
|
+
|
|
969
|
+
bin/rails generate b4um:in_place Product condition --radio='condition:new=Neu,used=Gebraucht,refurbished=Generalüberholt'
|
|
970
|
+
|
|
971
|
+
The value before "=" is stored in the database.
|
|
972
|
+
The optional value after "=" is used as the displayed label.
|
|
973
|
+
|
|
974
|
+
In-place editing features:
|
|
975
|
+
|
|
976
|
+
- Turbo Frame based editing without an additional in-place gem
|
|
977
|
+
- Click a displayed field to edit it in place
|
|
978
|
+
- Text and rich text fields save when clicking outside
|
|
979
|
+
- Select, radio, and boolean fields save immediately
|
|
980
|
+
- Single and multiple image attachment editing
|
|
981
|
+
- Existing attachments can be removed
|
|
982
|
+
- Validation errors remain visible inside the editor
|
|
983
|
+
- Successful updates can refresh the flash message immediately
|
|
984
|
+
- Existing resource layout remains in place while editing
|
|
985
|
+
- Multiple fields can be added in one generator run
|
|
986
|
+
- Additional fields can be added in later generator runs
|
|
987
|
+
- Safe repeated generator runs
|
|
988
|
+
|
|
989
|
+
In-place editing also integrates with b4um authentication.
|
|
990
|
+
|
|
991
|
+
Without authentication, generated in-place fields are editable.
|
|
992
|
+
When b4um authentication is installed, editing is restricted to
|
|
993
|
+
logged-in users and the affected controller actions are protected.
|
|
994
|
+
|
|
995
|
+
Authentication can be installed before or after in-place editing.
|
|
996
|
+
The generators update the integration automatically in either order.
|
|
997
|
+
|
|
998
|
+
|
|
908
999
|
TRIX / RICH TEXT
|
|
909
1000
|
|
|
910
1001
|
bin/rails generate b4um:trix MODEL ATTRIBUTE
|
|
@@ -915,21 +1006,27 @@ module B4um
|
|
|
915
1006
|
|
|
916
1007
|
bin/rails generate b4um:trix Article content
|
|
917
1008
|
|
|
918
|
-
The model and form must already exist.
|
|
1009
|
+
The model and b4um form must already exist. The selected
|
|
1010
|
+
attribute does not need to be present in the form yet.
|
|
919
1011
|
|
|
920
1012
|
The generator adds:
|
|
921
1013
|
|
|
922
1014
|
has_rich_text :content
|
|
923
1015
|
|
|
924
|
-
and replaces the selected form field with a rich
|
|
1016
|
+
and adds or replaces the selected form field with a rich
|
|
1017
|
+
text editor:
|
|
925
1018
|
|
|
926
1019
|
form.rich_text_area :content
|
|
927
1020
|
|
|
1021
|
+
The corresponding b4um resource field is also added when
|
|
1022
|
+
it does not already exist.
|
|
1023
|
+
|
|
928
1024
|
Trix / Rich Text features:
|
|
929
1025
|
|
|
930
1026
|
- Installs Action Text automatically when necessary
|
|
931
1027
|
- Adds the rich text association to the model
|
|
932
|
-
-
|
|
1028
|
+
- Adds or replaces the selected form field
|
|
1029
|
+
- Adds the rich text field to the b4um resource when necessary
|
|
933
1030
|
- Preserves compact Bento text using plain text
|
|
934
1031
|
- Image lightbox for images inside rich text
|
|
935
1032
|
- Previous / next image navigation
|