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
@@ -24,24 +24,44 @@ module Super
24
24
  "delete" => %w[destroy],
25
25
 
26
26
  "collection" => %w[index new create],
27
- "member" => %w[show edit update destroy],
27
+ "member" => %w[show edit update destroy]
28
28
  }
29
29
  end
30
30
 
31
31
  # @return [ActionInquirer]
32
- def self.index!; new(default_for_resources, "index"); end
32
+ def self.index!
33
+ new(default_for_resources, "index")
34
+ end
35
+
33
36
  # @return [ActionInquirer]
34
- def self.show!; new(default_for_resources, "show"); end
37
+ def self.show!
38
+ new(default_for_resources, "show")
39
+ end
40
+
35
41
  # @return [ActionInquirer]
36
- def self.new!; new(default_for_resources, "new"); end
42
+ def self.new!
43
+ new(default_for_resources, "new")
44
+ end
45
+
37
46
  # @return [ActionInquirer]
38
- def self.edit!; new(default_for_resources, "edit"); end
47
+ def self.edit!
48
+ new(default_for_resources, "edit")
49
+ end
50
+
39
51
  # @return [ActionInquirer]
40
- def self.create!; new(default_for_resources, "create"); end
52
+ def self.create!
53
+ new(default_for_resources, "create")
54
+ end
55
+
41
56
  # @return [ActionInquirer]
42
- def self.update!; new(default_for_resources, "update"); end
57
+ def self.update!
58
+ new(default_for_resources, "update")
59
+ end
60
+
43
61
  # @return [ActionInquirer]
44
- def self.destroy!; new(default_for_resources, "destroy"); end
62
+ def self.destroy!
63
+ new(default_for_resources, "destroy")
64
+ end
45
65
 
46
66
  def initialize(categories_and_their_actions, action)
47
67
  @categories = categories_and_their_actions.keys.map(&:to_s)
data/lib/super/assets.rb CHANGED
@@ -16,7 +16,7 @@ module Super
16
16
  end
17
17
 
18
18
  def self.use_webpacker(assets, grep: nil)
19
- assets = [assets] if !assets.kind_of?(Array)
19
+ assets = [assets] if !assets.is_a?(Array)
20
20
 
21
21
  assets.map do |asset|
22
22
  grep_matches = grep && asset === grep
@@ -29,7 +29,7 @@ module Super
29
29
  end
30
30
 
31
31
  def self.use_sprockets(assets, grep: nil)
32
- assets = [assets] if !assets.kind_of?(Array)
32
+ assets = [assets] if !assets.is_a?(Array)
33
33
 
34
34
  assets.map do |asset|
35
35
  grep_matches = grep && asset === grep
data/lib/super/badge.rb CHANGED
@@ -9,46 +9,22 @@ module Super
9
9
  yellow: "bg-yellow-400 text-black",
10
10
  green: "bg-green-700 text-white",
11
11
  blue: "bg-blue-700 text-white",
12
- purple: "bg-purple-800 text-white",
12
+ purple: "bg-purple-800 text-white"
13
13
  }
14
14
 
15
- def initialize(text, style: nil, styles: nil)
16
- @text = text
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}")
15
+ def initialize(text, style:)
16
+ if !STYLES.key?(style)
17
+ raise Super::Error::Initialization, "`style:` must be one of #{STYLES.keys.inspect}"
26
18
  end
19
+
20
+ @text = text
21
+ @style = style
27
22
  end
28
23
 
29
24
  def styles
30
25
  return @styles if instance_variable_defined?(:@styles)
31
- @styles =
32
- if requested_styles.delete(:reset)
33
- []
34
- else
35
- COMMON_STYLES
36
- end
37
-
38
- if requested_styles.empty?
39
- @styles += [STYLES[:light]]
40
- else
41
- requested_styles.each do |style|
42
- @styles +=
43
- if STYLES.key?(style)
44
- [STYLES[style]]
45
- else
46
- [style]
47
- end
48
- end
49
- end
50
26
 
51
- @styles
27
+ @styles = COMMON_STYLES + [STYLES.fetch(@style)]
52
28
  end
53
29
 
54
30
  def to_s
data/lib/super/cheat.rb CHANGED
@@ -5,16 +5,17 @@ module Super
5
5
  def controller
