super 0.21.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -47
  3. data/app/assets/javascripts/super/application.js +1201 -2092
  4. data/app/assets/stylesheets/super/application.css +54 -6569
  5. data/app/controllers/super/application_controller.rb +44 -30
  6. data/app/controllers/super/foundation_controller.rb +30 -0
  7. data/app/controllers/super/sitewide_controller.rb +6 -3
  8. data/app/controllers/super/substructure_controller.rb +40 -47
  9. data/app/controllers/super/view_controller.rb +5 -1
  10. data/app/views/layouts/super/application.html.erb +3 -3
  11. data/app/views/super/application/_batch_checkbox.csv.erb +1 -1
  12. data/app/views/super/application/_batch_checkbox.html.erb +1 -1
  13. data/app/views/super/application/_collection_header.html.erb +1 -1
  14. data/app/views/super/application/_csv_button.html.erb +1 -1
  15. data/app/views/super/application/_display_actions.html.erb +1 -1
  16. data/app/views/super/application/_display_rich_text.html.erb +1 -1
  17. data/app/views/super/application/_form.html.erb +1 -1
  18. data/app/views/super/application/_form_fieldset.html.erb +1 -1
  19. data/app/views/super/application/_form_has_many.html.erb +2 -2
  20. data/app/views/super/application/_form_has_one.html.erb +1 -1
  21. data/app/views/super/application/_layout.html.erb +6 -6
  22. data/app/views/super/application/_link.html.erb +1 -6
  23. data/app/views/super/application/_member_header.html.erb +1 -1
  24. data/app/views/super/application/_panel.html.erb +1 -1
  25. data/app/views/super/application/_query.html.erb +2 -2
  26. data/app/views/super/application/_site_header.html.erb +2 -2
  27. data/app/views/super/application/_sort.html.erb +2 -2
  28. data/app/views/super/application/_sort_expression.html.erb +1 -1
  29. data/app/views/super/application/_view_chain.html.erb +1 -24
  30. data/app/views/super/application/edit.html.erb +1 -1
  31. data/app/views/super/application/index.html.erb +1 -1
  32. data/app/views/super/application/new.html.erb +1 -1
  33. data/app/views/super/application/show.html.erb +1 -1
  34. data/frontend/super-frontend/dist/application.css +54 -6569
  35. data/frontend/super-frontend/dist/application.js +1201 -2092
  36. data/lib/super/action_inquirer.rb +28 -8
  37. data/lib/super/assets.rb +2 -2
  38. data/lib/super/badge.rb +8 -32
  39. data/lib/super/cheat.rb +6 -5
  40. data/lib/super/client_error.rb +4 -0
  41. data/lib/super/compatibility.rb +4 -0
  42. data/lib/super/configuration.rb +3 -0
  43. data/lib/super/display/schema_types.rb +38 -82
  44. data/lib/super/display.rb +13 -13
  45. data/lib/super/error.rb +14 -0
  46. data/lib/super/filter/form_object.rb +2 -2
  47. data/lib/super/filter/operator.rb +1 -1
  48. data/lib/super/filter/schema_types.rb +1 -1
  49. data/lib/super/form/field_transcript.rb +4 -0
  50. data/lib/super/form/schema_types.rb +2 -2
  51. data/lib/super/form/strong_params.rb +1 -1
  52. data/lib/super/form_builder/base_methods.rb +3 -9
  53. data/lib/super/form_builder/flatpickr_methods.rb +3 -3
  54. data/lib/super/form_builder.rb +19 -21
  55. data/lib/super/form_builder_helper.rb +3 -3
  56. data/lib/super/link.rb +15 -6
  57. data/lib/super/link_builder.rb +4 -4
  58. data/lib/super/navigation.rb +12 -8
  59. data/lib/super/partial.rb +0 -12
  60. data/lib/super/plugin.rb +2 -2
  61. data/lib/super/railtie.rb +1 -0
  62. data/lib/super/render_helper.rb +31 -0
  63. data/lib/super/reset.rb +1 -6
  64. data/lib/super/schema/guesser.rb +5 -5
  65. data/lib/super/schema.rb +2 -2
  66. data/lib/super/sort.rb +1 -1
  67. data/lib/super/useful/deprecations.rb +1 -3
  68. data/lib/super/useful/enum.rb +1 -1
  69. data/lib/super/useful/i19.rb +1 -1
  70. data/lib/super/version.rb +1 -1
  71. data/lib/super/view_chain.rb +19 -0
  72. data/lib/super.rb +1 -0
  73. metadata +4 -2
