hot-glue 0.6.15 → 0.6.17

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.
@@ -2,13 +2,7 @@ class RelatedSetField < Field
2
2
 
3
3
  attr_accessor :assoc_name, :assoc_class, :assoc
4
4
 
5
- def initialize( class_name: , default_boolean_display:, display_as: ,
6
- name: , singular: , plural:,
7
- alt_lookup: ,
8
- update_show_only: ,
9
- hawk_keys: , auth: , sample_file_path:, ownership_field: ,
10
- attachment_data: nil , layout_strategy: , form_placeholder_labels: nil,
11
- form_labels_position:, modify_as: , self_auth: , namespace:, pundit:)
5
+ def initialize( scaffold: , name: )
12
6
  super
13
7
 
14
8
  @related_set_model = eval("#{class_name}.reflect_on_association(:#{name})")
@@ -37,12 +31,13 @@ class RelatedSetField < Field
37
31
 
38
32
  def form_field_output
39
33
  disabled_syntax = +""
34
+
40
35
  if pundit
41
36
  disabled_syntax << ", {disabled: ! #{class_name}Policy.new(#{auth}, @#{singular}).role_ids_able?}"
42
37
  end
43
38
  " <%= f.collection_check_boxes :#{association_ids_method}, #{association_class_name}.all, :id, :label, {}#{disabled_syntax} do |m| %>
44
- <%= m.check_box %> <%= m.label %><br />
45
- <% end %>"
39
+ <%= m.check_box %> <%= m.label %><br />
40
+ <% end %>"
46
41
  end
47
42
 
48
43
  def association_ids_method