6
6
  paths = %w[
7
7
  ../../app/controllers/super/application_controller.rb
8
- ../../app/controllers/super/substructure_controller.rb
9
8
  ../../app/controllers/super/view_controller.rb
10
9
  ../../app/controllers/super/sitewide_controller.rb
10
+ ../../app/controllers/super/substructure_controller.rb
11
+ ../../app/controllers/super/foundation_controller.rb
11
12
  ]
12
13
  methods =
13
14
  paths
14
- .map { |f| File.read(File.expand_path(f, __dir__)) }
15
- .flat_map { |content| content.scan(/^\s+(?:helper_method )?def .*$/) }
16
- .reject { |method| method =~ /\bdef self\./ }
17
- .map { |method| method.strip.sub(/^(?:helper_method )?def /, "#") }
15
+ .map { |f| File.read(File.expand_path(f, __dir__)) }
16
+ .flat_map { |content| content.scan(/^\s+(?:helper_method )?def .*$/) }
17
+ .reject { |method| method =~ /\bdef self\./ }
18
+ .map { |method| method.strip.sub(/^(?:helper_method )?def /, "#") }
18
19
 
19
20
  puts "== Super::ApplicationController"
20
21
  puts methods.join("\n")
@@ -6,9 +6,13 @@ module Super
6
6
  # See also `Super::Error`
7
7
  class ClientError < StandardError
8
8
  class BadRequest < ClientError; end
9
+
9
10
  class Unauthorized < ClientError; end
11
+
10
12
  class Forbidden < ClientError; end
13
+
11
14
  class NotFound < ClientError; end
15
+
12
16
  class UnprocessableEntity < ClientError; end
13
17
 
14
18
  module Handling
@@ -34,6 +34,10 @@ module Super
34
34
  def method_missing(method_name)
35
35
  Rails.application.routes.url_helpers.public_send(method_name)
36
36
  end
37
+
38
+ def respond_to_missing?(*args, **kwargs)
39
+ Rails.application.routes.url_helpers.respond_to?(*args, **kwargs)
40
+ end
37
41
  end
38
42
 
39
43
  klass.new
@@ -24,6 +24,9 @@ module Super
24
24
  include ActiveSupport::Configurable
25
25
 
26
26
  config_accessor(:title) { "Super Admin" }
27
+
28
+ # @!attribute [rw] index_records_per_page
29
+ # @return [Integer]
27
30
  config_accessor(:index_records_per_page) { 100 }
28
31
  config_accessor(:javascripts) do
29
32
  [Super::Assets.auto("super/application")]
@@ -12,21 +12,30 @@ module Super
12
12
  @transform_block = block
13
13
  end
14
14
 
15
- builder def real; @real = true; end
16
- builder def computed; @real = false; end
15
+ builder def real
16
+ @real = true
17
+ end
18
+ builder def computed
19
+ @real = false
20
+ end
17
21
 
18
- # @deprecated Prefer {#attribute}
19
- builder def column
20
- Useful::Deprecation["0.22"].deprecation_warning(":column", "use :attribute instead")
22
+ builder def attribute
21
23
  @type = :attribute
22
24
  end
23
- builder def attribute; @type = :attribute; end
24
- builder def record; @type = :record; end
25
- builder def none; @type = :none; end
25
+ builder def record
26
+ @type = :record
27
+ end
28
+ builder def none
29
+ @type = :none
30
+ end
26
31
 
27
- builder def ignore_nil; @ignore_nil = true; end
32
+ builder def ignore_nil
33
+ @ignore_nil = true
34
+ end
28
35
 
29
- builder def attribute_name(name); @attribute_name = name; end
36
+ builder def attribute_name(name) # standard:disable Style/TrivialAccessors
37
+ @attribute_name = name
38
+ end
30
39
 
31
40
  def build
