super 0.20.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -48
  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 +52 -47
  6. data/app/controllers/super/foundation_controller.rb +30 -0
  7. data/app/controllers/super/sitewide_controller.rb +36 -0
  8. data/app/controllers/super/substructure_controller.rb +40 -92
  9. data/app/controllers/super/view_controller.rb +59 -0
  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_index.html.erb +8 -2
  17. data/app/views/super/application/_display_rich_text.html.erb +1 -1
  18. data/app/views/super/application/_display_show.html.erb +10 -2
  19. data/app/views/super/application/_filter.html.erb +63 -59
  20. data/app/views/super/application/_form.html.erb +1 -1
  21. data/app/views/super/application/_form_fieldset.html.erb +1 -1
  22. data/app/views/super/application/_form_has_many.html.erb +2 -2
  23. data/app/views/super/application/_form_has_one.html.erb +1 -1
  24. data/app/views/super/application/_layout.html.erb +6 -8
  25. data/app/views/super/application/_link.html.erb +1 -6
  26. data/app/views/super/application/_member_header.html.erb +1 -1
  27. data/app/views/super/application/_panel.html.erb +1 -1
  28. data/app/views/super/application/_query.html.erb +13 -12
  29. data/app/views/super/application/_site_header.html.erb +2 -2
  30. data/app/views/super/application/_sort.html.erb +18 -14
  31. data/app/views/super/application/_sort_expression.html.erb +1 -1
  32. data/app/views/super/application/_view_chain.html.erb +1 -5
  33. data/app/views/super/application/edit.html.erb +1 -1
  34. data/app/views/super/application/index.html.erb +1 -1
  35. data/app/views/super/application/new.html.erb +1 -1
  36. data/app/views/super/application/show.html.erb +1 -1
  37. data/config/locales/en.yml +3 -0
  38. data/frontend/super-frontend/dist/application.css +54 -6569
  39. data/frontend/super-frontend/dist/application.js +1201 -2092
  40. data/lib/super/action_inquirer.rb +28 -8
  41. data/lib/super/assets.rb +2 -2
  42. data/lib/super/badge.rb +8 -23
  43. data/lib/super/cheat.rb +11 -5
  44. data/lib/super/client_error.rb +4 -0
  45. data/lib/super/compatibility.rb +4 -0
  46. data/lib/super/configuration.rb +3 -0
  47. data/lib/super/display/schema_types.rb +50 -71
  48. data/lib/super/display.rb +16 -15
  49. data/lib/super/error.rb +16 -2
  50. data/lib/super/filter/form_object.rb +2 -2
  51. data/lib/super/filter/operator.rb +1 -1
  52. data/lib/super/filter/schema_types.rb +1 -1
  53. data/lib/super/form/field_transcript.rb +4 -0
  54. data/lib/super/form/schema_types.rb +2 -2
  55. data/lib/super/form/strong_params.rb +1 -1
  56. data/lib/super/form_builder/base_methods.rb +3 -9
  57. data/lib/super/form_builder/flatpickr_methods.rb +3 -3
  58. data/lib/super/form_builder.rb +19 -21
  59. data/{app/helpers → lib}/super/form_builder_helper.rb +13 -2
  60. data/lib/super/link.rb +15 -6
  61. data/lib/super/link_builder.rb +4 -4
  62. data/lib/super/navigation.rb +49 -45
  63. data/lib/super/partial.rb +0 -12
  64. data/lib/super/plugin.rb +2 -2
  65. data/lib/super/query.rb +61 -0
  66. data/lib/super/{engine.rb → railtie.rb} +8 -1
  67. data/lib/super/render_helper.rb +31 -0
  68. data/lib/super/reset.rb +7 -5
  69. data/lib/super/schema/guesser.rb +5 -5
  70. data/lib/super/schema.rb +10 -4
  71. data/lib/super/sort.rb +2 -4
  72. data/lib/super/useful/deprecations.rb +16 -0
  73. data/lib/super/useful/enum.rb +1 -1
  74. data/lib/super/useful/i19.rb +1 -1
  75. data/lib/super/version.rb +1 -1
  76. data/lib/super/view_chain.rb +33 -4
  77. data/lib/super.rb +9 -2
  78. metadata +11 -49
  79. data/config/routes.rb +0 -4
  80. data/lib/super/query/form_object.rb +0 -48
@@ -19,7 +19,7 @@ module Super
19
19
  # https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html
20
20
  class FormBuilder < ActionView::Helpers::FormBuilder
