Module: Hooch::HoochHelper
- Defined in:
- lib/hooch/hooch_helper.rb
Instance Method Summary collapse
- #bind_key(key_name) ⇒ Object
- #bind_key_attrs(key_name) ⇒ Object
- #click_proxy(target = nil) ⇒ Object
- #click_proxy_hash(target = nil) ⇒ Object
- #collapsed(id, type: nil, expand_class: nil, collapse_class: nil) ⇒ Object
- #collapser(id) ⇒ Object
- #emptier(id) ⇒ Object
- #expanded(id, type: nil, expand_class: nil, collapse_class: nil) ⇒ Object
- #expander(id, expand_class: nil, collapse_class: nil) ⇒ Object
- #fake_checkbox(form_selector, field_name, field_value, toggle_form: false) ⇒ Object
- #fake_checkbox_attrs(form_selector, field_name, field_value, toggle_form: false) ⇒ Object
- #fake_deselect ⇒ Object
- #fake_deselect_attrs ⇒ Object
- #fake_select ⇒ Object
- #fake_select_attrs ⇒ Object
- #field_filler(target, value) ⇒ Object
- #field_filler_hash(target, value) ⇒ Object
- #hide_show(target, any_click_closes: false) ⇒ Object
- #hide_show_attrs(target, any_click_closes: false) ⇒ Object
- #history_pusher(key = nil, value = nil) ⇒ Object
- #history_pusher_attrs(key = nil, value = nil) ⇒ Object
- #history_replacer(new_path) ⇒ Object
- #history_replacer_attrs(new_path) ⇒ Object
- #link ⇒ Object
- #modal_closer(milliseconds: 0) ⇒ Object
- #modal_now(target, dismissable: true, delay: 0) ⇒ Object
- #modal_trigger(target, dismissable: true) ⇒ Object
- #prevent_double_click ⇒ Object
- #prevent_double_click_hash ⇒ Object
- #prevent_double_submit ⇒ Object
- #prevent_double_submit_hash ⇒ Object
- #remover(id) ⇒ Object
- #revealer(id, type: nil, highlander: false) ⇒ Object
- #revealer_attrs(id, type: nil, highlander: false) ⇒ Object
- #revealer_option(id, trigger: nil, triggers: nil) ⇒ Object
- #revealer_option_attrs(id, trigger: nil, triggers: nil) ⇒ Object
- #revealer_target_attrs(id) ⇒ Object
- #send_sort_now ⇒ Object
- #solo_sort_element(reusable: false, target_filters: nil) ⇒ Object
- #sorter(polymorphic_id: nil, recipient_filters: nil, href: nil) ⇒ Object
- #submit_proxy(target = nil) ⇒ Object
- #submit_proxy_hash(target = nil) ⇒ Object
- #tab_content(id) ⇒ Object
- #tab_set(name, type: nil, default_tab: nil, no_history: nil, preload_tabs: nil) ⇒ Object
- #tab_trigger(target_id, push_state: nil) ⇒ Object
Instance Method Details
#bind_key(key_name) ⇒ Object
292 293 294 |
# File 'lib/hooch/hooch_helper.rb', line 292 def bind_key(key_name) {"data-bind-key" => key_name} end |
#bind_key_attrs(key_name) ⇒ Object
296 297 298 |
# File 'lib/hooch/hooch_helper.rb', line 296 def bind_key_attrs(key_name) "data-bind-key=\"#{key_name}\"".html_safe end |
#click_proxy(target = nil) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/hooch/hooch_helper.rb', line 154 def click_proxy(target = nil) ''.tap do |attrs| attrs.concat "data-click-proxy=true" attrs.concat " data-target=#{target}" if target.present? end end |
#click_proxy_hash(target = nil) ⇒ Object
161 162 163 164 165 166 |
# File 'lib/hooch/hooch_helper.rb', line 161 def click_proxy_hash(target = nil) {}.tap do |params| params['data-click-proxy'] = true params['data-target'] = target if target.present? end end |
#collapsed(id, type: nil, expand_class: nil, collapse_class: nil) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hooch/hooch_helper.rb', line 82 def collapsed(id, type: nil, expand_class: nil, collapse_class: nil) if :ajax == type type = 'AjaxExpandable' end attrs = "data-expand-state=collapsed data-expand-id=" + id attrs += " data-sub-type=" + type if type.present? attrs += " data-expand-class=" + if .present? attrs += " data-collapse-class=" + collapse_class if collapse_class.present? attrs end |
#collapser(id) ⇒ Object
78 79 80 |
# File 'lib/hooch/hooch_helper.rb', line 78 def collapser(id) attrs = "data-collapser=true data-expand-id=" + id end |
#emptier(id) ⇒ Object
104 105 106 |
# File 'lib/hooch/hooch_helper.rb', line 104 def emptier(id) attrs = "data-emptier=true data-target=" + id end |
#expanded(id, type: nil, expand_class: nil, collapse_class: nil) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/hooch/hooch_helper.rb', line 93 def (id, type: nil, expand_class: nil, collapse_class: nil) if :ajax == type type = 'AjaxExpandable' end attrs = "data-expand-state=expanded data-expand-id=" + id attrs += " data-sub-type=" + type if type.present? attrs += " data-expand-class=" + if .present? attrs += " data-collapse-class=" + collapse_class if collapse_class.present? attrs end |
#expander(id, expand_class: nil, collapse_class: nil) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/hooch/hooch_helper.rb', line 71 def (id, expand_class: nil, collapse_class: nil) attrs = "data-expander=true data-expand-id=" + id attrs += " data-expand-class=" + if .present? attrs += " data-collapse-class=" + collapse_class if collapse_class.present? attrs end |
#fake_checkbox(form_selector, field_name, field_value, toggle_form: false) ⇒ Object
192 193 194 195 196 197 198 199 200 |
# File 'lib/hooch/hooch_helper.rb', line 192 def fake_checkbox(form_selector, field_name, field_value, toggle_form: false) {}.tap do |params| params['data-fake-checkbox'] = true params['data-form-selector'] = form_selector params['data-field-name'] = field_name params['data-field-value'] = field_value params['data-toggle-form'] = toggle_form if toggle_form end end |
#fake_checkbox_attrs(form_selector, field_name, field_value, toggle_form: false) ⇒ Object
182 183 184 185 186 187 188 189 190 |
# File 'lib/hooch/hooch_helper.rb', line 182 def fake_checkbox_attrs(form_selector, field_name, field_value, toggle_form: false) ''.tap do |attrs| attrs.concat 'data-fake-checkbox=true' attrs.concat " data-form-selector=#{form_selector}" attrs.concat " data-field-name=\"#{field_name}\"" attrs.concat " data-field-value=\"#{field_value}\"" attrs.concat " data-toggle-form=\"#{toggle_form}\"" if toggle_form end.html_safe end |
#fake_deselect ⇒ Object
202 203 204 205 206 |
# File 'lib/hooch/hooch_helper.rb', line 202 def fake_deselect {}.tap do |params| params['data-fake-deselector'] = true end end |
#fake_deselect_attrs ⇒ Object
208 209 210 211 212 |
# File 'lib/hooch/hooch_helper.rb', line 208 def fake_deselect_attrs ''.tap do |attrs| attrs.concat 'data-fake-deselector=true' end end |
#fake_select ⇒ Object
214 215 216 217 218 |
# File 'lib/hooch/hooch_helper.rb', line 214 def fake_select {}.tap do |params| params['data-fake-selector'] = true end end |
#fake_select_attrs ⇒ Object
220 221 222 223 224 |
# File 'lib/hooch/hooch_helper.rb', line 220 def fake_select_attrs ''.tap do |attrs| attrs.concat 'data-fake-selector=true' end end |
#field_filler(target, value) ⇒ Object
226 227 228 229 230 231 232 |
# File 'lib/hooch/hooch_helper.rb', line 226 def field_filler(target, value) ''.tap do |attrs| attrs.concat 'data-field-filler=true' attrs.concat " data-target=#{target}" attrs.concat " data-value=\"#{value}\"" end.html_safe end |
#field_filler_hash(target, value) ⇒ Object
234 235 236 237 238 239 240 |
# File 'lib/hooch/hooch_helper.rb', line 234 def field_filler_hash(target, value) {}.tap do |params| params['data-field-filler'] = true params['data-target'] = target params['data-value'] = value end end |
#hide_show(target, any_click_closes: false) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/hooch/hooch_helper.rb', line 57 def hide_show(target, any_click_closes: false) {}.tap do |params| params['data-hide-show'] = true params['data-target'] = target params['data-any-click-closes'] = true if any_click_closes end end |
#hide_show_attrs(target, any_click_closes: false) ⇒ Object
65 66 67 68 69 |
# File 'lib/hooch/hooch_helper.rb', line 65 def hide_show_attrs(target, any_click_closes: false) attrs = "data-hide-show=true data-target=" + target attrs += " data-any-click-closes=true" if any_click_closes attrs end |
#history_pusher(key = nil, value = nil) ⇒ Object
250 251 252 253 254 255 256 |
# File 'lib/hooch/hooch_helper.rb', line 250 def history_pusher(key = nil,value = nil) {}.tap do |params| params['data-history-pusher'] = true params['data-key'] = key if key params['data-value'] = value if value end end |
#history_pusher_attrs(key = nil, value = nil) ⇒ Object
242 243 244 245 246 247 248 |
# File 'lib/hooch/hooch_helper.rb', line 242 def history_pusher_attrs(key = nil,value = nil) ''.tap do |attrs| attrs.concat 'data-history-pusher=true' attrs.concat " data-key=#{key}" if key attrs.concat " data-value=\"#{value}\"" if value end.html_safe end |
#history_replacer(new_path) ⇒ Object
265 266 267 268 269 270 |
# File 'lib/hooch/hooch_helper.rb', line 265 def history_replacer(new_path) {}.tap do |params| params['data-history-replacer'] = true params['data-new-path'] = new_path end end |
#history_replacer_attrs(new_path) ⇒ Object
258 259 260 261 262 263 |
# File 'lib/hooch/hooch_helper.rb', line 258 def history_replacer_attrs(new_path) ''.tap do |attrs| attrs.concat 'data-history-replacer=true' attrs.concat " data-new-path=#{new_path}" end.html_safe end |
#link ⇒ Object
272 273 274 |
# File 'lib/hooch/hooch_helper.rb', line 272 def link "data-link=true" end |
#modal_closer(milliseconds: 0) ⇒ Object
51 52 53 54 55 |
# File 'lib/hooch/hooch_helper.rb', line 51 def modal_closer(milliseconds: 0) attrs = 'data-modal-closer=true' attrs += " data-milliseconds=#{milliseconds}" attrs end |
#modal_now(target, dismissable: true, delay: 0) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/hooch/hooch_helper.rb', line 43 def modal_now(target, dismissable: true, delay: 0) attrs = 'data-modal-now=true' attrs += " data-content-target=#{target}" attrs += " data-delay=#{delay}" attrs += " data-dismissable=true" if dismissable attrs end |
#modal_trigger(target, dismissable: true) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/hooch/hooch_helper.rb', line 36 def modal_trigger(target, dismissable: true) attrs = 'data-modal-trigger=true' attrs += " data-content-target=#{target}" attrs += " data-dismissable=true" if dismissable attrs end |
#prevent_double_click ⇒ Object
284 285 286 |
# File 'lib/hooch/hooch_helper.rb', line 284 def prevent_double_click "data-prevent-double-click=true" end |
#prevent_double_click_hash ⇒ Object
288 289 290 |
# File 'lib/hooch/hooch_helper.rb', line 288 def prevent_double_click_hash {"data-prevent-double-click" => true} end |
#prevent_double_submit ⇒ Object
276 277 278 |
# File 'lib/hooch/hooch_helper.rb', line 276 def prevent_double_submit "data-prevent-double-submit=true" end |
#prevent_double_submit_hash ⇒ Object
280 281 282 |
# File 'lib/hooch/hooch_helper.rb', line 280 def prevent_double_submit_hash {"data-prevent-double-submit" => true} end |
#remover(id) ⇒ Object
108 109 110 |
# File 'lib/hooch/hooch_helper.rb', line 108 def remover(id) attrs = "data-remover=true data-target=" + id end |
#revealer(id, type: nil, highlander: false) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/hooch/hooch_helper.rb', line 123 def revealer(id, type: nil, highlander: false) {}.tap do |params| params['data-revealer'] = true params['data-revealer-children-id'] = id params['data-sub-type'] = type if type.present? params['data-sub-type'] = 'FormFieldRevealer' if highlander end end |
#revealer_attrs(id, type: nil, highlander: false) ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/hooch/hooch_helper.rb', line 112 def revealer_attrs(id, type: nil, highlander: false) ''.tap do |attrs| attrs.concat "data-revealer=true data-revealer-children-id=\"#{id}\"" attrs.concat " data-sub-type=\"#{type}\"" if type.present? if highlander attrs.concat " data-sub-type=FormFieldRevealer" attrs.concat " data-revealer-highlander=\"true\"" end end.html_safe end |
#revealer_option(id, trigger: nil, triggers: nil) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/hooch/hooch_helper.rb', line 140 def revealer_option(id, trigger: nil, triggers: nil) {}.tap do |params| params['data-revealer-id'] = id params['data-revealer-trigger'] = trigger if trigger.present? params['data-revealer-triggers'] = triggers if triggers.present? end end |
#revealer_option_attrs(id, trigger: nil, triggers: nil) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/hooch/hooch_helper.rb', line 132 def revealer_option_attrs(id, trigger: nil, triggers: nil) ''.tap do |attrs| attrs.concat "data-revealer-id=#{id}" attrs.concat " data-revealer-trigger=\"#{trigger}\"" if trigger.present? attrs.concat " data-revealer-triggers='#{triggers.to_json}'" if triggers.present? end.html_safe end |
#revealer_target_attrs(id) ⇒ Object
148 149 150 151 152 |
# File 'lib/hooch/hooch_helper.rb', line 148 def revealer_target_attrs(id) ''.tap do |attrs| attrs.concat "data-revealer-target=\"#{id}\"" end.html_safe end |
#send_sort_now ⇒ Object
315 316 317 |
# File 'lib/hooch/hooch_helper.rb', line 315 def send_sort_now "data-send-sort-now" end |
#solo_sort_element(reusable: false, target_filters: nil) ⇒ Object
308 309 310 311 312 313 |
# File 'lib/hooch/hooch_helper.rb', line 308 def solo_sort_element(reusable: false, target_filters: nil) attrs = "data-sort-element=true" attrs += " data-target-filters=#{target_filters}" if target_filters attrs += " data-sort-reusable=true" if reusable attrs end |
#sorter(polymorphic_id: nil, recipient_filters: nil, href: nil) ⇒ Object
300 301 302 303 304 305 306 |
# File 'lib/hooch/hooch_helper.rb', line 300 def sorter(polymorphic_id: nil, recipient_filters: nil, href: nil) attrs = "data-sorter=true" attrs += " data-recipient-filters=#{recipient_filters}" if recipient_filters attrs += " data-polymorphic-id=#{polymorphic_id}" if polymorphic_id attrs += " href=#{href}" if href attrs end |
#submit_proxy(target = nil) ⇒ Object
168 169 170 171 172 173 |
# File 'lib/hooch/hooch_helper.rb', line 168 def submit_proxy(target = nil) ''.tap do |attrs| attrs.concat 'data-submit-proxy=true' attrs.concat " data-target=#{target}" if target.present? end end |
#submit_proxy_hash(target = nil) ⇒ Object
175 176 177 178 179 180 |
# File 'lib/hooch/hooch_helper.rb', line 175 def submit_proxy_hash(target = nil) {}.tap do |params| params['data-submit-proxy'] = true params['data-target'] = target if target.present? end end |
#tab_content(id) ⇒ Object
32 33 34 |
# File 'lib/hooch/hooch_helper.rb', line 32 def tab_content(id) attrs = 'data-tab-id=' + id end |
#tab_set(name, type: nil, default_tab: nil, no_history: nil, preload_tabs: nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/hooch/hooch_helper.rb', line 3 def tab_set(name, type: nil, default_tab: nil, no_history: nil, preload_tabs: nil) param_key = name.to_sym clean_params = params.permit!.to_hash.symbolize_keys if clean_params[param_key].present? default_tab = clean_params[param_key].to_s else default_tab = default_tab end if :ajax == type type = 'AjaxTabGroup' end attrs = 'data-tab-group=' + name attrs += ' data-sub-type=' + type if type.present? attrs += ' data-default-tab=' + default_tab if default_tab.present? attrs += ' data-preload-tabs=' + preload_tabs if preload_tabs.present? attrs += ' data-no-history=true' if no_history.present? attrs end |
#tab_trigger(target_id, push_state: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/hooch/hooch_helper.rb', line 22 def tab_trigger(target_id, push_state: nil) attrs = 'data-tab-trigger=true data-tab-target-id=' + target_id if push_state.present? attrs += ' data-push-state=' + push_state else attrs += ' data-push-state=' + target_id end attrs end |