@@ -40,7 +40,8 @@ module HotGlue
40
40
  layout_object = {
41
41
  columns: {
42
42
  size_each: smart_layout ? bootstrap_column_width : (specified_grouping_mode ? nil : 1),
43
- container: [] # array of arrays
43
+ container: [] , # array of arrays,
44
+ bootstrap_column_width: []
44
45
  },
45
46
  portals: {
46
47
 
@@ -99,7 +100,7 @@ module HotGlue
99
100
  }
100
101
  layout_object[:columns][:container] = (0..available_columns-1).collect { |x| [columns[x]] }
101
102
  layout_object[:columns][:container].reject!{|x| x == [nil]}
102
- layout_object[:columns][:size_each] = bootstrap_column_width
103
+ # layout_object[:columns][:size_each] = bootstrap_column_width
103
104
  end
104
105
  elsif ! specified_grouping_mode
105
106
  # not smart and no specified grouping
@@ -117,22 +118,33 @@ module HotGlue
117
118
  # input control
118
119
 
119
120
  user_layout_columns = @include_setting.split(":")
120
- size_each = (bootstrap_columns / user_layout_columns.count).floor # this is the bootstrap size
121
121
 
122
- layout_object[:columns][:size_each] = size_each
122
+ extra_columns = available_columns - user_layout_columns.size
123
+ # size_each = (bootstrap_columns / user_layout_columns.count).floor # this is the bootstrap size
124
+ #
125
+ # layout_object[:columns][:size_each] = size_each
123
126
 
124
- if user_layout_columns.size > available_columns
125
- raise "Your include statement #{@include_setting } has #{user_layout_columns.size} columns, but I can only construct up to #{available_columns}"
126
- end
127
+ # if user_layout_columns.size > available_columns
128
+ # raise "Your include statement #{@include_setting } has #{user_layout_columns.size} columns, but I can only construct up to #{available_columns}"
129
+ # end
127
130
  user_layout_columns.each_with_index do |column,i|
128
131
  layout_object[:columns][:container][i] = column.split(",").collect(&:to_sym)
132
+
133
+ default_col_width = 1
134
+ if extra_columns > 0
135
+ default_col_width += 1
136
+ extra_columns -= 1
137
+ end
138
+ layout_object[:columns][:bootstrap_column_width][i] = default_col_width
129
139
  end
130
140
 
131
141
  if user_layout_columns.size < layout_object[:columns][:container].size
132
142
  layout_object[:columns][:container].reject!{|x| x == []}
133
143
  end
144
+
134
145
  end
135
146
 
147
+
136
148
  puts "*** constructed smart layout columns #{layout_object.inspect}"
137
149
  layout_object
138
150
  end
@@ -17,20 +17,20 @@ class LayoutStrategy::Bootstrap < LayoutStrategy::Base
17
17
  end
18
18
 
19
19
 
20
- def column_classes_for_form_fields
21
- "col-md-#{builder.layout_object[:columns][:size_each]}"
20
+ def column_classes_for_form_fields(size = nil)
21
+ "col-md-#{size || builder.layout_object[:columns][:size_each]}"
22
22
  end
23
23
 
24
- def column_classes_for_column_headings
25
- column_classes_for_line_fields
24
+ def column_classes_for_column_headings(size = nil)
25
+ column_classes_for_line_fields(size)
26
26
  end
27
27
 
28
28
  def container_name
29
29
  "container"
30
30
  end
31
31
 
32
- def column_classes_for_line_fields
33
- "col-sm-#{builder.layout_object[:columns][:size_each]}"
32
+ def column_classes_for_line_fields(size = nil)
33
+ "col-sm-#{size || builder.layout_object[:columns][:size_each]}"
34
34
  end
35
35
 
36
36
  def column_width
@@ -39,18 +39,18 @@ class LayoutStrategy::HotGlue < LayoutStrategy::Base
39
39
  "scaffold-row"
40
40
  end
41
41
 
42
- def column_classes_for_form_fields
42
+ def column_classes_for_form_fields(size = nil)
43
43
  "scaffold-cell"
44
44
  end
45
45
 
46
46
  def row_heading_classes
47
47
  "scaffold-heading-row"
48
48
  end
49
- def column_classes_for_line_fields
49
+ def column_classes_for_line_fields(size = nil)
50
50
  "scaffold-cell"
51
51
  end
52
52
 
53
- def column_classes_for_column_headings
53
+ def column_classes_for_column_headings(size = nil)
54
54
  "scaffold-cell"
55
55
  end
56
56
 
@@ -6,9 +6,9 @@ class LayoutStrategy::Tailwind < LayoutStrategy::Base
6
6
  def button_style ; ""; end
7
7
  def column_headings_col_style; "" ; end
8
8
  def column_width; ""; end
9
- def column_classes_for_line_fields; ""; end
10
- def column_classes_for_form_fields; ""; end
11
- def column_classes_for_column_headings; ""; end
9
+ def column_classes_for_line_fields(size = nil); ""; end
10
+ def column_classes_for_form_fields(size = nil); ""; end
11
+ def column_classes_for_column_headings(size = nil); ""; end
12
12
  def col_width; 100; end
13
13
  def container_name; ""; end
14
14
  def downnest_style ; ""; end
@@ -10,7 +10,8 @@ module HotGlue
10
10
  :form_placeholder_labels, :hawk_keys, :update_show_only,
11
11
  :attachments, :show_only, :columns_map, :pundit, :related_sets,
12
12
  :search, :search_fields, :search_query_fields, :search_position,
13
- :form_path, :layout_object, :search_clear_button, :search_autosearch
13
+ :form_path, :layout_object, :search_clear_button, :search_autosearch,
14
+ :stimmify, :stimmify_camel, :hidden
14
15
 
15
16
 
16
17
  def initialize(singular:, singular_class: ,
@@ -22,7 +23,7 @@ module HotGlue
22
23
  update_show_only:, attachments: , columns_map:, pundit:, related_sets:,
23
24
  search:, search_fields:, search_query_fields: , search_position:,
24
25
  search_clear_button:, search_autosearch:, layout_object:,
25
- form_path: )
26
+ form_path: , stimmify: , stimmify_camel:, hidden: )
26
27
 
27
28
 
28
29
  @form_path = form_path
@@ -31,6 +32,9 @@ module HotGlue
31
32
  @search_by_query = search_query_fields
32
33
  @search_position = search_position
33
34
  @layout_object = layout_object
35
+ @stimmify = stimmify
36
+ @stimmify_camel = stimmify_camel
37
+ @hidden = hidden
34
38
 
35
39
  @singular = singular
36
40
  @singular_class = singular_class
@@ -76,13 +80,14 @@ module HotGlue
76
80
  }.join("\n")
77
81
  end
78
82
 
79
- def list_column_headings(col_identifier: ,
80
- column_width:, singular: )
83
+ def list_column_headings(column_width:, singular: )
81
84
  col_style = @layout_strategy.column_headings_col_style
82
85
 
83
86
  columns = layout_object[:columns][:container]