21
21
  FIELD_ERROR_PROC = proc { |html_tag, instance| html_tag }
22
- FORM_BUILDER_DEFAULTS = { builder: self }.freeze
22
+ FORM_BUILDER_DEFAULTS = {builder: self}.freeze
23
23
 
24
24
  def super(**options)
25
25
  @super_wrappers ||= Wrappers.new(self, @template)
@@ -68,29 +68,27 @@ module Super
68
68
  elsif type == :block
69
69
  definition_last.push("&#{name}")
70
70
  call_last.push("&#{name}")
71
- else
72
- if type == :req
73
- definition.push(name.to_s)
71
+ elsif type == :req
72
+ definition.push(name.to_s)
73
+ call.push(name.to_s)
74
+ elsif type == :opt || type == :key
75
+ if !optionals.key?(name)
76
+ raise Super::Error::ArgumentError, "Form bang method has optional argument, but doesn't know the default value: #{name}"
77
+ end
78
+
79
+ default_value = optionals[name]
80
+
81
+ if type == :opt
82
+ definition.push("#{name} = #{default_value}")
74
83
  call.push(name.to_s)
75
- elsif type == :opt || type == :key
76
- if !optionals.key?(name)
77
- raise Super::Error::ArgumentError, "Form bang method has optional argument, but doesn't know the default value: #{name}"
78
- end
79
-
80
- default_value = optionals[name]
81
-
82
- if type == :opt
83
- definition.push("#{name} = #{default_value}")
84
- call.push(name.to_s)
85
- elsif type == :key
86
- definition.push("#{name}: #{default_value}")
87
- call.push("#{name}: #{name}")
88
- else
89
- raise Super::Error::ArgumentError, "Form bang method has a unprocessable argument with name #{name}"
90
- end
84
+ elsif type == :key
85
+ definition.push("#{name}: #{default_value}")
86
+ call.push("#{name}: #{name}")
91
87
  else
92
- raise Super::Error::ArgumentError, "Form bang method has keyword argument type #{type} and name #{name}"
88
+ raise Super::Error::ArgumentError, "Form bang method has a unprocessable argument with name #{name}"
93
89
  end
90
+ else
91
+ raise Super::Error::ArgumentError, "Form bang method has keyword argument type #{type} and name #{name}"
94
92
  end
95
93
  end
96
94
 
@@ -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,18 @@ 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
+ ensure
29
+ ActionView::Base.field_error_proc = original
30
+ end
31
+
32
+ # Super's version of `#fields_for`
33
+ def super_fields_for(*args, **options, &block)
34
+ original = ActionView::Base.field_error_proc
35
+ ActionView::Base.field_error_proc = FormBuilder::FIELD_ERROR_PROC
36
+
37
+ options[:builder] ||= FormBuilder
38
+ fields_for(*args, **options, &block)
28
39
  ensure
29
40
  ActionView::Base.field_error_proc = original
30
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,14 +4,11 @@ module Super
4
4
  class Navigation
5
5
  def initialize
6
6
  @builder = Builder.new
7
- @definition = yield @builder
8
- if !@definition.is_a?(Array)
9
- @definition = [@definition]
10
- end
7
+ yield @builder
11
8
  end
12
9
 
13
10
  def definition
14
- return @defs if instance_variable_defined?(:@defs)
11
+ return @definition if instance_variable_defined?(:@definition)
15
12
 
16
13
  searcher = RouteFormatterButReallySearcher.new
17
14
  inspector = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
@@ -19,37 +16,12 @@ module Super
19
16
  all_matches = searcher.matches
20
17
  unused_matches = all_matches.each_with_object({}) { |match, hash| hash[match] = true }
21
18
 
22
- defs = expand_proc_syntax_sugar(@definition)
23
- defs = validate_and_determine_explicit_links(defs, unused_matches)
24
- @defs = expand_directives(defs, all_matches, unused_matches.keys)
19
+ defs = validate_and_determine_explicit_links(@builder.build, unused_matches)
20
+ @definition = expand_directives(defs, all_matches, unused_matches.keys)
25
21
  end
26
22
 
27
23
  private
28
24
 
