b4um_generators 0.3.0 → 0.4.2

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.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -2
  3. data/CHANGELOG.md +72 -0
  4. data/README.de.md +338 -4
  5. data/README.md +330 -5
  6. data/lib/b4um_generators/version.rb +1 -1
  7. data/lib/generators/b4um/admin/admin_generator.rb +725 -0
  8. data/lib/generators/b4um/admin/templates/add_admin_fields_migration.rb.tt +10 -0
  9. data/lib/generators/b4um/admin/templates/admin_base_controller.rb.tt +5 -0
  10. data/lib/generators/b4um/admin/templates/admin_dashboard.html.erb.tt +19 -0
  11. data/lib/generators/b4um/admin/templates/admin_dashboard_controller.rb.tt +6 -0
  12. data/lib/generators/b4um/admin/templates/admin_users_controller.rb.tt +70 -0
  13. data/lib/generators/b4um/admin/templates/admin_users_index.html.erb.tt +110 -0
  14. data/lib/generators/b4um/admin/templates/b4um_admin.rake.tt +106 -0
  15. data/lib/generators/b4um/authentication/authentication_generator.rb +436 -23
  16. data/lib/generators/b4um/comments/comments_generator.rb +39 -9
  17. data/lib/generators/b4um/guest/guest_generator.rb +673 -0
  18. data/lib/generators/b4um/guest/templates/add_guest_fields_migration.rb.tt +12 -0
  19. data/lib/generators/b4um/guest/templates/b4um_guests.rake.tt +12 -0
  20. data/lib/generators/b4um/guest/templates/edit.html.erb.tt +156 -0
  21. data/lib/generators/b4um/guest/templates/guest_expiration_warning.html.erb.tt +12 -0
  22. data/lib/generators/b4um/guest/templates/guests_controller.rb.tt +88 -0
  23. data/lib/generators/b4um/guest/templates/new.html.erb.tt +136 -0
  24. data/lib/generators/b4um/help/help_generator.rb +162 -0
  25. data/lib/generators/b4um/in_place/in_place_generator.rb +132 -7
  26. data/lib/generators/b4um/readable/readable_generator.rb +8 -5
  27. data/lib/generators/b4um/scaffold/scaffold_generator.rb +213 -73
  28. data/lib/generators/b4um/scaffold/templates/_form.html.erb.tt +18 -14
  29. data/lib/generators/b4um/sortable/sortable_generator.rb +104 -36
  30. metadata +16 -1
@@ -15,6 +15,8 @@
15
15
  <%% end %>
16
16
 
17
17
  <% attributes.each do |attribute| -%>
18
+ <% required = required_fields.include?(attribute.name) -%>
19
+ <% label = attribute.name.humanize + (required ? " *" : "") -%>
18
20
  <% if attribute.name == "password_digest" -%>
19
21
  <div class="form-field">
20
22
  <%%= form.password_field :password,
@@ -35,7 +37,7 @@
35
37
  <%%= form.email_field :<%= attribute.name %>,
36
38
  class: "form-input",
37
39
  placeholder: " " %>
38
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
40
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
39
41
  </div>
40
42
 
41
43
  <% elsif attribute.name.match?(/(?:^|_)(?:password|password_confirmation)(?:_|$)/) -%>
@@ -43,7 +45,7 @@
43
45
  <%%= form.password_field :<%= attribute.name %>,
44
46
  class: "form-input",
45
47
  placeholder: " " %>
46
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
48
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
47
49
  </div>
48
50
 
49
51
  <% elsif attribute.name.match?(/(?:^|_)(?:phone|telephone|mobile)(?:_|$)/) -%>
@@ -51,7 +53,7 @@
51
53
  <%%= form.telephone_field :<%= attribute.name %>,
52
54
  class: "form-input",
53
55
  placeholder: " " %>
54
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
56
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
55
57
  </div>
56
58
 
57
59
  <% elsif attribute.name.match?(/(?:^|_)(?:url|website|homepage)(?:_|$)/) -%>
@@ -59,12 +61,12 @@
59
61
  <%%= form.url_field :<%= attribute.name %>,
60
62
  class: "form-input",
61
63
  placeholder: " " %>
62
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
64
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
63
65
  </div>
64
66
 
65
67
  <% elsif select_field?(attribute.name) -%>
66
68
  <div class="form-field form-field--select">