84
- result = columns.map{ |column|
85
- "<div class='#{col_identifier} hg-heading-row heading--#{singular}--#{column.join("-")}' " + col_style + ">" +
87
+ result = columns.map.with_index{ |column,i|
88
+
89
+ size = layout_object[:columns][:bootstrap_column_width][i]
90
+ "<div class='#{layout_strategy.column_classes_for_column_headings(size)} hg-heading-row heading--#{singular}--#{column.join("-")}' " + col_style + ">" +
86
91
  column.map(&:to_s).map{|col_name| "#{col_name.humanize}"}.join("<br />") + "</div>"
87
92
  }.join("\n")
88
93
  return result
@@ -95,7 +100,6 @@ module HotGlue
95
100
 
96
101
  def search_input_area
97
102
  columns = layout_object[:columns][:container]
98
- column_classes = layout_strategy.column_classes_for_form_fields
99
103
 
100
104
  res =+ "<\%= form_with url: #{form_path}, method: :get, html: {'data-turbo-action': 'advance', 'data-controller': 'search-form'} do |f| %>"
101
105
  res << "<div class=\"#{@layout_strategy.row_classes} search--#{@plural}\">"
@@ -116,12 +120,13 @@ module HotGlue
116
120
  end
117
121
  }.compact.join("\n")
118
122
 
119
- " <div class='#{column_classes} search-cell--#{singular}--#{column.join("-")}' >" +
123
+ size = layout_object[:columns][:bootstrap_column_width][columns.index(column)]
124
+ " <div class='#{layout_strategy.column_classes_for_form_fields(size)} search-cell--#{singular}--#{column.join("-")}' >" +
120
125
  cols_result + "</div>"
121
126
 
122
127
  }.join("\n")
123
128
  res << "</div>"
124
- res << "<div class='#{column_classes}'>"
129
+ res << "<div class='#{layout_strategy.column_classes_for_form_fields(nil)}'>"
125
130
  if @search_clear_button
126
131
  res << "<\%= f.button \"Clear\", name: nil, 'data-search-form-target': 'clearButton', class: 'btn btn-sm btn-secondary' %>"
127
132
  end
@@ -132,11 +137,12 @@ module HotGlue
132
137
 
133
138
 
134
139
  def all_form_fields(layout_strategy:)
135
- column_classes = layout_strategy.column_classes_for_form_fields
136
140
  columns = layout_object[:columns][:container]
137
141
 
138
142
  result = columns.map{ |column|
139
- " <div class='#{column_classes} cell--#{singular}--#{column.join("-")}' >" +
143
+ size = layout_object[:columns][:bootstrap_column_width][columns.index(column)]
144
+
145
+ " <div class='#{layout_strategy.column_classes_for_form_fields(size)} cell--#{singular}--#{column.join("-")}' >" +
140
146
  column.map { |col|
141
147
 
142
148
  field_error_name = columns_map[col].field_error_name
@@ -167,11 +173,21 @@ module HotGlue
167
173
 
168
174
  @tinymce_stimulus_controller = (columns_map[col].modify_as == {tinymce: 1} ? "data-controller='tiny-mce' " : "")
169
175
 
170
- add_spaces_each_line( "\n <span #{@tinymce_stimulus_controller}class='<%= \"alert alert-danger\" if #{singular}.errors.details.keys.include?(:#{field_error_name}) %>' #{'style="display: inherit;"'} >\n" +
171
- add_spaces_each_line( (form_labels_position == 'before' ? (the_label || "") + "<br />\n" : "") +
172
- + field_result +
173
- (form_labels_position == 'after' ? ( columns_map[col].newline_after_field? ? "<br />\n" : "") + (the_label || "") : "") , 4) +
174
- "\n </span>\n ", 2)
176
+ if @stimmify
177
+ col_target = HotGlue.to_camel_case(col.to_s.gsub("_", " "))
178
+ data_attr = " data-#{@stimmify}-target='#{col_target}Wrapper'"
179
+ end
180
+
181
+ unless hidden.include?(col.to_sym)
182
+ add_spaces_each_line( "\n <span #{@tinymce_stimulus_controller}class='<%= \"alert alert-danger\" if #{singular}.errors.details.keys.include?(:#{field_error_name}) %>' #{data_attr} >\n" +
183
+ add_spaces_each_line( (form_labels_position == 'before' ? (the_label || "") + "<br />\n" : "") +
184
+ + field_result +
185
+ (form_labels_position == 'after' ? ( columns_map[col].newline_after_field? ? "<br />\n" : "") + (the_label || "") : "") , 4) +
186
+ "\n </span>\n ", 2)
187
+ else
188
+ columns_map[col].hidden_output
189
+ end
190
+
175
191
 
176
192
  }.join("") + "\n </div>"
177
193
  }.join("\n")