@@ -13,7 +13,7 @@ module Super
13
13
  ActionView::Base.field_error_proc = FormBuilder::FIELD_ERROR_PROC
14
14
 
15
15
  options[:builder] ||= FormBuilder
16
- return form_for(record, options, &block)
16
+ form_for(record, options, &block)
17
17
  ensure
18
18
  ActionView::Base.field_error_proc = original
19
19
  end
@@ -24,7 +24,7 @@ module Super
24
24
  ActionView::Base.field_error_proc = FormBuilder::FIELD_ERROR_PROC
25
25
 
26
26
  options[:builder] ||= FormBuilder
27
- return form_with(**options, &block)
27
+ form_with(**options, &block)
28
28
  ensure
29
29
  ActionView::Base.field_error_proc = original
30
30
  end
@@ -35,7 +35,7 @@ module Super
35
35
  ActionView::Base.field_error_proc = FormBuilder::FIELD_ERROR_PROC
36
36
 
37
37
  options[:builder] ||= FormBuilder
38
- return fields_for(*args, **options, &block)
38
+ fields_for(*args, **options, &block)
39
39
  ensure
40
40
  ActionView::Base.field_error_proc = original
41
41
  end
data/lib/super/link.rb CHANGED
@@ -26,24 +26,24 @@ module Super
26
26
  @registry ||= {}.tap do |reg|
27
27
  reg[:new] = LinkBuilder.new
28
28
  .text { |params:| Super::Useful::I19.i18n_with_fallback("super", params[:controller].split("/"), "actions.new") }
29
- .href { |params:| { controller: params[:controller], action: :new, only_path: true } }
29
+ .href { |params:| {controller: params[:controller], action: :new, only_path: true} }
30
30
  .freeze
31
31
  reg[:index] = LinkBuilder.new
32
32
  .text { |params:| Super::Useful::I19.i18n_with_fallback("super", params[:controller].split("/"), "actions.index") }
33
- .href { |params:| { controller: params[:controller], action: :index, only_path: true } }
33
+ .href { |params:| {controller: params[:controller], action: :index, only_path: true} }
34
34
  .freeze
35
35
  reg[:show] = LinkBuilder.new
36
36
  .text { |params:, **| Super::Useful::I19.i18n_with_fallback("super", params[:controller].split("/"), "actions.show") }
37
- .href { |params:, record:| { controller: params[:controller], action: :show, id: record, only_path: true } }
37
+ .href { |params:, record:| {controller: params[:controller], action: :show, id: record, only_path: true} }
38
38
  .freeze
39
39
  reg[:edit] = LinkBuilder.new
40
40
  .text { |params:, **| Super::Useful::I19.i18n_with_fallback("super", params[:controller].split("/"), "actions.edit") }
41
- .href { |params:, record:| { controller: params[:controller], action: :edit, id: record, only_path: true } }
41
+ .href { |params:, record:| {controller: params[:controller], action: :edit, id: record, only_path: true} }
42
42
  .freeze
43
43
  reg[:destroy] = LinkBuilder.new
44
44
  .text { |params:, **| Super::Useful::I19.i18n_with_fallback("super", params[:controller].split("/"), "actions.destroy") }
45
- .href { |params:, record:| { controller: params[:controller], action: :destroy, id: record, only_path: true } }
46
- .options { |**| { method: :delete, data: { confirm: "Really delete?" } } }
45
+ .href { |params:, record:| {controller: params[:controller], action: :destroy, id: record, only_path: true} }
46
+ .options { |**| {method: :delete, data: {confirm: "Really delete?"}} }
47
47
  .freeze
48
48
  end
49
49
  end
@@ -91,6 +91,15 @@ module Super
91
91
  @href = Super::Compatability.polymorphic_path_container.polymorphic_path(@href)
92
92
  end
93
93
 
94
+ def to_link(template, local_assigns)
95
+ default_options = local_assigns.fetch(:default_options, {})
96
+ template.link_to(
97
+ text,
98
+ href,
99
+ default_options.deep_merge(options)
100
+ )
101
+ end
102
+
94
103
  def to_partial_path
95
104
  "link"
96
105
  end
@@ -20,10 +20,10 @@ module Super
20
20
  raise Super::Error::IncompleteBuilder, "LinkBuilder requires that #text is set" if @text.nil?
21
21
  raise Super::Error::IncompleteBuilder, "LinkBuilder requires that #href is set" if @href.nil?
22
22
 