32
41
  Built.new(
@@ -48,7 +57,9 @@ module Super
48
57
  @transform_block = transform_block
49
58
  end
50
59
 
51
- def real?; @real; end
60
+ def real?
61
+ @real
62
+ end
52
63
  attr_reader :type
53
64
  attr_reader :attribute_name
54
65
 
@@ -71,78 +82,26 @@ module Super
71
82
  end
72
83
  end
73
84
 
74
- # @deprecated
75
- class Badge
76
- extend Useful::Builder
77
-
78
- def initialize(builder)
79
- @builder = builder
80
- @whens = {}
81
- format_for_lookup(&:itself)
82
- format_for_display(&:itself)
83
- end
84
-
85
- builder_with_block def when(*patterns, &block)
86
- patterns.each do |pattern|
87
- @whens[pattern] = block
88
- end
89
- end
90
-
91
- builder_with_block def else(&block)
92
- @else = block
93
- end
94
-
95
- builder_with_block def format_for_lookup(&block)
96
- @format_for_lookup = block
97
- end
98
-
99
- builder_with_block def format_for_display(&block)
100
- @format_for_display = block
101
- end
102
-
103
- def build
104
- @builder.transform do |value|
105
- lookup_value = @format_for_lookup.call(value)
106
- block = @whens[lookup_value] || @else
107
- Super::Badge.new(
108
- @format_for_display.call(value),
109
- styles: block&.call
110
- )
111
- end
112
- @builder.build
113
- end
114
- end
115
-
116
85
  def initialize(fields:)
117
86
  @actions_called = false
118
87
  @fields = fields
119
88
  end
120
89
 
121
90
  def real(type = :attribute, &transform_block)
122
- if type == :column
123
- Useful::Deprecation["0.22"].deprecation_warning(":column", "use :attribute instead")
124
- type = :attribute
125
- end
126
-
127
91
  TYPES
128
92
  .case(type)
129
93
  .when(:attribute) { Builder.new.real.ignore_nil.attribute.transform(&transform_block) }
130
- .when(:record) { Builder.new.real.ignore_nil.record.transform(&transform_block) }
131
- .when(:none) { Builder.new.real.ignore_nil.none.transform(&transform_block) }
94
+ .when(:record) { Builder.new.real.ignore_nil.record.transform(&transform_block) }
95
+ .when(:none) { Builder.new.real.ignore_nil.none.transform(&transform_block) }
132
96
  .result
133
97
  end
134
98
 
135
99
  def computed(type = :attribute, &transform_block)
136
- if type == :column
137
- Useful::Deprecation["0.22"].deprecation_warning(":column", "use :attribute instead")
138
- type = :attribute
139
- end
140
-
141
100
  TYPES
142
101
  .case(type)
143
102
  .when(:attribute) { Builder.new.computed.ignore_nil.attribute.transform(&transform_block) }
144
- .when(:record) { Builder.new.computed.ignore_nil.record.transform(&transform_block) }
145
- .when(:none) { Builder.new.computed.ignore_nil.none.transform(&transform_block) }
103
+ .when(:record) { Builder.new.computed.ignore_nil.record.transform(&transform_block) }
104
+ .when(:none) { Builder.new.computed.ignore_nil.none.transform(&transform_block) }
146
105
  .result
147
106
  end
148
107
 
@@ -152,29 +111,26 @@ module Super
152
111
 
153
112
  def batch
154
113
  real do |value|
155
- Partial.new("batch_checkbox", locals: { value: value })
114
+ Partial.new("batch_checkbox", locals: {value: value})
156
115
  end
157
116
  end
158
117
 
159
- def string; real(&:to_s); end
118
+ def string
119
+ real(&:to_s)
120
+ end
160
121
 
161
- def timestamp; real(&:to_s); end
162
- def time; real { |value| value.strftime("%H:%M:%S") }; end
122
+ def timestamp
123
+ real(&:to_s)
124
+ end
163
125
 
164
- def rich_text
165
- computed do |value|
166
- Partial.new("display_rich_text", locals: { rich_text: value })
167
- end
126
+ def time
127
+ real { |value| value.strftime("%H:%M:%S") }
168
128
  end
169
129
 
170
- # @deprecated Use {#real} or {#computed} instead, and return an instance of {Super::Badge}
171
- def badge(*builder_methods)
172
- Useful::Deprecation["0.22"].deprecation_warning("#badge", "use #real or #computed instead, and return an instance of Super::Badge")
173
- builder_methods = %i[real ignore_nil attribute] if builder_methods.empty?
174
- builder = builder_methods.each_with_object(Builder.new) do |builder_method, builder|
175
- builder.public_send(builder_method)
130
+ def rich_text
131
+ computed do |value|
132
+ Partial.new("display_rich_text", locals: {rich_text: value})
176
133
  end
177
- Badge.new(builder)
178
134
  end
179
135
 
180
136
  def actions
data/lib/super/display.rb CHANGED
@@ -27,7 +27,7 @@ module Super
27
27
 
28
28
  def initialize
29
29
  @fields = Super::Schema::Fields.new(
30
- transform_value_on_set: -> (val) { if val.respond_to?(:build) then val.build else val end }
30
+ transform_value_on_set: ->(val) { val.respond_to?(:build) ? val.build : val }
31
31
  )
32
32
  @schema_types = SchemaTypes.new(fields: @fields)
33
33
 
@@ -62,18 +62,18 @@ module Super
62
62
 
63
63
  formatted =
64
64
  SchemaTypes::TYPES
65
- .case(formatter.type)
66
- .when(:record) do
67
- formatter.present(column, record)
68
- end
69
- .when(:attribute) do
70
- value = record.public_send(column)
71
- formatter.present(column, value)
72
- end
73
- .when(:none) do
74
- formatter.present(column)
75
- end
76
- .result
65
+ .case(formatter.type)
66
+ .when(:record) do
67
+ formatter.present(column, record)
68
+ end
69
+ .when(:attribute) do
70
+ value = record.public_send(column)
71
+ formatter.present(column, value)
72
+ end
73
+ .when(:none) do
74
+ formatter.present(column)
75
+ end
76
+ .result
77
77
 
78
78
  if formatted.respond_to?(:to_partial_path)
79
79
  if formatted.respond_to?(:locals)
data/lib/super/error.rb CHANGED
@@ -7,14 +7,19 @@ module Super
7
7
  class Error < StandardError
8
8
  # Error raised when some configuration is not set
9
9
  class UnconfiguredConfiguration < Error; end
10
+
10
11
  # Error raised when a configuration is set to a invalid value
11
12
  class InvalidConfiguration < Error; end
13
+
12
14
  # Error raised on problematic plugins, see `Super::Plugin`
13
15
  class InvalidPluginArgument < Error; end
16
+
14
17
  # Error raised on problematic ActionInquirer settings, see `Super::ActionInquirer`
15
18
  class ActionInquirerError < Error; end
19
+
16
20
  # Error raised when a `Super::Link` couldn't be found
17
21
  class LinkNotRegistered < Error; end
22
+
18
23
  # Error raised when rendering if `@view` wasn't set by the controller
19
24
  class NothingToRender < Error
20
25
  def initialize(basename)
@@ -24,23 +29,32 @@ module Super
24
29
  )