@@ -192,10 +208,8 @@ module HotGlue
192
208
  ################################################################
193
209
 
194
210
  def all_line_fields(layout_strategy:,
195
- perc_width:,
196
- col_identifier: nil)
211
+ perc_width:)
197
212
 
198
- @col_identifier = layout_strategy.column_classes_for_line_fields
199
213
 
200
214
  inline_list_labels = @inline_list_labels || 'omit'
201
215
  columns = layout_object[:columns][:container]
@@ -205,13 +219,16 @@ module HotGlue
205
219
 
206
220
  style_with_flex_basis = layout_strategy.style_with_flex_basis(perc_width)
207
221
 
208
- result = columns.map{ |column|
222
+ result = columns.map.with_index{ |column,i|
223
+
224
+ size = layout_object[:columns][:bootstrap_column_width][i]
209
225
 
210
- "<div class='hg-col #{col_identifier} #{singular}--#{column.join("-")}'#{style_with_flex_basis}> " +
226
+ "<div class='hg-col #{layout_strategy.column_classes_for_line_fields(size)} #{singular}--#{column.join("-")}'#{style_with_flex_basis}> " +
211
227
  column.map { |col|
212
228
  if eval("#{singular_class}.columns_hash['#{col}']").nil? && !attachments.keys.include?(col) && !related_sets.include?(col)
213
229
  raise "Can't find column '#{col}' on #{singular_class}, are you sure that is the column name?"
214
230
  end
231
+
215
232
  field_output = columns_map[col].line_field_output
216
233
 
217
234
  label = "<label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
@@ -219,6 +236,8 @@ module HotGlue
219
236
  "#{inline_list_labels == 'before' ? label + "<br/>" : ''}#{field_output}#{inline_list_labels == 'after' ? "<br/>" + label : ''}"
220
237
  }.join( "<br />") + "</div>"
221
238
  }.join("\n")
239
+ return result
240
+
222
241
  end
223
242
  end
224
243
  end
@@ -28,7 +28,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
28
28
  :layout_strategy, :form_placeholder_labels,
29
29
  :form_labels_position, :no_nav_menu, :pundit,
30
30
  :self_auth, :namespace_value, :record_scope, :related_sets,
31
- :search_clear_button, :search_autosearch, :include_object_names
31
+ :search_clear_button, :search_autosearch, :include_object_names,
32
+ :stimmify, :stimmify_camel, :hidden
32
33
  # important: using an attr_accessor called :namespace indirectly causes a conflict with Rails class_name method
33
34
  # so we use namespace_value instead
34
35
 
@@ -56,6 +57,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
56
57
  class_option :big_edit, type: :boolean, default: false
57
58
  class_option :show_only, type: :string, default: ""
58
59
  class_option :update_show_only, type: :string, default: ""
60
+ class_option :hidden, type: :string, default: ""
59
61
  class_option :ujs_syntax, type: :boolean, default: nil
60
62
  class_option :downnest, type: :string, default: nil
61
63
  class_option :magic_buttons, type: :string, default: nil
@@ -91,6 +93,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
91
93
  class_option :modify, default: {}
92
94
  class_option :display_as, default: {}
93
95
  class_option :pundit, default: nil
96
+ class_option :pundit_policy_override, default: nil
94
97
  class_option :related_sets, default: ''
95
98
  class_option :code_before_create, default: nil
96
99
  class_option :code_after_create, default: nil
@@ -101,6 +104,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
101
104
  class_option :include_object_names, type: :boolean, default: false
102
105
  class_option :new_button_position, type: :string, default: 'above'
103
106
  class_option :downnest_shows_headings, type: :boolean, default: nil
107
+ class_option :stimmify, type: :string, default: nil
104
108
 
105
109
 
106
110
  # SEARCH OPTIONS
@@ -220,25 +224,18 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
220
224
  @include_fields += options['include'].split(":").collect { |x| x.split(",") }.flatten.collect(&:to_sym)
221
225
  end
222
226
 
223
- # @show_only_data = {}
224
- # if !options['show_only'].empty?
225
- # show_only_input = options['show_only'].split(",")
226
- # show_only_input.each do |setting|
227
- # if setting.include?("[")
228
- # setting =~ /(.*)\[(.*)\]/
229
- # key, lookup_as = $1, $2
230
- # @show_only_data[key.to_sym] = {cast: $2 }
231
- # else
232
- # @show_only_data[setting.to_sym] = {cast: nil}
233
- # end
234
- # end
235
- # end
227
+
236
228
 
237
229
  @show_only = options['show_only'].split(",").collect(&:to_sym)
238
230
  if @show_only.any?
239
231
  puts "show only field #{@show_only}}"
240
232
  end
241
233
 
234
+ @hidden = options['hidden'].split(",").collect(&:to_sym)
235
+ if @hidden.any?
236
+ puts "hidden fields #{@hidden}}"
237
+ end
238
+
242
239
  @modify_as = {}
243
240
  if !options['modify'].empty?
244
241
  modify_input = options['modify'].split(",")
@@ -357,6 +354,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
357
354
 
358
355
 
359
356
  @pundit = options['pundit']
357
+ @pundit_policy_override = options['pundit_policy_override']
360
358
 
361
359
  @no_nav_menu = options['no_nav_menu']
362
360
 
@@ -439,6 +437,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
439
437
  @related_sets = {}
440
438
  related_set_input.each do |setting|
441
439
  name = setting.to_sym
440
+ byebug
442
441
  association_ids_method = eval("#{singular_class}.reflect_on_association(:#{setting.to_sym})").class_name.underscore + "_ids"
443
442
  class_name = eval("#{singular_class}.reflect_on_association(:#{setting.to_sym})").class_name
444
443
 
@@ -522,7 +521,11 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
522
521
  # { key: value }
523
522
  # : nil}.compact
524
523
 
525
-
524
+ @stimmify = options['stimmify']
525
+ if @stimmify === "stimmify"
526
+ @stimmify = @singular.gsub("_", "-") + "-form"
527
+ @stimify_camel = @stimmify.camelize
528
+ end
526
529
 
527
530
  # build a new polymorphic object
528
531
  @associations = []
@@ -647,7 +650,10 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
647
650
  search_position: @search_position,
648
651
  search_clear_button: @search_clear_button,
649
652
  search_autosearch: @search_autosearch,
650
- form_path: form_path_new_helper
653
+ form_path: form_path_new_helper,
654
+ stimmify: @stimmify,
655
+ stimmify_camel: @stimmify_camel,
656
+ hidden: @hidden
651
657
  )
