super 0.20.0 → 0.21.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e47e4344e0e7e7cf55cc943672017a92e7e30d566aa84b28b2351b4f190b22ed
4
- data.tar.gz: 62b74ffa083bbabe27890359f987e78363e6fc86a8b164d8529155f9eeaff655
3
+ metadata.gz: 8074c717fdd2f747e7d880cdbb02ec13515ec85b3504e7f55f1db526ace24838
4
+ data.tar.gz: 5d446f1574a35e4ba542281b2edfe5ef36dd588a5c2420b81288702bb96f4607
5
5
  SHA512:
6
- metadata.gz: ec637b18bb09e636e988507036d41dde995a8f33aeacd69a5b94924eadfcbae4acba73a58c32a0d4188f4f3a8ae852c5b9a9566af647bf4e0583484369d4566c
7
- data.tar.gz: 7a9e37ed3dc2232e902e2d8b770c02e737413eec66cc4df80c1cefdb974e38d523568a1f66962a2943b667c6cb28439c0fb501c98b102747ad511d9d5204cc3c
6
+ metadata.gz: adca04cac0470dfe22929b710d331ff651eb53ee0fdf5f88657f9b18094963f09bda9c6b13808bc112a565937851eda14622e8a0d853b992fa5f1551e6daadb0
7
+ data.tar.gz: b694a20146e50d743fcc7ca5bbf6e67cdd63df3e256352b70a99a5a677ad0f5014f38ca29efe48263d840809d9c4e3f63d1972a28277510c882c0a6023cf55d0
data/README.md CHANGED
@@ -38,7 +38,7 @@ changes before 1.0.
38
38
  * Builds on top of standard Rails controllers and ERB views
39
39
  * Plenty of escape hatches for those very customized pages
40
40
  * No DSL. Configure your admin pages by setting methods and returning objects
41
- * Supports Rails 5.0+, 6.0+
41
+ * Supports Rails 5.0+, 6.0+, 7.0+
42
42
  * Supports Ruby 2.3+, 3.0+
43
43
 
44
44
 
@@ -22,7 +22,6 @@ module Super
22
22
  @records = load_records
23
23
  @display = display_schema.apply(action: current_action, format: request.format)
24
24
  @view = index_view
25
- @query_form = initialize_query_form
26
25
  initialize_filter_form
27
26
  initialize_sort_form
28
27
  @records = apply_queries
@@ -48,12 +47,9 @@ module Super
48
47
  set_record_attributes
49
48
 
50
49
  if save_record
51
- redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
50
+ redirect_to_record
52
51
  else
53
- @current_action = ActionInquirer.new!
54
- @form = form_schema
55
- @view = new_view
56
- render :new, status: :bad_request
52
+ render_new_as_bad_request
57
53
  end
58
54
  end
59
55
 
@@ -70,12 +66,9 @@ module Super
70
66
  set_record_attributes
71
67
 
72
68
  if save_record
73
- redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
69
+ redirect_to_record
74
70
  else
75
- @current_action = ActionInquirer.edit!
76
- @form = form_schema
77
- @view = edit_view
78
- render :edit, status: :bad_request
71
+ render_edit_as_bad_request
79
72
  end
80
73
  end
81
74
 
@@ -84,14 +77,12 @@ module Super
84
77
  @record = load_record
85
78
 
86
79
  if destroy_record
87
- redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
80
+ redirect_to_records
88
81
  else
89
- flash.alert = "Couldn't delete record"
90
- redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
82
+ redirect_to_record_with_destroy_failure_message
91
83
  end
92
- rescue ActiveRecord::InvalidForeignKey => e
93
- flash.alert = "Couldn't delete record: #{e.class}"
94
- redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
84
+ rescue ActiveRecord::ActiveRecordError => e
85
+ redirect_to_record_with_destroy_failure_message(e)
95
86
  end
96
87
 
97
88
  private
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ # Various methods that are useful for all Super admin controllers, regardless
5
+ # of the controller being a resourceful or non-resourceful.
6
+ class SitewideController < ActionController::Base
7
+ private
8
+
9
+ helper_method def site_title
10
+ Super.configuration.title
11
+ end
12
+
13
+ helper_method def site_navigation
14
+ Super::Navigation.new(&:all)
15
+ end
16
+
17
+ helper_method def document_title
18
+ if instance_variable_defined?(:@document_title)
19
+ return @document_title
20
+ end
21
+
22
+ document_title_segments.map(&:presence).compact.join(document_title_separator)
23
+ end
24
+
25
+ def document_title_segments
26
+ @document_title_segments ||= [page_title, site_title]
27
+ end
28
+
29
+ def document_title_separator
30
+ @document_title_separator ||= " - "
31
+ end
32
+ end
33
+ end
@@ -3,7 +3,7 @@
3
3
  module Super