23
- @options ||= -> (**) { {} }
24
- @process_text ||= -> (t) { t }
25
- @process_href ||= -> (h) { h }
26
- @process_options ||= -> (o) { o }
23
+ @options ||= ->(**) { {} }
24
+ @process_text ||= ->(t) { t }
25
+ @process_href ||= ->(h) { h }
26
+ @process_options ||= ->(o) { o }
27
27
 
28
28
  Super::Link.new(
29
29
  @process_text.call(@text.call(**kwargs)),
@@ -4,10 +4,7 @@ module Super
4
4
  class Navigation
5
5
  def initialize
6
6
  @builder = Builder.new
7
- result = yield @builder
8
- if result.is_a?(Array)
9
- Useful::Deprecation["0.22"].deprecation_warning("returning an array", "calling a Super::Navigation builder method defines the navigation")
10
- end
7
+ yield @builder
11
8
  end
12
9
 
13
10
  def definition
@@ -155,10 +152,17 @@ module Super
155
152
  end
156
153
  end
157
154
 
158
- def header(routes); end
159
- def no_routes(routes, filter); end
160
- def result; end
161
- def section_title(title); end
155
+ def header(routes)
156
+ end
157
+
158
+ def no_routes(routes, filter)
159
+ end
160
+
161
+ def result
162
+ end
163
+
164
+ def section_title(title)
165
+ end
162
166
  end
163
167
  end
164
168
  end
data/lib/super/partial.rb CHANGED
@@ -2,18 +2,6 @@
2
2
 
3
3
  module Super
4
4
  class Partial
5
- def self.render(partialish, template:)
6
- if partialish.respond_to?(:to_partial_path)
7
- if partialish.respond_to?(:locals)
8
- template.render(partialish, partialish.locals)
9
- else
10
- template.render(partialish)
11
- end
12
- else
13
- partialish
14
- end
15
- end
16
-
17
5
  def initialize(path, locals: {})
18
6
  @to_partial_path = path
19
7
  @locals = locals
data/lib/super/plugin.rb CHANGED
@@ -27,8 +27,8 @@ module Super
27
27
  end
28
28
 
29
29
  def classes_ordered
30
- each_node = -> (&b) { @ordering.each_key(&b) }
31
- each_child = -> (cb, &b) { @ordering[cb].each(&b) }
30
+ each_node = ->(&b) { @ordering.each_key(&b) }
31
+ each_child = ->(cb, &b) { @ordering[cb].each(&b) }
32
32
 
33
33
  TSort.tsort(each_node, each_child)
34
34
  end
data/lib/super/railtie.rb CHANGED
@@ -14,6 +14,7 @@ module Super
14
14
  initializer "super.inclusion" do
15
15
  ActiveSupport.on_load(:action_view) do
16
16
  include Super::FormBuilderHelper
17
+ include Super::RenderHelper
17
18
  end
18
19
  end
19
20
 
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ # typed: false
3
+
4
+ module Super::RenderHelper
5
+ def super_render(*args, **kwargs, &block)
6
+ if args.size >= 1
7
+ renderable = args.first
8
+
9
+ case renderable
10
+ when ActiveSupport::SafeBuffer
11
+ return renderable
12
+ when Super::Partial
13
+ return render(*args, **kwargs, &block)
14
+ when Super::Link
15
+ return renderable.to_link(self, kwargs)
16
+ when Super::ViewChain
17
+ return renderable.handle_super_render(self, kwargs)
18
+ end
19
+ end
20
+
21
+ render(*args, **kwargs, &block)
22
+ end
23
+
24
+ def super_resolve_renderable(renderable)
25
+ if renderable.is_a?(Symbol)
26
+ instance_variable_get(renderable)
27
+ else
28
+ renderable
29
+ end
30
+ end
31
+ end
data/lib/super/reset.rb CHANGED
@@ -10,12 +10,7 @@ module Super
10
10
  _generate_paths_by_default: true,
11
11
 
12
12
  # Defined in Super::SubstructureController
13
- navigation: true,
14
- page_title: true,
15
-
16
- # Defined in Super::ApplicationController
17
- current_action: true,
18
- with_current_action: true,
13
+ page_title: true
19
14
 
20
15
  # Keep all of the ones in Super::SitewideController
21
16
  }
@@ -21,7 +21,7 @@ module Super
21
21
  end
22
22
 
23
23
  def ignore_foreign_keys
24
- @rejects.push(-> (attribute_name) { is_foreign_key[attribute_name] })
24
+ @rejects.push(->(attribute_name) { is_foreign_key[attribute_name] })
25
25
  self