652
658
  elsif @markup == "slim"
653
659
  raise(HotGlue::Error, "SLIM IS NOT IMPLEMENTED")
@@ -978,7 +984,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
978
984
 
979
985
  def list_column_headings
980
986
  @template_builder.list_column_headings(
981
- col_identifier: @layout_strategy.column_classes_for_column_headings,
982
987
  column_width: @layout_strategy.column_width,
983
988
  singular: @singular
984
989
  )
@@ -1084,6 +1089,17 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1084
1089
  top_level: top_level)
1085
1090
  end
1086
1091
 
1092
+ def edit_parent_path_helper
1093
+ # the path to the edit route of the PARENT
1094
+ if @nested_set.any? && @nested
1095
+ "edit_#{@namespace + "_" if @namespace}#{(@nested_set.collect { |x| x[:singular] }.join("_") + "_" if @nested_set.any?)}path(" +
1096
+ "#{@nested_set.collect { |x| x[:singular] }.join(", ")}" + ")"
1097
+
1098
+ else
1099
+ "edit_#{@namespace + "_" if @namespace}path"
1100
+ end
1101
+ end
1102
+
1087
1103
  def datetime_fields_list
1088
1104
  @columns.select do |col|
1089
1105
  if @the_object.columns_hash[col.to_s]
@@ -1442,7 +1458,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1442
1458
 
1443
1459
  def all_line_fields
1444
1460
  @template_builder.all_line_fields(
1445
- col_identifier: @layout_strategy.column_classes_for_line_fields,
1446
1461
  perc_width: @layout_strategy.each_col, # undefined method `each_col'
1447
1462
  layout_strategy: @layout_strategy
1448
1463
  )
@@ -78,11 +78,12 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
78
78
  end
79
79
 
80
80
  def index
81
- load_all_<%= plural %>
82
- <% if @search_fields %>
81
+ load_all_<%= plural %><% if @search_fields %>
83
82
  <%= @search_fields.collect{|field_name| @columns_map[field_name.to_sym].code_to_reset_match_if_search_is_blank}.compact.join(" \n") %><% end %>