4
4
  # Various methods that determine the behavior of your controllers. These
5
5
  # methods can and should be overridden.
6
- class SubstructureController < ActionController::Base
6
+ class SubstructureController < ViewController
7
7
  def self.batch(action_name)
8
8
  mod = Module.new do
9
9
  define_method(action_name) do
@@ -215,22 +215,55 @@ module Super
215
215
  @record.destroy
216
216
  end
217
217
 
218
- def initialize_query_form
219
- Super::Query::FormObject.new(
218
+ def redirect_to_record
219
+ redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
220
+ end
221
+
222
+ def redirect_to_records
223
+ redirect_to polymorphic_path(Super::Link.polymorphic_parts(model))
224
+ end
225
+
226
+ def redirect_to_record_with_destroy_failure_message(error = nil)
227
+ flash.alert =
228
+ case error
229
+ when ActiveRecord::InvalidForeignKey
230
+ I18n.t("super.destroy_error.invalid_foreign_key")
231
+ else
232
+ I18n.t("super.destroy_error.generic")
233
+ end
234
+
235
+ redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
236
+ end
237
+
238
+ def render_new_as_bad_request
239
+ @current_action = ActionInquirer.new!
240
+ @form = form_schema
241
+ @view = new_view
242
+ render :new, status: :bad_request
243
+ end
244
+
245
+ def render_edit_as_bad_request
246
+ @current_action = ActionInquirer.edit!
247
+ @form = form_schema
248
+ @view = edit_view
249
+ render :edit, status: :bad_request
250
+ end
251
+
252
+ helper_method def query
253
+ @query ||= Super::Query.new(
220
254
  model: model,
221
- params: params,
222
- namespace: :q,
255
+ params: request.GET,
223
256
  current_path: request.path,
224
257
  )
225
258
  end
226
259
 
227
260
  def apply_queries
228
- @query_form.apply_changes(@records)
261
+ query.apply_changes(@records)
229
262
  end
230
263
 
231
264
  def initialize_filter_form
232
265
  if filters_enabled?
233
- @query_form.add(
266
+ @filter_form = query.build(
234
267
  Super::Filter::FormObject,
235
268
  namespace: :f,
236
269
  schema: filter_schema
@@ -240,7 +273,7 @@ module Super
240
273
 
241
274
  def initialize_sort_form
242
275
  if sort_enabled?
243
- @query_form.add(
276
+ @sort_form = query.build(
244
277
  Super::Sort::FormObject,
245
278
  namespace: :s,
246
279
  default: default_sort,
@@ -290,83 +323,5 @@ module Super
290
323
  helper_method def csv_enabled?
291
324
  true
292
325
  end
293
-
294
- def index_view
295
- Super::Layout.new(
296
- main: Super::ViewChain.new(
297
- main_panel: Super::Panel.new,
298
- batch_form: Super::Partial.new("batch_form"),
299
- main_header: Super::Partial.new("collection_header"),
300
- main: :@display
301
- ),
302
- aside: Super::ViewChain.new(
303
- main: :@query_form
304
- )
305
- )
306
- end
307
-
308
- def show_view
309
- Super::Layout.new(
310
- main: Super::ViewChain.new(
311
- main_panel: Super::Panel.new,
312
- main_header: Super::Partial.new("member_header"),
313
- main: :@display
314
- )
315
- )
316
- end
317
-
318
- def new_view
319
- Super::Layout.new(
320
- main: Super::ViewChain.new(
321
- main_panel: Super::Panel.new,
322
- main_header: Super::Partial.new("collection_header"),
323
- main: :@form
324
- )
325
- )
326
- end
327
-
328
- def edit_view
329
- Super::Layout.new(
330
- main: Super::ViewChain.new(
331
- main_panel: Super::Panel.new,
332
- main_header: Super::Partial.new("member_header"),
333
- main: :@form
334
- )
335
- )
336
- end
337
-
338
- concerning :Sitewide do
339
- included do
340
- helper_method :site_title
341
- helper_method :site_navigation
342
- helper_method :document_title
343
- end
344
-
345
- private
346
-
347
- def site_title
348
- Super.configuration.title
349
- end
350
-
351
- def site_navigation
352
- Super::Navigation.new(&:all)
353
- end
354
-
355
- def document_title
356
- if instance_variable_defined?(:@document_title)
357
- return @document_title
358
- end
359
-
360
- document_title_segments.map(&:presence).compact.join(document_title_separator)
361
- end
362
-
363
- def document_title_segments
364
- @document_title_segments ||= [page_title, site_title]
365
- end
366
-
367
- def document_title_separator
368
- @document_title_separator ||= " - "
369
- end
370
- end
371
326
  end
372
327
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ # These methods define what each resourceful Super admin page looks like.
5
+ # Generally, the return value of each of these methods should be set to
6
+ # `@view`.
7
+ class ViewController < SitewideController
8
+ private
9
+
10
+ def index_view
11
+ Super::Layout.new(
12
+ main: Super::ViewChain.new(
13
+ main_panel: Super::Panel.new,
14
+ batch_form: Super::Partial.new("batch_form"),
15
+ main_header: Super::Partial.new("collection_header"),
16
+ main: :@display
17
+ ),
18
+ aside: Super::ViewChain.new(
19
+ query_panel: Super::Panel.new,
20
+ query: query,
21
+ )
22
+ )
23
+ end
24
+
25
+ def show_view
26
+ Super::Layout.new(
27
+ main: Super::ViewChain.new(
28
+ main_panel: Super::Panel.new,
29
+ main_header: Super::Partial.new("member_header"),
30
+ main: :@display
31
+ )
32
+ )
33
+ end
34
+
35
+ def new_view
36
+ Super::Layout.new(
37
+ main: Super::ViewChain.new(
38
+ main_panel: Super::Panel.new,
39
+ main_header: Super::Partial.new("collection_header"),
40
+ main: :@form
41
+ )
42
+ )
43
+ end
44
+
45
+ def edit_view
46
+ Super::Layout.new(
47
+ main: Super::ViewChain.new(
48
+ main_panel: Super::Panel.new,
49
+ main_header: Super::Partial.new("member_header"),
50
+ main: :@form
51
+ )
52
+ )
53
+ end
54
+ end
55
+ end
@@ -2,9 +2,15 @@
2
2
  <table class="w-full border-separate" cellspacing="0" cellpadding="0">
3
3
  <thead class="">
4
4
  <tr class="">
5
- <% display_index.each_attribute_name do |attribute_name| %>
5
+ <% display_index.each_attribute do |attribute_name, attribute_definition| %>
6
6
  <th class="p-2 first:pl-6 border-b border-b-2 border-gray-400 text-gray-600 text-left text-sm font-normal bg-white top-0 z-10">
7
- <%= model.human_attribute_name(attribute_name) %>
7
+ <%=
8
+ if attribute_definition.respond_to?(:attribute_name) && attribute_definition.attribute_name
9
+ attribute_definition.attribute_name
10
+ else
11
+ model.human_attribute_name(attribute_name)
12
+ end
13
+ %>
8
14
  </th>
9
15
  <% end %>
10
16
  </tr>
@@ -1,7 +1,15 @@
1
1
  <table class="max-w-full mt-4">
2
- <% display_show.each_attribute_name do |attribute_name| %>
2
+ <% display_show.each_attribute do |attribute_name, attribute_definition| %>
3
3
  <tr>
4
- <th class="py-1 align-baseline text-right px-4"><%= model.human_attribute_name(attribute_name) %></th>
4
+ <th class="py-1 align-baseline text-right px-4">
5
+ <%=
6
+ if attribute_definition.respond_to?(:attribute_name) && attribute_definition.attribute_name
7
+ attribute_definition.attribute_name
8
+ else
9
+ model.human_attribute_name(attribute_name)
10
+ end
11
+ %>
12
+ </th>
5
13
  <td class="py-1 align-baseline"><%= display_show.render_attribute(template: self, record: @record, column: attribute_name) %></td>
6
14
  </tr>
7
15
  <% end %>
@@ -1,66 +1,70 @@
1
- <h1 class="text-lg">Filter</h1>
2
- <% filter.each_attribute do |attribute_form_object| %>
3
- <div class="mt-4">
4
- <%= form.fields_for(attribute_form_object.field_name, attribute_form_object) do |attribute_form| %>
5
- <% selected_index = 0 %>
6
- <div data-controller="tab-container" data-tab-container-tab-identifier-getter-value="tabIdentifierValue" data-tab-container-tab-controller-name-value="tab">
7
- <div>
8
- <span class="inline-block"><%= attribute_form_object.humanized_attribute_name %></span>
9
- <select data-tab-container-target="control" data-action="tab-container#change" class="super-input super-input-select inline-block">
10
- <% selected = false %>
1
+ <h1 class="text-lg mt-4">Filter</h1>
2
+ <%= super_fields_for(query.namespace_for(filter), filter) do |form| %>
3
+ <% filter.each_attribute do |attribute_form_object| %>
4
+ <div class="mt-4">
5
+ <%= form.fields_for(attribute_form_object.field_name, attribute_form_object) do |attribute_form| %>
6
+ <% selected_index = 0 %>
7
+ <div data-controller="tab-container" data-tab-container-tab-identifier-getter-value="tabIdentifierValue" data-tab-container-tab-controller-name-value="tab">
8
+ <div>
9
+ <span class="inline-block"><%= attribute_form_object.humanized_attribute_name %></span>
10
+ <select data-tab-container-target="control" data-action="tab-container#change" class="super-input super-input-select inline-block">
11
+ <% selected = false %>
12
+ <% attribute_form_object.each_operator.with_index do |operator_form_object, index| %>
13
+ <%
14
+ selected_attribute =
15
+ if !selected && operator_form_object.specified?
16
+ selected = true
17
+ selected_index = index
18
+ %(selected=selected)
19
+ else
20
+ ""
21
+ end
22
+ %>
23
+ <option value="<%= operator_form_object.identifier %>" <%= selected_attribute %>><%= operator_form_object.operator.humanized_operator_name %></option>
24
+ <% end %>
25
+ </select>
26
+ </div>
27
+ <div>
11
28
  <% attribute_form_object.each_operator.with_index do |operator_form_object, index| %>
12
- <%
13
- selected_attribute =
14
- if !selected && operator_form_object.specified?
15
- selected = true
16
- selected_index = index
17
- %(selected=selected)
18
- else
19
- ""
20
- end
21
- %>
22
- <option value="<%= operator_form_object.identifier %>" <%= selected_attribute %>><%= operator_form_object.operator.humanized_operator_name %></option>
23
- <% end %>
24
- </select>
25
- </div>
26
- <div>
27
- <% attribute_form_object.each_operator.with_index do |operator_form_object, index| %>
28
- <div data-controller="tab" data-tab-tab-container-getter-value="tabContainer" data-tab-container-target="tab" data-tab-identifier-value="<%= operator_form_object.identifier %>">
29
- <% form_html = capture do %>
30
- <div data-tab-target="content">
31
- <%= attribute_form.fields_for(operator_form_object.identifier, operator_form_object) do |operator_form| %>
32
- <div class="flex gap-x-2 mt-2">
33
- <% operator_form_object.each_field.with_index do |operator_field_name, index| %>
34
- <div class="flex-1">
35
- <% if operator_field_name == Super::Filter::FormObject::OperatorForm::NULLARY %>
36
- <%= operator_form.super.check_box(operator_field_name, {}, "1", "") %>
37
- <%= operator_form.super.label(operator_field_name, nil, super: { class: "select-none ml-1" }) %>
38
- <% elsif operator_form_object.operator.respond_to?(:field_transcript) && operator_form_object.operator.field_transcript %>
39
- <% field_transcript = operator_form_object.operator.field_transcript %>
40
- <% if field_transcript.super? %>
41
- <%= operator_form.super.public_send(field_transcript.method_name, operator_field_name, *field_transcript.args, **field_transcript.kwargs) %>
29
+ <div data-controller="tab" data-tab-tab-container-getter-value="tabContainer" data-tab-container-target="tab" data-tab-identifier-value="<%= operator_form_object.identifier %>">
30
+ <% form_html = capture do %>
31
+ <div data-tab-target="content">
32
+ <%= attribute_form.fields_for(operator_form_object.identifier, operator_form_object) do |operator_form| %>
33
+ <div class="flex gap-x-2 mt-2">
34
+ <% operator_form_object.each_field.with_index do |operator_field_name, index| %>
35
+ <div class="flex-1">
36
+ <% if operator_field_name == Super::Filter::FormObject::OperatorForm::NULLARY %>
37
+ <%= operator_form.super.check_box(operator_field_name, {}, "1", "") %>
38
+ <%= operator_form.super.label(operator_field_name, nil, super: { class: "select-none ml-1" }) %>
39
+ <% elsif operator_form_object.operator.respond_to?(:field_transcript) && operator_form_object.operator.field_transcript %>
40
+ <% field_transcript = operator_form_object.operator.field_transcript %>
41
+ <% if field_transcript.super? %>
42
+ <%= operator_form.super.public_send(field_transcript.method_name, operator_field_name, *field_transcript.args, **field_transcript.kwargs) %>
43
+ <% else %>
44
+ <%= operator_form.public_send(field_transcript.method_name, operator_field_name, *field_transcript.args, **field_transcript.kwargs) %>
45
+ <% end %>
42
46
  <% else %>
43
- <%= operator_form.public_send(field_transcript.method_name, operator_field_name, *field_transcript.args, **field_transcript.kwargs) %>
47
+ <%= operator_form.super.text_field(operator_field_name) %>
44
48
  <% end %>
45
- <% else %>
46
- <%= operator_form.super.text_field(operator_field_name) %>
47
- <% end %>
48
- </div>
49
- <% end %>
50
- </div>
51
- <% end %>
52
- </div>
53
- <% end %>
49
+ </div>
50
+ <% end %>
51
+ </div>
52
+ <% end %>
53
+ </div>
54
+ <% end %>
54
55
 
55
- <%= form_html if index == selected_index %>
56
+ <%= form_html if index == selected_index %>
56
57
 
57
- <template data-tab-target="pocket">
58
- <%= form_html %>
59
- </template>
60
- </div>
61
- <% end %>
58
+ <template data-tab-target="pocket">
59
+ <%= form_html %>
60
+ </template>
61
+ </div>
62
+ <% end %>
63
+ </div>
62
64
  </div>
63
- </div>
64
- <% end %>
65
- </div>
65
+ <% end %>
66
+ </div>
67
+ <% end %>
66
68
  <% end %>
69
+
70
+ <%= yield if block_given? %>
@@ -1,5 +1,3 @@
1
- <%# <% layout.resolve(self) %1> %>
2
-
3
1
  <% if layout.header %>
4
2
  <%= render layout.header %>
5
3
  <% end %>
@@ -1,18 +1,19 @@
1
- <%= render(Super::Panel.new) do %>
1
+ <% if filters_enabled? || sort_enabled? %>
2
2
  <h1 class="text-xl">Query</h1>
3
- <%= super_form_for(
4
- query,
5
- url: query.path,
6
- method: :get,
7
- as: query.namespace,
8
- html: { class: "mt-4" },
9
- data: { controller: "clean-filter-params", action: "submit->clean-filter-params#call" }) do |form| %>
10
- <% query.addons.each do |namespace, addon| %>
11
- <%= form.fields_for namespace do |addon_form| %>
12
- <%= render(addon, form: addon_form) %>
3
+
4
+ <%= form_tag(query.path, method: :get, data: { controller: "clean-filter-params", action: "submit->clean-filter-params#call" }) do %>
5
+ <% if filters_enabled? %>
6
+ <%= render @filter_form %>
7
+ <% end %>
8
+ <% if sort_enabled? %>
9
+ <% if filters_enabled? %>
10
+ <div class="mt-6"></div>
13
11
  <% end %>
12
+ <%= render @sort_form %>
14
13
  <% end %>
15
14
 
16
- <%= form.super.submit "Apply", class: "super-button--border-gray mt-6" %>
15
+ <%= submit_tag("Apply", class: "super-button super-button--border-gray mt-6") %>
17
16
  <% end %>
18
17
  <% end %>
18
+
19
+ <%= yield if block_given? %>
@@ -1,18 +1,22 @@
1
1
  <h1 class="text-lg mt-6">Sort</h1>
2
- <div data-controller="apply-template">
3
- <% sort.exprs.each.with_index do |expr, index| %>
4
- <%= form.fields_for("exprs[]", expr.with_index(index)) do |expr_fields| %>
5
- <%= render "sort_expression", expr_fields: expr_fields, sort: sort %>
2
+ <%= super_fields_for(query.namespace_for(sort), sort) do |form| %>
3
+ <div data-controller="apply-template">
4
+ <% sort.exprs.each.with_index do |expr, index| %>
5
+ <%= form.fields_for("exprs[]", expr.with_index(index)) do |expr_fields| %>
6
+ <%= render "sort_expression", expr_fields: expr_fields, sort: sort %>
7
+ <% end %>
6
8
  <% end %>
7
- <% end %>
8
9
 
9
- <%= form.fields_for("exprs[]", sort.new_expr.with_index("TEMPLATEINDEX")) do |expr_fields| %>
10
- <template data-apply-template-target="template">
11
- <%= render "sort_expression", expr_fields: expr_fields, sort: sort %>
12
- </template>
13
- <% end %>
10
+ <%= form.fields_for("exprs[]", sort.new_expr.with_index("TEMPLATEINDEX")) do |expr_fields| %>
11
+ <template data-apply-template-target="template">
12
+ <%= render "sort_expression", expr_fields: expr_fields, sort: sort %>
13
+ </template>
14
+ <% end %>
15
+
16
+ <a href="#" data-action="apply-template#call" class="block mt-2 text-sm">
17
+ Add
18
+ </a>
19
+ </div>
20
+ <% end %>
14
21
 
15
- <a href="#" data-action="apply-template#call" class="block mt-2 text-sm">
16
- Add
17
- </a>
18
- </div>
22
+ <%= yield if block_given? %>
@@ -1,5 +1,24 @@
1
- <% current = view_chain.chain.shift %>
2
- <% current = instance_variable_get(current) if current.kind_of?(Symbol) %>
3
- <%= render(current) do %>
4
- <%= render(view_chain) %>
1
+ <%
2
+ name, current = view_chain.shift
3
+ current =
4
+ if current.kind_of?(Symbol)
5
+ instance_variable_get(current)
6
+ else
7
+ current
8
+ end
9
+
10
+ if !current
11
+ Rails.logger.warn do
12
+ "Super::ViewChain encountered a nil view: #{name.inspect}."
13
+ end
14
+ end
15
+ %>
16
+ <% if current %>
17
+ <% if view_chain.empty? %>
18
+ <%= render(current) %>
19
+ <% else %>
20
+ <%= render(current) do %>
21
+ <%= render(view_chain) %>
22
+ <% end %>
23
+ <% end %>
5
24
  <% end %>
@@ -17,3 +17,6 @@ en:
17
17
  layout:
18
18
  powered_by_html: "%{env} environment. Powered by Super %{version}. <a href='https://superadministration.github.io/v%{version}/'>Developer docs.</a>"
19
19
  mismatching_package_json_gemfile_versions: "The version of Super specified in your package.json file does not match the version specified in your Gemfile.lock."
20
+ destroy_error:
21
+ invalid_foreign_key: Couldn't delete record because other records still refer to this one
22
+ generic: Couldn't delete record
data/lib/super/badge.rb CHANGED
@@ -12,9 +12,18 @@ module Super
12
12
  purple: "bg-purple-800 text-white",
13
13
  }
14
14
 
15
- def initialize(text, styles: nil)
15
+ def initialize(text, style: nil, styles: nil)
16
16
  @text = text
17
- @requested_styles = Array(styles.presence).flatten
17
+ if styles.present?
18
+ Super::Useful::Deprecation["0.22"].deprecation_warning("styles:", "use `style:` with a single style")
19
+ end
20
+ @requested_styles = Array(styles.presence).flatten + Array(style.presence).flatten
21
+ if @requested_styles.any? { |s| s.is_a?(String) }
22
+ Super::Useful::Deprecation["0.22"].warn("Super::Badge.new(text, style:) accepts exactly one Symbol style from this list #{STYLES.keys.inspect}")
23
+ end
24
+ if @requested_styles.size != 1
25
+ Super::Useful::Deprecation["0.22"].warn("Super::Badge.new(text, style:) accepts exactly one style, but it received #{@requested_styles.size}")
26
+ end
18
27
  end
19
28
 
20
29
  def styles
data/lib/super/cheat.rb CHANGED
@@ -3,7 +3,12 @@
3
3
  module Super
4
4
  class Cheat
5
5
  def controller
6
- paths = %w[../../app/controllers/super/substructure_controller.rb]
6
+ paths = %w[
7
+ ../../app/controllers/super/application_controller.rb
8
+ ../../app/controllers/super/substructure_controller.rb
9
+ ../../app/controllers/super/view_controller.rb
10
+ ../../app/controllers/super/sitewide_controller.rb
11
+ ]
7
12
  methods =
8
13
  paths
9
14
  .map { |f| File.read(File.expand_path(f, __dir__)) }