29
- # This expands the syntax sugar that allows `nav.menu("Name")[nav.link(Item)]`
30
- def expand_proc_syntax_sugar(definition)
31
- definition.map do |link_or_menu_or_rest_or_menuproc|
32
- link_or_menu_or_rest =
33
- if link_or_menu_or_rest_or_menuproc.is_a?(Proc)
34
- link_or_menu_or_rest_or_menuproc.call
35
- else
36
- link_or_menu_or_rest_or_menuproc
37
- end
38
-
39
- if link_or_menu_or_rest.is_a?(Menu)
40
- link_or_menu_or_rest.links = link_or_menu_or_rest.links.map do |menu_item|
41
- if menu_item.is_a?(Proc)
42
- menu_item.call
43
- else
44
- menu_item
45
- end
46
- end
47
- end
48
-
49
- link_or_menu_or_rest
50
- end
51
- end
52
-
53
25
  def validate_and_determine_explicit_links(definition, unused_links)
54
26
  definition.each do |link_or_menu_or_rest|
55
27
  if link_or_menu_or_rest.is_a?(Super::Link)
@@ -103,31 +75,56 @@ module Super
103
75
  Menu = Struct.new(:title, :links)
104
76
 
105
77
  class Builder
78
+ def initialize
79
+ @links = []
80
+ @menu_level = 0
81
+ end
82
+
83
+ def build
84
+ @links
85
+ end
86
+
106
87
  def link(model, **kwargs)
107
88
  text = model.model_name.human.pluralize
108
89
  parts = Super::Link.polymorphic_parts(model)
109
90
 
110
- Super::Link.new(text, parts, **kwargs)
91
+ @links.push(Super::Link.new(text, parts, **kwargs))
92
+ self
111
93
  end
112
94
 
113
95
  def link_to(*args, **kwargs)
114
- Super::Link.new(*args, **kwargs)
96
+ @links.push(Super::Link.new(*args, **kwargs))
97
+ self
115
98
  end
116
99
 
117
- def menu(title, *links)
118
- menu = Menu.new(title, links)
119
- proc do |*more_links|
120
- menu.links += more_links
121
- menu
100
+ def menu(title)
101
+ if @menu_level > 0
102
+ raise Super::Error::ArgumentError, "Navigation menus can't be nested"
122
103
  end
104
+
105
+ begin
106
+ @menu_level += 1
107
+ original_links = @links
108
+ @links = []
109
+ yield
110
+ menu_links = @links
111
+ ensure
112
+ @links = original_links
113
+ @menu_level -= 1
114
+ end
115
+
116
+ @links.push(Menu.new(title, menu_links))
117
+ self
123
118
  end
124
119
 
125
120
  def rest
126
- REST
121
+ @links.push(REST)
122
+ self
127
123
  end
128
124
 
129
125
  def all
130
- ALL
126
+ @links.push(ALL)
127
+ self
131
128
  end
132
129
  end
133
130
 
@@ -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
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ class Query
5
+ def initialize(model:, params:, current_path:)
6
+ @model = model
7
+ @params = params
8
+ @path = current_path
9
+ @addons = {}
10
+ @backwards_addons = {}
11
+ end
12
+
13
+ attr_reader :addons
14
+ attr_reader :model
15
+ attr_reader :params
16
+ attr_reader :path
17
+ attr_reader :backwards_addons
18
+
19
+ private :model
20
+ private :params
21
+ private :backwards_addons
22
+
23
+ def build(klass, namespace:, **additional_initialization_arguments)
24
+ params_for_querier =
25
+ params.fetch(namespace) { ActiveSupport::HashWithIndifferentAccess.new }
26
+
27
+ instance = klass.new(
28
+ model: model,
29
+ params: params_for_querier,
30
+ **additional_initialization_arguments
31
+ )
32
+
33
+ addons[namespace] = instance
34
+ backwards_addons[instance] = namespace
35
+ instance
36
+ end
37
+
38
+ def namespace_for(query_form_object)
39
+ backwards_addons.fetch(query_form_object)
40
+ end
41
+
42
+ def form_options
43
+ {
44
+ url: path,
45
+ method: :get
46
+ }
47
+ end
48
+
49
+ def apply_changes(records)
50
+ addons.each_value do |addon|
51
+ records = addon.apply_changes(records)
52
+ end
53
+
54
+ records
55
+ end
56
+
57
+ def to_partial_path
58
+ "query"
59
+ end
60
+ end
61
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Super
4
4
  # Configures the host Rails app to work with Super
5
- class Engine < ::Rails::Engine
5
+ class Railtie < ::Rails::Engine
6
6
  isolate_namespace Super
7
7
 
8
8
  initializer "super.assets.precompile" do |app|
@@ -11,6 +11,13 @@ module Super
11
11
  end
