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
|
@@ -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)
|
|
@@ -45,6 +45,21 @@ module B4um
|
|
|
45
45
|
)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
def update_index_layout
|
|
49
|
+
return unless File.exist?(index_path)
|
|
50
|
+
|
|
51
|
+
index = File.read(index_path)
|
|
52
|
+
|
|
53
|
+
updated_index = index.sub(
|
|
54
|
+
/render\s+["'](?:bento|table|list|alternating)["']/,
|
|
55
|
+
'render "bento"'
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
return if updated_index == index
|
|
59
|
+
|
|
60
|
+
File.write(index_path, updated_index)
|
|
61
|
+
end
|
|
62
|
+
|
|
48
63
|
private
|
|
49
64
|
|
|
50
65
|
def model_path
|
|
@@ -55,6 +70,15 @@ module B4um
|
|
|
55
70
|
)
|
|
56
71
|
end
|
|
57
72
|
|
|
73
|
+
def index_path
|
|
74
|
+
File.join(
|
|
75
|
+
destination_root,
|
|
76
|
+
"app/views",
|
|
77
|
+
plural_table_name,
|
|
78
|
+
"index.html.erb"
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
|
|
58
82
|
def resource_partial_path
|
|
59
83
|
File.join(
|
|
60
84
|
destination_root,
|
|
@@ -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:
|
|
@@ -728,15 +758,39 @@ module B4um
|
|
|
728
758
|
|
|
729
759
|
TABLE
|
|
730
760
|
|
|
731
|
-
bin/rails generate b4um:table MODEL FIELDS
|
|
761
|
+
bin/rails generate b4um:table MODEL [FIELDS]
|
|
732
762
|
|
|
733
763
|
Generates a reusable b4um table partial for an existing model.
|
|
734
764
|
|
|
735
|
-
|
|
765
|
+
The model must already exist.
|
|
736
766
|
|
|
737
|
-
|
|
767
|
+
Fields are optional. If no fields are supplied, the generator
|
|
768
|
+
automatically detects:
|
|
738
769
|
|
|
739
|
-
|
|
770
|
+
- Database fields
|
|
771
|
+
- Action Text rich text fields
|
|
772
|
+
- Active Storage single attachments
|
|
773
|
+
- Active Storage multiple attachments
|
|
774
|
+
|
|
775
|
+
id, created_at and updated_at are excluded automatically.
|
|
776
|
+
|
|
777
|
+
Recommended:
|
|
778
|
+
|
|
779
|
+
bin/rails generate b4um:table Product
|
|
780
|
+
|
|
781
|
+
Fields can also be specified explicitly:
|
|
782
|
+
|
|
783
|
+
bin/rails generate b4um:table Product name price status
|
|
784
|
+
|
|
785
|
+
Select fields can be configured with --select:
|
|
786
|
+
|
|
787
|
+
bin/rails generate b4um:table Product --select='status:active=Active,inactive=Inactive'
|
|
788
|
+
|
|
789
|
+
Radio fields can be configured with --radio:
|
|
790
|
+
|
|
791
|
+
bin/rails generate b4um:table Product --radio='condition:new=New,used=Used'
|
|
792
|
+
|
|
793
|
+
The configured database values are displayed using their labels.
|
|
740
794
|
|
|
741
795
|
The generated partial is created at:
|
|
742
796
|
|
|
@@ -744,18 +798,34 @@ module B4um
|
|
|
744
798
|
|
|
745
799
|
Table features:
|
|
746
800
|
|
|
801
|
+
- Automatic field detection from the existing model
|
|
747
802
|
- Responsive b4um table component
|
|
748
|
-
-
|
|
803
|
+
- Model-aware field types
|
|
749
804
|
- Text fields shortened to 100 characters
|
|
750
|
-
-
|
|
805
|
+
- Decimal values formatted with two decimal places
|
|
806
|
+
- Status fields displayed as b4um badges
|
|
807
|
+
- Select and radio labels
|
|
808
|
+
- Action Text / Trix content
|
|
809
|
+
- Lightbox for images embedded in rich text
|
|
810
|
+
- Trix image captions in the lightbox
|
|
811
|
+
- Active Storage single images
|
|
812
|
+
- Active Storage multiple image galleries
|
|
813
|
+
- Image thumbnails and lightbox navigation
|
|
814
|
+
- Mouse and touch drag / swipe
|
|
751
815
|
- Actions column with a Show button
|
|
816
|
+
- Empty-state handling
|
|
752
817
|
- No migrations, routes or controllers are generated
|
|
753
818
|
|
|
754
|
-
|
|
819
|
+
Running the Table generator automatically switches an existing
|
|
820
|
+
b4um index view to the table partial:
|
|
755
821
|
|
|
756
822
|
<%= render "table", products: @products %>
|
|
757
823
|
|
|
758
|
-
|
|
824
|
+
Running b4um:bento later switches the index back to the Bento
|
|
825
|
+
partial. This also applies to the grid, list and alternating
|
|
826
|
+
Bento layouts.
|
|
827
|
+
|
|
828
|
+
The table partial uses a local collection, so it can also be
|
|
759
829
|
reused with another collection:
|
|
760
830
|
|
|
761
831
|
<%= render "products/table", products: @featured_products %>
|
|
@@ -905,6 +975,67 @@ module B4um
|
|
|
905
975
|
the generator to stop with an error.
|
|
906
976
|
|
|
907
977
|
|
|
978
|
+
IN-PLACE EDITING
|
|
979
|
+
|
|
980
|
+
bin/rails generate b4um:in_place MODEL FIELD [FIELD ...]
|
|
981
|
+
|
|
982
|
+
Adds in-place editing to fields of an existing b4um resource.
|
|
983
|
+
|
|
984
|
+
Examples:
|
|
985
|
+
|
|
986
|
+
bin/rails generate b4um:in_place Product name
|
|
987
|
+
bin/rails generate b4um:in_place Product name price status
|
|
988
|
+
|
|
989
|
+
The model, controller and resource routes must already exist.
|
|
990
|
+
|
|
991
|
+
The generator detects the field type automatically and creates
|
|
992
|
+
the appropriate in-place editor.
|
|
993
|
+
|
|
994
|
+
Supported fields include:
|
|
995
|
+
|
|
996
|
+
- String and text fields
|
|
997
|
+
- Numeric and decimal fields
|
|
998
|
+
- Boolean fields
|
|
999
|
+
- Action Text rich text fields
|
|
1000
|
+
- Active Storage single image attachments
|
|
1001
|
+
- Active Storage multiple image attachments
|
|
1002
|
+
|
|
1003
|
+
Select fields can be configured with --select:
|
|
1004
|
+
|
|
1005
|
+
bin/rails generate b4um:in_place Product status --select='status:Active=Aktiv,Inactive=Inaktiv'
|
|
1006
|
+
|
|
1007
|
+
Radio buttons can be configured with --radio:
|
|
1008
|
+
|
|
1009
|
+
bin/rails generate b4um:in_place Product condition --radio='condition:new=Neu,used=Gebraucht,refurbished=Generalüberholt'
|
|
1010
|
+
|
|
1011
|
+
The value before "=" is stored in the database.
|
|
1012
|
+
The optional value after "=" is used as the displayed label.
|
|
1013
|
+
|
|
1014
|
+
In-place editing features:
|
|
1015
|
+
|
|
1016
|
+
- Turbo Frame based editing without an additional in-place gem
|
|
1017
|
+
- Click a displayed field to edit it in place
|
|
1018
|
+
- Text and rich text fields save when clicking outside
|
|
1019
|
+
- Select, radio, and boolean fields save immediately
|
|
1020
|
+
- Single and multiple image attachment editing
|
|
1021
|
+
- Existing attachments can be removed
|
|
1022
|
+
- Validation errors remain visible inside the editor
|
|
1023
|
+
- Successful updates can refresh the flash message immediately
|
|
1024
|
+
- Existing resource layout remains in place while editing
|
|
1025
|
+
- Multiple fields can be added in one generator run
|
|
1026
|
+
- Additional fields can be added in later generator runs
|
|
1027
|
+
- Safe repeated generator runs
|
|
1028
|
+
|
|
1029
|
+
In-place editing also integrates with b4um authentication.
|
|
1030
|
+
|
|
1031
|
+
Without authentication, generated in-place fields are editable.
|
|
1032
|
+
When b4um authentication is installed, editing is restricted to
|
|
1033
|
+
logged-in users and the affected controller actions are protected.
|
|
1034
|
+
|
|
1035
|
+
Authentication can be installed before or after in-place editing.
|
|
1036
|
+
The generators update the integration automatically in either order.
|
|
1037
|
+
|
|
1038
|
+
|
|
908
1039
|
TRIX / RICH TEXT
|
|
909
1040
|
|
|
910
1041
|
bin/rails generate b4um:trix MODEL ATTRIBUTE
|
|
@@ -915,21 +1046,27 @@ module B4um
|
|
|
915
1046
|
|
|
916
1047
|
bin/rails generate b4um:trix Article content
|
|
917
1048
|
|
|
918
|
-
The model and form must already exist.
|
|
1049
|
+
The model and b4um form must already exist. The selected
|
|
1050
|
+
attribute does not need to be present in the form yet.
|
|
919
1051
|
|
|
920
1052
|
The generator adds:
|
|
921
1053
|
|
|
922
1054
|
has_rich_text :content
|
|
923
1055
|
|
|
924
|
-
and replaces the selected form field with a rich
|
|
1056
|
+
and adds or replaces the selected form field with a rich
|
|
1057
|
+
text editor:
|
|
925
1058
|
|
|
926
1059
|
form.rich_text_area :content
|
|
927
1060
|
|
|
1061
|
+
The corresponding b4um resource field is also added when
|
|
1062
|
+
it does not already exist.
|
|
1063
|
+
|
|
928
1064
|
Trix / Rich Text features:
|
|
929
1065
|
|
|
930
1066
|
- Installs Action Text automatically when necessary
|
|
931
1067
|
- Adds the rich text association to the model
|
|
932
|
-
-
|
|
1068
|
+
- Adds or replaces the selected form field
|
|
1069
|
+
- Adds the rich text field to the b4um resource when necessary
|
|
933
1070
|
- Preserves compact Bento text using plain text
|
|
934
1071
|
- Image lightbox for images inside rich text
|
|
935
1072
|
- Previous / next image navigation
|