Class: Super::Form::Builder::Wrappers
- Inherits:
-
Object
- Object
- Super::Form::Builder::Wrappers
- Defined in:
- lib/super/form/builder.rb
Instance Method Summary collapse
- #check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #check_box!(attribute, checked_value: "1", unchecked_value: "0", label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
- #container(&block) ⇒ Object
- #date_flatpickr(attribute, options = {}) ⇒ Object
- #date_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
- #datetime_flatpickr(attribute, options = {}) ⇒ Object
- #datetime_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
-
#initialize(builder, template) ⇒ Wrappers
constructor
A new instance of Wrappers.
- #inline_errors(attribute) ⇒ Object
- #label(attribute, text = nil, options = {}, &block) ⇒ Object
- #password_field(attribute, options = {}) ⇒ Object
- #password_field!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
- #rich_text_area(attribute, options = {}) ⇒ Object
- #rich_text_area!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
- #select(attribute, choices, options = {}, html_options = {}, &block) ⇒ Object
- #select!(attribute, collection, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
- #submit(value = nil, options = {}) ⇒ Object
- #text_field(attribute, options = {}) ⇒ Object
- #text_field!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
- #time_flatpickr(attribute, options = {}) ⇒ Object
- #time_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
Constructor Details
#initialize(builder, template) ⇒ Wrappers
Returns a new instance of Wrappers.
30 31 32 33 |
# File 'lib/super/form/builder.rb', line 30 def initialize(builder, template) @builder = builder @template = template end |
Instance Method Details
#check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
57 58 59 |
# File 'lib/super/form/builder.rb', line 57 def check_box(attribute, = {}, checked_value = "1", unchecked_value = "0") @builder.check_box(attribute, , checked_value, unchecked_value) end |
#check_box!(attribute, checked_value: "1", unchecked_value: "0", label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/super/form/builder.rb', line 165 def check_box!(attribute, checked_value: "1", unchecked_value: "0", label_text: nil, label: {}, field: {}, show_errors: true) label[:super] ||= {} label[:super] = { class: "select-none ml-1" }.merge(label[:super]) container do compact_join([ "<div>".html_safe, public_send(:check_box, attribute, field, checked_value, unchecked_value), public_send(:label, attribute, label_text, label), "</div>".html_safe, show_errors && inline_errors(attribute), ]) end end |
#container(&block) ⇒ Object
161 162 163 |
# File 'lib/super/form/builder.rb', line 161 def container(&block) @template.content_tag(:div, class: "super-field-group", &block) end |
#date_flatpickr(attribute, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/super/form/builder.rb', line 61 def date_flatpickr(attribute, = {}) , defaults = split_defaults( , class: "super-input w-full", data: { controller: "flatpickr", flatpickr_options_value: { dateFormat: "Y-m-d", } } ) [:class] = join_classes(defaults[:class], [:class]) [:data] = defaults[:data].deep_merge([:data] || {}) [:value] = @builder.object.public_send(attribute).presence [:value] = [:value].iso8601 if [:value].respond_to?(:iso8601) @builder.text_field(attribute, ) end |
#date_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/super/form/builder.rb', line 179 def date_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, label_text, label), %(<div class="mt-1">).html_safe, public_send(:date_flatpickr, attribute, field), show_errors && inline_errors(attribute), %(</div>).html_safe, ]) end end |
#datetime_flatpickr(attribute, options = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/super/form/builder.rb', line 80 def datetime_flatpickr(attribute, = {}) , defaults = split_defaults( , class: "super-input w-full", data: { controller: "flatpickr", flatpickr_options_value: { enableSeconds: true, enableTime: true, dateFormat: "Z", } } ) [:class] = join_classes(defaults[:class], [:class]) [:data] = defaults[:data].deep_merge([:data] || {}) [:value] = @builder.object.public_send(attribute).presence [:value] = [:value].iso8601 if [:value].respond_to?(:iso8601) @builder.text_field(attribute, ) end |
#datetime_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/super/form/builder.rb', line 191 def datetime_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, label_text, label), %(<div class="mt-1">).html_safe, public_send(:datetime_flatpickr, attribute, field), show_errors && inline_errors(attribute), %(</div>).html_safe, ]) end end |
#inline_errors(attribute) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/super/form/builder.rb', line 35 def inline_errors(attribute) if @builder.object = InlineErrors.(@builder.object, attribute).map do |msg| error_content_tag(msg) end @template.safe_join() else error_content_tag(<<~MSG.html_safe) This form doesn't have an object, so something is probably wrong. Maybe <code>accepts_nested_attributes_for</code> isn't set up? MSG end end |
#label(attribute, text = nil, options = {}, &block) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/super/form/builder.rb', line 50 def label(attribute, text = nil, = {}, &block) , defaults = split_defaults(, class: "block") [:class] = join_classes(defaults[:class], [:class]) @builder.label(attribute, text, , &block) end |
#password_field(attribute, options = {}) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/super/form/builder.rb', line 123 def password_field(attribute, = {}) , defaults = split_defaults(, class: "super-input w-full") [:class] = join_classes(defaults[:class], [:class]) @builder.password_field(attribute, ) end |
#password_field!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/super/form/builder.rb', line 215 def password_field!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, label_text, label), %(<div class="mt-1">).html_safe, public_send(:password_field, attribute, field), show_errors && inline_errors(attribute), %(</div>).html_safe, ]) end end |
#rich_text_area(attribute, options = {}) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/super/form/builder.rb', line 130 def rich_text_area(attribute, = {}) , defaults = split_defaults(, class: "trix-content super-input w-full") [:class] = join_classes(defaults[:class], [:class]) @builder.rich_text_area(attribute, ) end |
#rich_text_area!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/super/form/builder.rb', line 227 def rich_text_area!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, label_text, label), %(<div class="mt-1">).html_safe, public_send(:rich_text_area, attribute, field), show_errors && inline_errors(attribute), %(</div>).html_safe, ]) end end |
#select(attribute, choices, options = {}, html_options = {}, &block) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/super/form/builder.rb', line 137 def select(attribute, choices, = {}, = {}, &block) , defaults = split_defaults(, include_blank: true) = defaults.merge() , html_defaults = split_defaults(, class: "super-input super-input-select") [:class] = join_classes(html_defaults[:class], [:class]) @builder.select(attribute, choices, , , &block) end |
#select!(attribute, collection, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/super/form/builder.rb', line 239 def select!(attribute, collection, label_text: nil, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, label_text, label), %(<div class="mt-1">).html_safe, public_send(:select, attribute, collection, field), show_errors && inline_errors(attribute), %(</div>).html_safe, ]) end end |
#submit(value = nil, options = {}) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/super/form/builder.rb', line 146 def submit(value = nil, = {}) value, = nil, value if value.is_a?(Hash) , defaults = split_defaults(, class: "super-button") [:class] = join_classes(defaults[:class], [:class]) @builder.submit(value, ) end |
#text_field(attribute, options = {}) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/super/form/builder.rb', line 154 def text_field(attribute, = {}) , defaults = split_defaults(, class: "super-input w-full") [:class] = join_classes(defaults[:class], [:class]) @builder.text_field(attribute, ) end |
#text_field!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/super/form/builder.rb', line 251 def text_field!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, label_text, label), %(<div class="mt-1">).html_safe, public_send(:text_field, attribute, field), show_errors && inline_errors(attribute), %(</div>).html_safe, ]) end end |
#time_flatpickr(attribute, options = {}) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/super/form/builder.rb', line 101 def time_flatpickr(attribute, = {}) , defaults = split_defaults( , class: "super-input w-full", data: { controller: "flatpickr", flatpickr_options_value: { enableSeconds: true, enableTime: true, noCalendar: true, dateFormat: "H:i:S", } } ) [:class] = join_classes(defaults[:class], [:class]) [:data] = defaults[:data].deep_merge([:data] || {}) [:value] = @builder.object.public_send(attribute).presence [:value] = [:value].strftime("%H:%M:%S") if [:value].respond_to?(:strftime) @builder.text_field(attribute, ) end |
#time_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/super/form/builder.rb', line 203 def time_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, label_text, label), %(<div class="mt-1">).html_safe, public_send(:time_flatpickr, attribute, field), show_errors && inline_errors(attribute), %(</div>).html_safe, ]) end end |