25
30
  end
26
31
  end
32
+
27
33
  # Error raised when something wasn't initialized correctly, and if there isn't
28
34
  # a more specific error
29
35
  class Initialization < Error; end
36
+
30
37
  class ArgumentError < Error; end
38
+
31
39
  class AlreadyRegistered < Error; end
40
+
32
41
  class AlreadyTranscribed < Error; end
42
+
33
43
  class NotImplementedError < Error; end
44
+
34
45
  class IncompleteBuilder < Error; end
35
46
 
36
47
  class Enum < Error
37
48
  class ImpossibleValue < Enum; end
49
+
38
50
  class ArgumentError < Enum; end
51
+
39
52
  class UndefinedCase < Enum; end
40
53
  end
41
54
 
42
55
  class ReorderableHash < Error
43
56
  class DuplicateKey < ReorderableHash; end
57
+
44
58
  class KeyError < ReorderableHash; end
45
59
  end
46
60
 
@@ -44,8 +44,8 @@ module Super
44
44
  query_parameter_keys = [NULLARY] if query_parameter_keys.empty?
45
45
  @specified_values =
46
46
  query_parameter_keys
47
- .map { |key| [key, @params[key].presence&.strip] }
48
- .to_h
47
+ .map { |key| [key, @params[key].presence&.strip] }
48
+ .to_h
49
49
 
50
50
  @specified_values.each do |key, value|
51
51
  define_singleton_method(key) { value }
@@ -57,7 +57,7 @@ module Super
57
57
  attr_reader :humanized_operator_name
58
58
 
59
59
  def behavior(&block)
60
- self.behavior = block if block_given?
60
+ self.behavior = block if block
61
61
  @behavior
62
62
  end
63
63
 
@@ -28,7 +28,7 @@ module Super
28
28
  nil