26
26
  end
27
27
 
@@ -69,10 +69,10 @@ module Super
69
69
  def is_foreign_key
70
70
  @is_foreign_key ||=
71
71
  @model
72
- .reflect_on_all_associations
73
- .select { |a| a.macro == :belongs_to }
74
- .map { |a| [a.foreign_key, true] }
75
- .to_h
72
+ .reflect_on_all_associations
73
+ .select { |a| a.macro == :belongs_to }
74
+ .map { |a| [a.foreign_key, true] }
75
+ .to_h
76
76
  end
77
77
  end
78
78
  end
data/lib/super/schema.rb CHANGED
@@ -41,7 +41,7 @@ module Super
41
41
  end
42
42
 
43
43
  def each(&block)
44
- if block_given?
44
+ if block
45
45
  return @backing.each(&block)
46
46
  end
47
47
 
@@ -65,7 +65,7 @@ module Super
65
65
  inside = {}
66
66
  @backing = inside
67
67
  yield
68
- return inside
68
+ inside
69
69
  ensure
70
70
  @backing = outside
71
71
  inside
data/lib/super/sort.rb CHANGED
@@ -99,7 +99,7 @@ module Super
99
99
  @default.map do |attribute_name, direction|
100
100
  {
101
101
  a: attribute_name,
102
- d: direction,
102
+ d: direction
103
103
  }
104
104
  end
105
105
  end
@@ -5,9 +5,7 @@ require "active_support/deprecation"
5
5
  module Super
6
6
  module Useful
7
7
  class Deprecation
8
- VERSIONS = {
9
- "0.22" => ActiveSupport::Deprecation.new("0.22", "Super")
10
- }
8
+ VERSIONS = {}
11
9
  private_constant :VERSIONS
12
10
 
13
11
  def self.[](version)
@@ -24,7 +24,7 @@ module Super
24
24
  end
25
25
 
26
26
  def when(*keys, &block)
27
- if !block_given?
27
+ if !block
28
28
  raise Error::ArgumentError, "must receive block"
29
29
  end
30
30
 
@@ -24,7 +24,7 @@ module Super
24
24
  def chain_to_i18n(chain)
25
25
  head, *tail = chain
26
26
 
27
- [head, { default: tail }]
27
+ [head, {default: tail}]
28
28
  end
29
29
 
30
30
  def i18n_with_fallback(prefix, optional, suffix)
data/lib/super/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Super
4
- VERSION = "0.21.0"
4
+ VERSION = "0.22.0"
5
5
  end
@@ -26,6 +26,25 @@ module Super
26
26
  chain.empty?
27
27
  end
28
28
 
29
+ def handle_super_render(template, local_assigns, &block)
30
+ name, current = shift
31
+ current = template.super_resolve_renderable(current)
32
+
33
+ if !current
34
+ Rails.logger.warn do
35
+ "Super::ViewChain encountered a nil view: #{name.inspect}."
36
+ end
37
+ end
38
+
39
+ if empty?
40
+ template.super_render(current)
41
+ else
42
+ template.super_render(current) do
43
+ template.concat(template.super_render(self))
44
+ end
45
+ end
46
+ end
47
+
29
48
  private
30
49
 
31
50
  def chain
data/lib/super.rb CHANGED
@@ -51,6 +51,7 @@ require "super/panel"
51
51
  require "super/partial"
52
52
  require "super/plugin"
53
53
  require "super/query"
54
+ require "super/render_helper"
54
55
  require "super/reorderable_hash"
55
56
  require "super/reset"
56
57
  require "super/schema"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-05 00:00:00.000000000 Z
11
+ date: 2023-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -212,6 +212,7 @@ files:
212
212
  - app/assets/javascripts/super/application.js
213
213
  - app/assets/stylesheets/super/application.css
214
214
  - app/controllers/super/application_controller.rb
215
+ - app/controllers/super/foundation_controller.rb
215
216
  - app/controllers/super/sitewide_controller.rb
216
217
  - app/controllers/super/substructure_controller.rb
217
218
  - app/controllers/super/view_controller.rb
@@ -312,6 +313,7 @@ files:
312
313
  - lib/super/plugin.rb
313
314
  - lib/super/query.rb
314
315
  - lib/super/railtie.rb
316
+ - lib/super/render_helper.rb
315
317
  - lib/super/reorderable_hash.rb
316
318
  - lib/super/reset.rb
317
319
  - lib/super/schema.rb