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: {}, field: {}, show_errors: true) ⇒ Object
- #container(&block) ⇒ Object
- #flatpickr_date(attribute, options = {}) ⇒ Object
- #flatpickr_date!(attribute, label: {}, field: {}, show_errors: true) ⇒ Object
- #flatpickr_datetime(attribute, options = {}) ⇒ Object
- #flatpickr_datetime!(attribute, label: {}, field: {}, show_errors: true) ⇒ Object
- #flatpickr_time(attribute, options = {}) ⇒ Object
- #flatpickr_time!(attribute, 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: {}, field: {}, show_errors: true) ⇒ Object
- #rich_text_area(attribute, options = {}) ⇒ Object
- #rich_text_area!(attribute, label: {}, field: {}, show_errors: true) ⇒ Object
- #select(attribute, choices, options = {}, html_options = {}, &block) ⇒ Object
- #select!(attribute, collection, label: {}, field: {}, show_errors: true) ⇒ Object
- #submit(value = nil, options = {}) ⇒ Object
- #text_field(attribute, options = {}) ⇒ Object
- #text_field!(attribute, 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: {}, field: {}, show_errors: true) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/super/form/builder.rb', line 174 def check_box!(attribute, checked_value = "1", unchecked_value = "0", 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, nil, label), "</div>".html_safe, show_errors && inline_errors(attribute), ]) end end |
#container(&block) ⇒ Object
170 171 172 |
# File 'lib/super/form/builder.rb', line 170 def container(&block) @template.content_tag(:div, class: "super-field-group", &block) end |
#flatpickr_date(attribute, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/super/form/builder.rb', line 61 def flatpickr_date(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] || {}) @builder.text_field(attribute, ) end |
#flatpickr_date!(attribute, label: {}, field: {}, show_errors: true) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/super/form/builder.rb', line 188 def flatpickr_date!(attribute, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, label), %(<div class="mt-1">).html_safe, public_send(:flatpickr_date, attribute, field), show_errors && inline_errors(attribute), %(</div>).html_safe, ]) end end |
#flatpickr_datetime(attribute, options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/super/form/builder.rb', line 78 def flatpickr_datetime(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] || {}) @builder.text_field(attribute, ) end |
#flatpickr_datetime!(attribute, label: {}, field: {}, show_errors: true) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/super/form/builder.rb', line 200 def flatpickr_datetime!(attribute, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, label), %(<div class="mt-1">).html_safe, public_send(:flatpickr_datetime, attribute, field), show_errors && inline_errors(attribute), %(</div>).html_safe, ]) end end |
#flatpickr_time(attribute, options = {}) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/super/form/builder.rb', line 97 def flatpickr_time(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] || {}) @builder.text_field(attribute, ) end |
#flatpickr_time!(attribute, label: {}, field: {}, show_errors: true) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/super/form/builder.rb', line 212 def flatpickr_time!(attribute, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, label), %(<div class="mt-1">).html_safe, public_send(:flatpickr_time, 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
117 118 119 120 121 122 |
# File 'lib/super/form/builder.rb', line 117 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: {}, field: {}, show_errors: true) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/super/form/builder.rb', line 224 def password_field!(attribute, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, 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
124 125 126 127 128 129 |
# File 'lib/super/form/builder.rb', line 124 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: {}, field: {}, show_errors: true) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/super/form/builder.rb', line 236 def rich_text_area!(attribute, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, 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
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/super/form/builder.rb', line 131 def select(attribute, choices, = {}, = {}, &block) , defaults = split_defaults(, include_blank: true) = defaults.merge() , html_defaults = split_defaults(, class: "super-input super-input-select-field") [:class] = join_classes(html_defaults[:class], [:class]) parts = [ %(<div class="super-input-select">).html_safe, @builder.select(attribute, choices, , , &block), <<~HTML.html_safe, @template.render("super/feather/chevron_down"), <<~HTML.html_safe, </span> </div> HTML %(</div>).html_safe, ] @template.safe_join(parts) end |
#select!(attribute, collection, label: {}, field: {}, show_errors: true) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/super/form/builder.rb', line 248 def select!(attribute, collection, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, 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
155 156 157 158 159 160 161 |
# File 'lib/super/form/builder.rb', line 155 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
163 164 165 166 167 168 |
# File 'lib/super/form/builder.rb', line 163 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: {}, field: {}, show_errors: true) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/super/form/builder.rb', line 260 def text_field!(attribute, label: {}, field: {}, show_errors: true) container do compact_join([ public_send(:label, attribute, label), %(<div class="mt-1">).html_safe, public_send(:text_field, attribute, field), show_errors && inline_errors(attribute), %(</div>).html_safe, ]) end end |