84
- load_all_<%= plural %><% if @pundit %><% if @pundit %>
85
- authorize @<%= plural_name %><% end %>
83
+ <% if @pundit %><% if @pundit && !@pundit_policy_override %>
84
+ authorize @<%= plural_name %><% elsif @pundit && @pundit_policy_override %>
85
+ skip_authorization
86
+ raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.index?<% end %>
86
87
  rescue Pundit::NotAuthorizedError
87
88
  flash[:alert] = 'You are not authorized to perform this action.'
88
89
  render 'layouts/error'<% end %>
@@ -92,7 +93,10 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
92
93
  @<%= singular_name %> = <%= class_name %>.new<% if eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>(<%= @object_owner_sym %>: <%= @object_owner_eval %>)<% end %><% elsif @object_owner_optional && any_nested? %>
93
94
  @<%= singular_name %> = <%= class_name %>.new({}.merge(<%= @nested_set.last[:singular] %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}))<% else %>
94
95
  @<%= singular_name %> = <%= class_name %>.new(<% if any_nested? %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)<% end %>
95
- <% if @pundit %>authorize @<%= singular_name %><% end %><% if @pundit %>
96
+ <% if @pundit && !@pundit_policy_override %>
97
+ authorize @<%= singular %><% elsif @pundit && @pundit_policy_override %>
98
+ skip_authorization
99
+ raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.new?<% end %><% if @pundit %>
96
100
  @action = 'new'
97
101
  rescue Pundit::NotAuthorizedError
98
102
  flash[:alert] = 'You are not authorized to perform this action.'
@@ -112,7 +116,10 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
112
116
  <%= creation_syntax %>
113
117
  <% if @pundit %><% @related_sets.each do |key, related_set| %>
114
118
  check_<%= related_set[:association_ids_method].to_s %>_permissions(modified_params, :create)<% end %><% end %>
115
- <% if @pundit %>authorize @<%= singular %><% end %>
119
+ <% if @pundit && !@pundit_policy_override %>
120
+ authorize @<%= singular %><% elsif @pundit && @pundit_policy_override %>
121
+ skip_authorization
122
+ raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.create?<% end %>
116
123
  <%= @code_before_create ? "\n " + @code_before_create.gsub(";", "\n") : "" %>
117
124
  if @<%= singular_name %>.save<%= @code_after_create ? ("\n " + @code_after_create.gsub(";", "\n")) : ""%>
118
125
  flash[:notice] = "Successfully created #{@<%= singular %>.<%= display_class %>}"
@@ -148,8 +155,10 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
148
155
 
149
156
  <% end %>
150
157
  <% unless @no_edit %>
151
- def show<% if @pundit %>
152
- authorize @<%= singular %><% end %>
158
+ def show<% if @pundit && !@pundit_policy_override %>
159
+ authorize @<%= singular %><% elsif @pundit && @pundit_policy_override %>
160
+ skip_authorization
161
+ raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.show?<% end %>
153
162
  redirect_to <%= HotGlue.optionalized_ternary(namespace: @namespace,
154
163
  target: @singular,
155
164
  top_level: false,
@@ -160,8 +169,10 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
160
169
  put_form: true).gsub("(#{singular}", "(@#{singular}") %>
161
170
  end
162
171
 
163
- def edit<% if @pundit %>
164
- authorize @<%= singular_name %><% end %>
172
+ def edit<% if @pundit && !@pundit_policy_override %>
173
+ authorize @<%= singular %><% elsif @pundit && @pundit_policy_override %>
174
+ skip_authorization
175
+ raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.edit?<% end %>
165
176
  @action = 'edit'
166
177
  render :edit<% if @pundit %>
167
178
  rescue Pundit::NotAuthorizedError
@@ -187,15 +198,19 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
187
198
 
188
199
  <% if @hawk_keys.any? %> modified_params = hawk_params({<%= hawk_to_ruby %>}, modified_params)<% end %>
189
200
  <%= controller_attachment_orig_filename_pickup_syntax %>
190
- <% if @pundit %>
191
- if @<%= singular_name %>.attributes = modified_params
201
+ <% if @pundit && !@pundit_policy_override %>
192
202
  authorize @<%= singular_name %>
193
203
  <%= @code_before_update ? "\n " + @code_before_update.gsub(";", "\n") : "" %>