29
29
  end
30
30
 
31
- alias add push
31
+ alias_method :add, :push
32
32
 
33
33
  def each
34
34
  return enum_for(:each) if !block_given?
@@ -38,6 +38,10 @@ module Super
38
38
  @kwargs = kwargs
39
39
  @method_name
40
40
  end
41
+
42
+ def respond_to_missing?(*, **)
43
+ true
44
+ end
41
45
  end
42
46
  end
43
47
  end
@@ -79,7 +79,7 @@ module Super
79
79
  end
80
80
 
81
81
  if @extras.key?(:reader)
82
- return @extras[:reader].to_s.singularize.humanize
82
+ @extras[:reader].to_s.singularize.humanize
83
83
  end
84
84
  end
85
85
 
@@ -142,7 +142,7 @@ module Super
142
142
  end
143
143
 
144
144
  def self.define_schema_type_for(method_name)
145
- class_eval(<<~RUBY)
145
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
146
146
  def #{method_name}(*args, **kwargs)
147
147
  Direct.new(super_builder: true, method_name: :#{method_name}!, args: args, kwargs: kwargs)
148
148
  end
@@ -20,7 +20,7 @@ module Super
20
20
  def unfurl(responds_to_each_attribute)
21
21
  responds_to_each_attribute.each_attribute.map do |name, type|
22
22
  if type.nested_fields&.any?
23
- { name => [:id, *unfurl(type)] }
23
+ {name => [:id, *unfurl(type)]}
24
24
  else
25
25
  name
26
26
  end
@@ -3,7 +3,7 @@
3
3
  module Super
4
4
  class FormBuilder
5
5
  class Wrappers
6
- skipped_field_helpers = [:label, :check_box, :radio_button, :fields_for, :fields, :hidden_field, :file_field]
6
+ skipped_field_helpers = [:label, :check_box, :radio_button, :fields_for, :fields, :hidden_field]
7
7
  (ActionView::Helpers::FormBuilder.field_helpers - skipped_field_helpers).each do |builder_method_name|
8
8
  class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
9
9
  def #{builder_method_name}(attribute, options = {})
@@ -30,26 +30,20 @@ module Super
30
30
 
31
31
  def check_box!(attribute, checked_value: "1", unchecked_value: "0", label_text: nil, label: {}, field: {}, show_errors: true)
32
32
  label[:super] ||= {}
33
- label[:super] = { class: "select-none ml-1" }.merge(label[:super])
33
+ label[:super] = {class: "select-none ml-1"}.merge(label[:super])
34
34
  container do
35
35
  compact_join([
36
36
  "<div>".html_safe,
37
37
  public_send(:check_box, attribute, field, checked_value, unchecked_value),
38
38
  public_send(:label, attribute, label_text, label),
39
39
  "</div>".html_safe,
40
- show_errors && inline_errors(attribute),
40
+ show_errors && inline_errors(attribute)
41
41
  ])
42
42
  end
43
43
  end
44
44
 
45
45
  ::Super::Form::SchemaTypes.define_schema_type_for(:check_box)
46
46
 
47
- # def file_field(attribute, options = {})
48
- # end
49
-
50
- # def file_field!(attribute, label_text: nil, label: {}, field: {}, show_errors: true)
51
- # end
52
-
53
47
  def hidden_field(attribute, options = {})
54
48
  @builder.hidden_field(attribute, options)
55
49
  end
@@ -10,7 +10,7 @@ module Super
10
10
  data: {
11
11
  controller: "flatpickr",
12
12
  flatpickr_options_value: {
13
- dateFormat: "Y-m-d",
13
+ dateFormat: "Y-m-d"
14
14
  }
15
15
  }
16
16
  )
@@ -33,7 +33,7 @@ module Super
33
33
  flatpickr_options_value: {
34
34
  enableSeconds: true,
35
35
  enableTime: true,
36
- dateFormat: "Z",
36
+ dateFormat: "Z"
37
37
  }
38
38
  }
39
39
  )
@@ -57,7 +57,7 @@ module Super
57
57
  enableSeconds: true,
58
58
  enableTime: true,
59
59
  noCalendar: true,
60
- dateFormat: "H:i:S",
60
+ dateFormat: "H:i:S"
61
61
  }
62
62
  }
63
63
  )
@@ -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