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
- #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_trigger(target) ⇒ 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
264 265 266 |
# File 'lib/hooch/hooch_helper.rb', line 264 def bind_key(key_name) {"data-bind-key" => key_name} end |
#bind_key_attrs(key_name) ⇒ Object
268 269 270 |
# File 'lib/hooch/hooch_helper.rb', line 268 def bind_key_attrs(key_name) "data-bind-key=\"#{key_name}\"".html_safe end |
#click_proxy(target = nil) ⇒ Object
138 139 140 141 142 143 |
# File 'lib/hooch/hooch_helper.rb', line 138 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
145 146 147 148 149 150 |
# File 'lib/hooch/hooch_helper.rb', line 145 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
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hooch/hooch_helper.rb', line 66 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
62 63 64 |
# File 'lib/hooch/hooch_helper.rb', line 62 def collapser(id) attrs = "data-collapser=true data-expand-id=" + id end |
#emptier(id) ⇒ Object
88 89 90 |
# File 'lib/hooch/hooch_helper.rb', line 88 def emptier(id) attrs = "data-emptier=true data-target=" + id end |
#expanded(id, type: nil, expand_class: nil, collapse_class: nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/hooch/hooch_helper.rb', line 77 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
55 56 57 58 59 60 |
# File 'lib/hooch/hooch_helper.rb', line 55 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
176 177 178 179 180 181 182 183 184 |
# File 'lib/hooch/hooch_helper.rb', line 176 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
166 167 168 169 170 171 172 173 174 |
# File 'lib/hooch/hooch_helper.rb', line 166 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
186 187 188 189 190 |
# File 'lib/hooch/hooch_helper.rb', line 186 def fake_deselect {}.tap do |params| params['data-fake-deselector'] = true end end |
#fake_deselect_attrs ⇒ Object
192 193 194 195 196 |
# File 'lib/hooch/hooch_helper.rb', line 192 def fake_deselect_attrs ''.tap do |attrs| attrs.concat 'data-fake-deselector=true' end end |
#field_filler(target, value) ⇒ Object
198 199 200 201 202 203 204 |
# File 'lib/hooch/hooch_helper.rb', line 198 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
206 207 208 209 210 211 212 |
# File 'lib/hooch/hooch_helper.rb', line 206 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
41 42 43 44 45 46 47 |
# File 'lib/hooch/hooch_helper.rb', line 41 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
49 50 51 52 53 |
# File 'lib/hooch/hooch_helper.rb', line 49 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
222 223 224 225 226 227 228 |
# File 'lib/hooch/hooch_helper.rb', line 222 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
214 215 216 217 218 219 220 |
# File 'lib/hooch/hooch_helper.rb', line 214 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
237 238 239 240 241 242 |
# File 'lib/hooch/hooch_helper.rb', line 237 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
230 231 232 233 234 235 |
# File 'lib/hooch/hooch_helper.rb', line 230 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
244 245 246 |
# File 'lib/hooch/hooch_helper.rb', line 244 def link "data-link=true" end |
#modal_trigger(target) ⇒ Object
36 37 38 39 |
# File 'lib/hooch/hooch_helper.rb', line 36 def modal_trigger(target) attrs = 'data-modal-trigger=true' attrs += " data-content-target=#{target}" end |
#prevent_double_click ⇒ Object
256 257 258 |
# File 'lib/hooch/hooch_helper.rb', line 256 def prevent_double_click "data-prevent-double-click=true" end |
#prevent_double_click_hash ⇒ Object
260 261 262 |
# File 'lib/hooch/hooch_helper.rb', line 260 def prevent_double_click_hash {"data-prevent-double-click" => true} end |
#prevent_double_submit ⇒ Object
248 249 250 |
# File 'lib/hooch/hooch_helper.rb', line 248 def prevent_double_submit "data-prevent-double-submit=true" end |
#prevent_double_submit_hash ⇒ Object
252 253 254 |
# File 'lib/hooch/hooch_helper.rb', line 252 def prevent_double_submit_hash {"data-prevent-double-submit" => true} end |
#remover(id) ⇒ Object
92 93 94 |
# File 'lib/hooch/hooch_helper.rb', line 92 def remover(id) attrs = "data-remover=true data-target=" + id end |
#revealer(id, type: nil, highlander: false) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/hooch/hooch_helper.rb', line 107 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
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/hooch/hooch_helper.rb', line 96 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
124 125 126 127 128 129 130 |
# File 'lib/hooch/hooch_helper.rb', line 124 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
116 117 118 119 120 121 122 |
# File 'lib/hooch/hooch_helper.rb', line 116 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
132 133 134 135 136 |
# File 'lib/hooch/hooch_helper.rb', line 132 def revealer_target_attrs(id) ''.tap do |attrs| attrs.concat "data-revealer-target=\"#{id}\"" end.html_safe end |
#send_sort_now ⇒ Object
287 288 289 |
# File 'lib/hooch/hooch_helper.rb', line 287 def send_sort_now "data-send-sort-now" end |
#solo_sort_element(reusable: false, target_filters: nil) ⇒ Object
280 281 282 283 284 285 |
# File 'lib/hooch/hooch_helper.rb', line 280 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
272 273 274 275 276 277 278 |
# File 'lib/hooch/hooch_helper.rb', line 272 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
152 153 154 155 156 157 |
# File 'lib/hooch/hooch_helper.rb', line 152 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
159 160 161 162 163 164 |
# File 'lib/hooch/hooch_helper.rb', line 159 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 |