194
- @<%= singular_name %>.save
195
- <% else %>
196
- <%= @code_before_update ? "\n " + @code_before_update.gsub(";", "\n") : "" %>
204
+
197
205
  if @<%= singular_name %>.update(modified_params)
198
- <% end %>
206
+
207
+ <% elsif @pundit && @pundit_policy_override %>
208
+ skip_authorization
209
+ raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.update?
210
+ if @<%= singular_name %>.update(modified_params)
211
+ <% else %>
212
+ <%= @code_before_update ? "\n " + @code_before_update.gsub(";", "\n") : "" %>
213
+ if @<%= singular_name %>.update(modified_params)<% end %>
199
214
  <%= post_action_parental_updates.compact.join("\n ") %>
200
215
  <%= @code_after_update ? "\n " + @code_after_update.gsub(";", "\n") : "" %>
201
216
  <% if @display_list_after_update %> load_all_<%= plural %><% end %>
@@ -216,11 +231,14 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
216
231
  end
217
232
 
218
233
  <% end %><% if destroy_action %> def destroy
219
- <% if @pundit %>authorize @<%= singular_name %><% end %>
234
+ <% if @pundit && !@pundit_policy_override %>
235
+ authorize @<%= singular %><% elsif @pundit && @pundit_policy_override %>
236
+ skip_authorization
237
+ raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.destroy?<% end %>
220
238
  begin
221
239
  @<%=singular_name%>.destroy
222
240
  flash[:notice] = '<%= singular_name.titlecase %> successfully deleted'
223
- rescue StandardError => e
241
+ rescue ActiveRecordError => e
224
242
  flash[:alert] = '<%= singular_name.titlecase %> could not be deleted'
225
243
  end
226
244
  <%= post_action_parental_updates.join("\n ") %>
@@ -4,7 +4,9 @@
4
4
  <\%= render(partial: "<%= namespace_with_trailing_dash %>errors", locals: {resource: <%= singular %> }) %>
5
5
  <\% end %>
6
6
  <h2>Editing <%= singular + " " if @include_object_names %><\%= <%= singular %>.<%= display_class %> %></h2>
7
- <\%= form_with model: <%= singular %>, url: <%= form_path_edit_helper %><%= ", html: {'data-turbo': false}" if @big_edit %> do |f| %>
7
+ <\%= form_with model: <%= singular %>,
8
+ <% if @stimmify %> data: {controller: '<%= @stimmify %>' },
9
+ <% end %>url: <%= form_path_edit_helper %><%= ", html: {'data-turbo': false}" if @big_edit %> do |f| %>
8
10
  <\%= render partial: "<%= namespace_with_trailing_dash + @controller_build_folder + "/" %>form", locals: {:<%= singular %> => <%= singular %>, f: f}<%= @nested_set.collect{|arg| ".merge(#{arg[:singular]} ? {#{arg[:singular]}: #{arg[:singular]}} : {})" }.join %> \%>
9
11
  <% if @edit_within_form_partial %><\%= render partial: "edit_within_form", locals: {f: f, <%= singular %>: <%= singular %>}<%= @nested_set.collect{|arg| ".merge(#{arg[:singular]} ? {#{arg[:singular]}: #{arg[:singular]}} : {})" }.join %> %><% end %>
10
12
  <\% end %>
@@ -2,7 +2,8 @@
2
2
  <%= form_fields_html %>
3
3
 
4
4
  <div class="<%= @layout_strategy.column_classes_for_button_column %>">
5
- <\%= link_to "Cancel", <%= path_helper_plural %>, {class: "btn btn-secondary"} %><% if @no_field_form %>
5
+ <\%= link_to "Cancel", <%=
6
+ @nested_set.none? ? path_helper_plural : edit_parent_path_helper %>, {class: "btn btn-secondary"} %><% if @no_field_form %>
6
7
  <\%= f.hidden_field "_________" %><% end %>
7
8
  <\%= f.submit "Save", class: "btn btn-primary pull-right" %>
8
9
  </div>
@@ -2,7 +2,9 @@
2
2
  <h3>
3
3
  <%= @new_form_heading %>
4
4
  </h3>