12
12
  end
13
13
 
14
+ initializer "super.inclusion" do
15
+ ActiveSupport.on_load(:action_view) do
16
+ include Super::FormBuilderHelper
17
+ include Super::RenderHelper
18
+ end
19
+ end
20
+
14
21
  config.to_prepare do
15
22
  Super::Plugin::Registry.controller.ordered do |klass, method_name|
16
23
  Super::ApplicationController.public_send(method_name, klass)
@@ -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,9 @@ module Super
10
10
  _generate_paths_by_default: true,
11
11
 
12
12
  # Defined in Super::SubstructureController
13
- navigation: true,
14
- page_title: true,
13
+ page_title: true
15
14
 
16
- # Defined in Super::ApplicationController
17
- current_action: true,
18
- with_current_action: true,
15
+ # Keep all of the ones in Super::SitewideController
19
16
  }
20
17
 
21
18
  included do
@@ -27,6 +24,11 @@ module Super
27
24
  undef_method :update
28
25
  undef_method :destroy
29
26
 
27
+ Super::ViewController.private_instance_methods(false).each do |imethod|
28
+ next if KEEP.key?(imethod)
29
+ undef_method imethod
30
+ end
31
+
30
32
  Super::SubstructureController.private_instance_methods(false).each do |imethod|
31
33
  next if KEEP.key?(imethod)
32
34
  undef_method imethod
@@ -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
@@ -14,8 +14,9 @@ module Super
14
14
  class Fields
15
15
  include Enumerable
16
16
 
17
- def initialize
17
+ def initialize(transform_value_on_set: nil)
18
18
  @backing = {}
19
+ @transform_value_on_set = transform_value_on_set
19
20
  end
20
21
 
21
22
  def [](key)
@@ -23,7 +24,12 @@ module Super
23
24
  end
24
25
 
25
26
  def []=(key, value)
26
- @backing[key] = value
27
+ @backing[key] =
28
+ if @transform_value_on_set
29
+ @transform_value_on_set.call(value)
30
+ else
31
+ value
32
+ end
27
33
  end
28
34
 
29
35
  def keys
@@ -35,7 +41,7 @@ module Super
35
41
  end
36
42
 
37
43
  def each(&block)
38
- if block_given?
44
+ if block
39
45
  return @backing.each(&block)
40
46
  end
41
47
 
@@ -59,7 +65,7 @@ module Super
59
65
  inside = {}
60
66
  @backing = inside
61
67
  yield
62
- return inside
68
+ inside
63
69
  ensure
64
70
  @backing = outside
65
71
  inside
data/lib/super/sort.rb CHANGED
@@ -7,11 +7,9 @@ module Super
7
7
 
8
8
  def initialize(model:, params:, default:, sortable_columns:)
9
9
  @model = model
10
- @params = params.dup
10
+ @params = params
11
11
  @default = default
12
12
  @sortable_columns = sortable_columns.map(&:to_s)
13
-
14
- @params.permit!
15
13
  end
16
14
 
17
15
  attr_reader :sortable_columns
@@ -101,7 +99,7 @@ module Super
101
99
  @default.map do |attribute_name, direction|
102
100
  {
103
101
  a: attribute_name,
104
- d: direction,
102
+ d: direction
105
103
  }
106
104
  end
107
105
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/deprecation"
4
+
5
+ module Super
6
+ module Useful
7
+ class Deprecation
8
+ VERSIONS = {}
9
+ private_constant :VERSIONS
10
+
11
+ def self.[](version)
12
+ VERSIONS.fetch(version)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -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.20.0"
4
+ VERSION = "0.22.0"
5
5
  end
@@ -6,10 +6,6 @@ module Super
6
6
  @data = ReorderableHash.new(chain)
7
7
  end
8
8
 
9
- def chain
10
- @chain ||= @data.values
11
- end
12
-
13
9
  def insert(*args, **kwargs)
14
10
  if instance_variable_defined?(:@chain)
15
11
  raise Error::ViewChain::ChainAlreadyStarted
@@ -21,5 +17,38 @@ module Super
21
17
  def to_partial_path
22
18
  "view_chain"
23
19
  end
20
+
21
+ def shift
22
+ chain.shift
23
+ end
24
+
25
+ def empty?
26
+ chain.empty?
27
+ end
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
+
48
+ private
49
+
50
+ def chain
51
+ @chain ||= @data.to_h
52
+ end
24
53
  end
25
54
  end