67
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
69
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
68
70
 
69
71
  <%%= form.select :<%= attribute.name %>,
70
72
  <%= select_configuration[:values].inspect %>.map { |choice|
@@ -76,7 +78,7 @@
76
78
 
77
79
  <% elsif radio_field?(attribute.name) -%>
78
80
  <div class="form-field form-field--radio">
79
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
81
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
80
82
 
81
83
  <div class="form-radio-options">
82
84
  <%% <%= radio_configuration[:values].inspect %>.each do |choice| %>
@@ -94,7 +96,7 @@
94
96
  <% elsif attribute.type == :boolean -%>
95
97
  <div class="form-field form-field--checkbox">
96
98
  <%%= form.check_box :<%= attribute.name %>, class: "form-checkbox" %>
97
- <%%= form.label :<%= attribute.name %>, class: "form-label form-label--checkbox" %>
99
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label form-label--checkbox" %>
98
100
  </div>
99
101
 
100
102
  <% elsif attribute.type == :text -%>
@@ -102,7 +104,7 @@
102
104
  <%%= form.text_area :<%= attribute.name %>,
103
105
  class: "form-textarea",
104
106
  placeholder: " " %>
105
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
107
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
106
108
  </div>
107
109
 
108
110
  <% elsif attribute.type == :integer -%>
@@ -111,7 +113,7 @@
111
113
  class: "form-input",
112
114
  placeholder: " ",
113
115
  step: 1 %>
114
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
116
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
115
117
  </div>
116
118
 
117
119
  <% elsif [:float, :decimal].include?(attribute.type) -%>
@@ -120,7 +122,7 @@
120
122
  class: "form-input",
121
123
  placeholder: " ",
122
124
  step: "any" %>
123
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
125
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
124
126
  </div>
125
127
 
126
128
  <% elsif attribute.type == :date -%>
@@ -128,7 +130,7 @@
128
130
  <%%= form.date_field :<%= attribute.name %>,
129
131
  class: "form-input",
130
132
  placeholder: " " %>
131
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
133
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
132
134
  </div>
133
135
 
134
136
  <% elsif [:datetime, :timestamp].include?(attribute.type) -%>
@@ -136,7 +138,7 @@
136
138
  <%%= form.datetime_local_field :<%= attribute.name %>,
137
139
  class: "form-input",
138
140
  placeholder: " " %>
139
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
141
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
140
142
  </div>
141
143
 
142
144
  <% elsif attribute.type == :time -%>
@@ -144,7 +146,7 @@
144
146
  <%%= form.time_field :<%= attribute.name %>,
145
147
  class: "form-input",
146
148
  placeholder: " " %>
147
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
149
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
148
150
  </div>
149
151
 
150
152
  <% elsif attribute.type == :attachment -%>
@@ -153,6 +155,7 @@
153
155
 
154
156
  <div class="form-file-control">
155
157
  <%%= form.label :<%= attribute.name %>,
158
+ "<%= label %>",
156
159
  class: "form-file-label" %>
157
160
 
158
161
  <%%= form.file_field :<%= attribute.name %>,
@@ -189,6 +192,7 @@
189
192
 
190
193
  <div class="form-file-control">
191
194
  <%%= form.label :<%= attribute.name %>,
195
+ "<%= label %>",
192
196
  class: "form-file-label" %>
193
197
 
194
198
  <%% <%= singular_table_name %>.<%= attribute.name %>.each do |image| %>
@@ -246,7 +250,7 @@
246
250
  <%%= form.<%= attribute.field_type %> :<%= attribute.name %>,
247
251
  class: "form-input",
248
252
  placeholder: " " %>
249
- <%%= form.label :<%= attribute.name %>, class: "form-label" %>
253
+ <%%= form.label :<%= attribute.name %>, "<%= label %>", class: "form-label" %>
250
254
  </div>
251
255
  <% end -%>
252
256
  <% end -%>
@@ -51,30 +51,80 @@ module B4um
51
51
  )
52
52
  end
53
53
 