5
- <\%= form_with model: <%= singular %>, url: <%= form_path_new_helper %>, method: :post<%= @display_edit_after_create ? ", html: {'data-turbo': false}" : "" %> do |f| \%>
5
+ <\%= form_with model: <%= singular %>,
6
+ <% if @stimmify %>data: {controller: '<%= @stimmify %>' },
7
+ <% end %>url: <%= form_path_new_helper %>, method: :post<%= @display_edit_after_create ? ", html: {'data-turbo': false}" : "" %> do |f| \%>
6
8
  <\%= render partial: "<%= namespace_with_slash + @controller_build_folder %>/form",
7
9
  locals: { <%= singular %>: <%= singular %>, f: f}<%= @nested_set.collect{|arg| ".merge(defined?(#{arg[:singular]}) ? {#{arg[:singular]}: #{arg[:singular]}}: {})" }.join %> \%>
8
10
 
@@ -8,30 +8,40 @@
8
8
  <% if @big_edit %>
9
9
  </div>
10
10
  </div>
11
+ </div>
12
+
11
13
 
12
14
 
13
15
  <% if @downnest_children.any? && @big_edit %>
14
- <hr />
15
- <% each_downnest_width = @downnest_children.count == 1 ? 33 : (53/@downnest_children.count).floor %>
16
- <% @downnest_object.each do |downnest, size| %>
17
- <div class="row">
18
- <div class="col-md-<%= @big_edit ? 12 : 6 %>">
16
+ <div class="container" data-controller="bootstrap-tabbed-nav">
17
+ <ul class="nav nav-tabs" id="<%= singular + "_downnest_portals" %>" role="tablist">
18
+ <% @downnest_object.each_with_index do |data,index| %>
19
+ <% downnest = data[0] %>
20
+ <li class="nav-item" role="presentation">
21
+ <button class="nav-link <%= "active" if index==0 %>" id="<%= downnest %>-tab" data-bs-toggle="tab" data-bs-target="#<%= downnest %>-portal" type="button" role="tab" aria-controls="home" aria-selected="true">
22
+ <%= downnest.titlecase.pluralize %>
23
+ </button>
24
+ </li>
25
+ <% end %>
26
+ </ul>
27
+
28
+ <div class="tab-content" id="myTabContent">
29
+ <% @downnest_object.each_with_index do |data, index| %>
30
+ <% downnest = data[0] %>
31
+ <div class="tab-pane fade <%= "show active" if index==0 %>" id="<%= downnest %>-portal" role="tabpanel" aria-labelledby="<%= downnest %>-tab">
19
32
  <% downnest_object = eval("#{singular_class}.reflect_on_association(:#{downnest})") %>
20
33
  <% if downnest_object.nil?; raise "no relationship for downnested portal `#{downnest}` found on `#{singular_class}`; please check relationship for has_many :#{downnest}"; end; %>
21
34
  <% downnest_class = downnest_object.class_name %>
22
35
  <% downnest_object_name = eval("#{downnest_class}.table_name") %>
23
36
  <% downnest_style = @layout_strategy.downnest_style %>
24
- <% if @downnest_shows_headings %>
25
- <h3>
26
- <%= downnest_class.titlecase.pluralize %>
27
- </h3>
28
- <% end %>
29
- <\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest_object_name %>/list", locals: {<%= @singular %>: @<%= @singular %>, <%= downnest_object_name %>: @<%= @singular %>.<%= downnest %><% if @nested_set.any? %>, <%= @nested_set.collect{|x| "#{x[:singular]}: @#{x[:singular]}"}.join(", ") %>, nested_for: "<%= @nested_set.collect{|x| "#{x[:singular]}-" + "\#{" + "@#{x[:singular]}.id}"}.join("__") %>__<%= singular %>-#{@<%= @singular %>.id}" <% end %> } \%>
30
37
 
31
- </div>
38
+ <\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest_object_name %>/list", locals: {<%= @singular %>: @<%= @singular %>, <%= downnest_object_name %>: @<%= @singular %>.<%= downnest %><% if @nested_set.any? %>, <%= @nested_set.collect{|x| "#{x[:singular]}: @#{x[:singular]}"}.join(", ") %>, nested_for: "<%= @nested_set.collect{|x| "#{x[:singular]}-" + "\#{" + "@#{x[:singular]}.id}"}.join("__") %>__<%= singular %>-#{@<%= @singular %>.id}" <% end %> } \%>
32
39
  </div>
33
40
  <% end %>
34
- <% end %>
41
+ </div>
42
+
35
43
  </div>
36
44
  <% end %>
37
45
 
46
+
47
+ <% end %>