Class: Kube::Station::FomanticFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Kube::Station::FomanticFormBuilder
- Defined in:
- app/helpers/kube/station/fomantic_form_builder.rb
Constant Summary collapse
- COLUMN_WORDS =
%w[ one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen ].freeze
Instance Method Summary collapse
-
#check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
────────────────────────────────────────────────────────────────────────── Check box ──────────────────────────────────────────────────────────────────────────.
-
#emoji_field(attribute, options = {}) ⇒ Object
────────────────────────────────────────────────────────────────────────── Emoji picker ──────────────────────────────────────────────────────────────────────────.
-
#error_message(header, messages = []) ⇒ Object
────────────────────────────────────────────────────────────────────────── Form-level message helpers ──────────────────────────────────────────────────────────────────────────.
-
#fields_group(options = {}, &block) ⇒ Object
────────────────────────────────────────────────────────────────────────── fields_group — wraps children in <div class=“fields …”>.
-
#file_field(attribute, options = {}) ⇒ Object
────────────────────────────────────────────────────────────────────────── File field ──────────────────────────────────────────────────────────────────────────.
-
#hidden_field(attribute, options = {}) ⇒ Object
────────────────────────────────────────────────────────────────────────── Hidden field (no wrapper) ──────────────────────────────────────────────────────────────────────────.
- #info_message(header, messages = []) ⇒ Object
-
#label(attribute, text = nil, options = {}, &block) ⇒ Object
────────────────────────────────────────────────────────────────────────── Label override — produces a plain <label> (called internally too) ──────────────────────────────────────────────────────────────────────────.
-
#radio_button(attribute, value, options = {}) ⇒ Object
────────────────────────────────────────────────────────────────────────── Radio button ──────────────────────────────────────────────────────────────────────────.
-
#select(attribute, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
────────────────────────────────────────────────────────────────────────── Select / Dropdown ──────────────────────────────────────────────────────────────────────────.
-
#submit(value = nil, options = {}) ⇒ Object
────────────────────────────────────────────────────────────────────────── Submit button ──────────────────────────────────────────────────────────────────────────.
- #success_message(header, body = nil) ⇒ Object
-
#text_area(attribute, options = {}) ⇒ Object
────────────────────────────────────────────────────────────────────────── Text area ──────────────────────────────────────────────────────────────────────────.
- #warning_message(header, messages = []) ⇒ Object
Instance Method Details
#check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
──────────────────────────────────────────────────────────────────────────Check box ──────────────────────────────────────────────────────────────────────────
117 118 119 120 121 122 123 124 125 126 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 117 def check_box(attribute, = {}, checked_value = "1", unchecked_value = "0") label_text = .delete(:label) { label_for(attribute) } kind = .delete(:kind) { :checkbox } # :checkbox | :slider | :toggle fomantic_field(attribute, .merge(suppress_label: true)) do |attr, opts| opts.delete(:input_class) checkbox_html = super(attr, opts, checked_value, unchecked_value) checkbox_ui(checkbox_html, label_text, kind) end end |
#emoji_field(attribute, options = {}) ⇒ Object
──────────────────────────────────────────────────────────────────────────Emoji picker ──────────────────────────────────────────────────────────────────────────
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 77 def emoji_field(attribute, = {}) fomantic_field(attribute, ) do |attr, opts| current = object&.public_send(attr) rescue nil name = object_name ? "#{object_name}[#{attr}]" : attr.to_s @template.tag.div(data: { controller: "fui-emoji-picker" }) { @template.safe_join([ @template.hidden_field_tag(name, current, data: { fui_emoji_picker_target: "input" }), @template.tag.( type: "button", class: "ui basic button", data: { fui_emoji_picker_target: "preview", action: "click->fui-emoji-picker#toggle" } ) { (current.presence || "Pick emoji").html_safe }, @template.tag.div( style: "display:none; position:absolute; z-index:1000;", data: { fui_emoji_picker_target: "dropdown" } ) ]) } end end |
#error_message(header, messages = []) ⇒ Object
──────────────────────────────────────────────────────────────────────────Form-level message helpers ──────────────────────────────────────────────────────────────────────────
226 227 228 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 226 def (header, = []) ("error", header, ) end |
#fields_group(options = {}, &block) ⇒ Object
──────────────────────────────────────────────────────────────────────────fields_group — wraps children in <div class=“fields …”>
Options:
equal_width: Boolean – adds "equal width"
inline: Boolean – adds "inline"
count: Integer – "N fields" (evenly divided)
──────────────────────────────────────────────────────────────────────────
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 203 def fields_group( = {}, &block) equal_width = .delete(:equal_width) inline = .delete(:inline) count = .delete(:count) extra = .delete(:class) count_word = COLUMN_WORDS[count.to_i - 1] if count css = class_names( count_word, "fields", ("equal width" if equal_width), ("inline" if inline), extra ) @template.tag.div(class: css, &block) end |
#file_field(attribute, options = {}) ⇒ Object
──────────────────────────────────────────────────────────────────────────File field ──────────────────────────────────────────────────────────────────────────
146 147 148 149 150 151 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 146 def file_field(attribute, = {}) fomantic_field(attribute, ) do |attr, opts| opts.delete(:input_class) super(attr, opts) end end |
#hidden_field(attribute, options = {}) ⇒ Object
──────────────────────────────────────────────────────────────────────────Hidden field (no wrapper) ──────────────────────────────────────────────────────────────────────────
157 158 159 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 157 def hidden_field(attribute, = {}) super(attribute, ) end |
#info_message(header, messages = []) ⇒ Object
238 239 240 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 238 def (header, = []) ("info", header, ) end |
#label(attribute, text = nil, options = {}, &block) ⇒ Object
──────────────────────────────────────────────────────────────────────────Label override — produces a plain <label> (called internally too) ──────────────────────────────────────────────────────────────────────────
190 191 192 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 190 def label(attribute, text = nil, = {}, &block) super(attribute, text, , &block) end |
#radio_button(attribute, value, options = {}) ⇒ Object
──────────────────────────────────────────────────────────────────────────Radio button ──────────────────────────────────────────────────────────────────────────
132 133 134 135 136 137 138 139 140 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 132 def (attribute, value, = {}) label_text = .delete(:label) { value.to_s.humanize } fomantic_field(attribute, .merge(suppress_label: true)) do |attr, opts| opts.delete(:input_class) radio_html = super(attr, value, opts) checkbox_ui(radio_html, label_text, :radio) end end |
#select(attribute, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
──────────────────────────────────────────────────────────────────────────Select / Dropdown ──────────────────────────────────────────────────────────────────────────
103 104 105 106 107 108 109 110 111 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 103 def select(attribute, choices = nil, = {}, = {}, &block) use_dropdown = .delete(:dropdown) fomantic_field(attribute, ) do |attr, opts| merged_html = .merge(class: class_names([:class], opts.delete(:input_class))) raw_select = super(attr, choices, opts, merged_html, &block) use_dropdown ? dropdown_wrap(raw_select) : raw_select end end |
#submit(value = nil, options = {}) ⇒ Object
──────────────────────────────────────────────────────────────────────────Submit button ──────────────────────────────────────────────────────────────────────────
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 165 def submit(value = nil, = {}) color = .delete(:color) basic = .delete(:basic) inverted = .delete(:inverted) size = .delete(:size) icon = .delete(:icon) = class_names( "ui", "button", color, size, ("basic" if basic), ("inverted" if inverted), .delete(:class) ) [:class] = icon_html = icon ? @template.tag.i(class: "#{icon} icon") : "".html_safe icon_html + super(value, ) end |
#success_message(header, body = nil) ⇒ Object
230 231 232 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 230 def (header, body = nil) ("success", header, [], body) end |
#text_area(attribute, options = {}) ⇒ Object
──────────────────────────────────────────────────────────────────────────Text area ──────────────────────────────────────────────────────────────────────────
64 65 66 67 68 69 70 71 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 64 def text_area(attribute, = {}) transparent = .delete(:transparent) fomantic_field(attribute, ) do |attr, opts| input_class = class_names(("transparent" if transparent), opts.delete(:input_class)) opts[:class] = input_class.presence super(attr, opts) end end |
#warning_message(header, messages = []) ⇒ Object
234 235 236 |
# File 'app/helpers/kube/station/fomantic_form_builder.rb', line 234 def (header, = []) ("warning", header, ) end |