54
+ def update_fixtures
55
+ return unless File.exist?(fixture_path)
56
+
57
+ fixtures = File.read(fixture_path)
58
+ position = 0
59
+
60
+ updated_fixtures = fixtures.gsub(
61
+ /^([^\s#][^:\n]*:\s*\n)((?:^[ \t]+.*\n?)*)/
62
+ ) do
63
+ fixture_header = Regexp.last_match(1)
64
+ fixture_body = Regexp.last_match(2)
65
+
66
+ next "#{fixture_header}#{fixture_body}" if fixture_header.start_with?("_")
67
+
68
+ position += 1
69
+
70
+ if fixture_body.match?(/^[ \t]+position:\s+/)
71
+ fixture_body = fixture_body.sub(
72
+ /^[ \t]+position:\s+.*$/,
73
+ " position: #{position}"
74
+ )
75
+
76
+ "#{fixture_header}#{fixture_body}"
77
+ else
78
+ "#{fixture_header} position: #{position}\n#{fixture_body}"
79
+ end
80
+ end
81
+
82
+ return if updated_fixtures == fixtures
83
+
84
+ File.write(fixture_path, updated_fixtures)
85
+
86
+ say_status(
87
+ :fixture,
88
+ "#{plural_table_name}.yml now includes sortable positions",
89
+ :green
90
+ )
91
+ end
92
+
54
93
  def update_model
55
94
  model_content = File.read(model_path)
56
95
 
57
- return if model_content.include?("before_create :b4um_set_sortable_position")
96
+ return if model_content.include?(
97
+ "before_create :b4um_set_sortable_position"
98
+ )
58
99
 
59
- inject_into_class(
60
- model_path,
61
- class_name,
62
- <<~RUBY.indent(2)
63
- before_create :b4um_set_sortable_position
64
- after_destroy :b4um_compact_sortable_positions
100
+ existing_model_body = model_content
101
+ .lines[1...-1]
102
+ .to_a
103
+ .any? { |line| line.match?(/\S/) }
65
104
 
66
- def b4um_set_sortable_position
67
- return if position.present?
105
+ sortable_model_code = <<~RUBY.indent(2)
106
+ before_create :b4um_set_sortable_position
107
+ after_destroy :b4um_compact_sortable_positions
68
108
 
69
- self.position = self.class.maximum(:position).to_i + 1
70
- end
109
+ def b4um_set_sortable_position
110
+ return if position.present?
71
111
 
72
- def b4um_compact_sortable_positions
73
- self.class
74
- .where("position > ?", position)
75
- .update_all("position = position - 1")
76
- end
77
- RUBY
112
+ self.position = self.class.maximum(:position).to_i + 1
113
+ end
114
+
115
+ def b4um_compact_sortable_positions
116
+ self.class
117
+ .where("position > ?", position)
118
+ .update_all("position = position - 1")
119
+ end
120
+ RUBY
121
+
122
+ sortable_model_code << "\n" if existing_model_body
123
+
124
+ inject_into_class(
125
+ model_path,
126
+ class_name,
127
+ sortable_model_code
78
128
  )
79
129
 
80
130
  say_status(
@@ -217,6 +267,14 @@ module B4um
217
267
  )
218
268
  end
219
269
 
270
+ def fixture_path
271
+ File.join(
272
+ destination_root,
273
+ "test/fixtures",
274
+ "#{plural_table_name}.yml"
275
+ )
276
+ end
277
+
220
278
  def model_path
221
279
  File.join(
222
280
  destination_root,
@@ -322,15 +380,16 @@ module B4um
322
380
 
323
381
  head :no_content
324
382
  end
325
-
326
383
  RUBY
327
384
 
385
+ action = action.rstrip
386
+
328
387
  private_marker = "\n private\n"
329
388
 
330
389
  if controller_content.include?(private_marker)
331
390
  insert_into_file(
332
391
  controller_path,
333
- action,
392
+ "\n#{action}\n",
334
393
  before: private_marker
335
394
  )
336
395
  else
@@ -341,10 +400,10 @@ module B4um
341
400
  "Could not find the end of app/controllers/#{plural_table_name}_controller.rb"
342
401
  end
343
402
 
344
- insert_into_file(
403
+ gsub_file(
345
404
  controller_path,
346
- "\n#{action}",
347
- before: controller_end
405
+ controller_end,
406
+ "\n\n#{action}\nend\n"
348
407
  )
349
408
  end
350
409
  end
@@ -354,7 +413,7 @@ module B4um
354
413
  return if controller_content.include?("if request.get?")
355
414
 
356
415
  sort_action =
357
- /^(\s*)def sort\s*$/
416
+ /^([ \t]*)def sort[ \t]*$/
358
417
 
359
418
  unless controller_content.match?(sort_action)
360
419
  raise Thor::Error,
@@ -365,15 +424,15 @@ module B4um
365
424
  controller_path,
366
425
  sort_action
367
426
  ) do |match|
368
- indentation = match[/\A\s*/]
369
-
370
- <<~RUBY.chomp
371
- #{match}
372
- #{indentation} if request.get?
373
- #{indentation} @#{plural_table_name} = #{class_name}.order(:position, :id)
374
- #{indentation} return
375
- #{indentation} end
376
- RUBY
427
+ indentation = match[/\A[ \t]*/]
428
+
429
+ [
430
+ match,
431
+ "#{indentation} if request.get?",
432
+ "#{indentation} @#{plural_table_name} = #{class_name}.order(:position, :id)",
433
+ "#{indentation} return",
434
+ "#{indentation} end"
435
+ ].join("\n")
377
436
  end
378
437
  end
379
438
 
@@ -510,19 +569,28 @@ module B4um
510
569
  end
511
570
 
512
571
  def schema_contains_position?
513
- schema_path = File.join(destination_root, "db/schema.rb")
572
+ schema_path = File.join(
573
+ destination_root,
574
+ "db/schema.rb"
575
+ )
514
576
 
515
577
  return false unless File.exist?(schema_path)
516
578
 
517
579
  schema = File.read(schema_path)
518
580
 
519
581
  table_pattern = /
520
- create_table\s+"#{Regexp.escape(plural_table_name)}".*?^ end
582
+ ^[ \t]*create_table\s+"#{Regexp.escape(plural_table_name)}".*?\n
583
+ (?<table_body>.*?)
584
+ ^[ \t]{2}end\s*$
521
585
  /mx
522
586
 
523
- table = schema[table_pattern]
587
+ match = schema.match(table_pattern)
524
588
 
525
- table&.match?(/t\.integer\s+"position"/) || false
589
+ return false unless match
590
+
591
+ match[:table_body].match?(
592
+ /^[ \t]+t\.integer\s+"position"/
593
+ )
526
594
  end
527
595
  end
528
596
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: b4um_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Baum
@@ -49,6 +49,14 @@ files:
49
49
  - bin/setup
50
50
  - lib/b4um_generators.rb
51
51
  - lib/b4um_generators/version.rb
52
+ - lib/generators/b4um/admin/admin_generator.rb
53
+ - lib/generators/b4um/admin/templates/add_admin_fields_migration.rb.tt
54
+ - lib/generators/b4um/admin/templates/admin_base_controller.rb.tt
55
+ - lib/generators/b4um/admin/templates/admin_dashboard.html.erb.tt
56
+ - lib/generators/b4um/admin/templates/admin_dashboard_controller.rb.tt
57
+ - lib/generators/b4um/admin/templates/admin_users_controller.rb.tt
58
+ - lib/generators/b4um/admin/templates/admin_users_index.html.erb.tt
59
+ - lib/generators/b4um/admin/templates/b4um_admin.rake.tt
52
60
  - lib/generators/b4um/attachment/attachment_generator.rb
53
61
  - lib/generators/b4um/authentication/authentication_generator.rb
54
62
  - lib/generators/b4um/authentication/templates/new.html.erb.tt
@@ -64,6 +72,13 @@ files:
64
72
  - lib/generators/b4um/comments/templates/comments_controller.rb.tt
65
73
  - lib/generators/b4um/comments/templates/create_comments.rb.tt
66
74
  - lib/generators/b4um/controller/controller_generator.rb
75
+ - lib/generators/b4um/guest/guest_generator.rb
76
+ - lib/generators/b4um/guest/templates/add_guest_fields_migration.rb.tt
77
+ - lib/generators/b4um/guest/templates/b4um_guests.rake.tt
78
+ - lib/generators/b4um/guest/templates/edit.html.erb.tt
79
+ - lib/generators/b4um/guest/templates/guest_expiration_warning.html.erb.tt
80
+ - lib/generators/b4um/guest/templates/guests_controller.rb.tt
81
+ - lib/generators/b4um/guest/templates/new.html.erb.tt
67
82
  - lib/generators/b4um/help/help_generator.rb
68
83
  - lib/generators/b4um/in_place/in_place_generator.rb
69
84
  - lib/generators/b4um/in_place/templates/_flash.html.erb