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
-
#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
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/super/form/builder.rb', line 118 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
114 115 116 |
# File 'lib/super/form/builder.rb', line 114 def container(&block) @template.content_tag(:div, class: "super-field-group", &block) 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
61 62 63 64 65 66 |
# File 'lib/super/form/builder.rb', line 61 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
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/super/form/builder.rb', line 132 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
68 69 70 71 72 73 |
# File 'lib/super/form/builder.rb', line 68 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
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/super/form/builder.rb', line 144 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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/super/form/builder.rb', line 75 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
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/super/form/builder.rb', line 156 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
99 100 101 102 103 104 105 |
# File 'lib/super/form/builder.rb', line 99 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
107 108 109 110 111 112 |
# File 'lib/super/form/builder.rb', line 107 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
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/super/form/builder.rb', line 168 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 |