Module: Hooch::HoochHelper

Defined in:
lib/hooch/hooch_helper.rb

Instance Method Summary collapse

Instance Method Details

#bind_key(key_name) ⇒ Object



209
210
211
# File 'lib/hooch/hooch_helper.rb', line 209

def bind_key(key_name)
  {"data-bind-key" => key_name}
end

#bind_key_attrs(key_name) ⇒ Object



213
214
215
# File 'lib/hooch/hooch_helper.rb', line 213

def bind_key_attrs(key_name)
  "data-bind-key=\"#{key_name}\"".html_safe
end

#click_proxy(target = nil) ⇒ Object



115
116
117
118
119
120
# File 'lib/hooch/hooch_helper.rb', line 115

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



122
123
124
125
126
127
# File 'lib/hooch/hooch_helper.rb', line 122

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



43
44
45
46
47
48
49
50
51
52
# File 'lib/hooch/hooch_helper.rb', line 43

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=" + expand_class if expand_class.present?
  attrs += " data-collapse-class=" + collapse_class if collapse_class.present?
  attrs
end

#collapser(id) ⇒ Object



39
40
41
# File 'lib/hooch/hooch_helper.rb', line 39

def collapser(id)
  attrs = "data-collapser=true data-expand-id=" + id
end

#emptier(id) ⇒ Object



65
66
67
# File 'lib/hooch/hooch_helper.rb', line 65

def emptier(id)
  attrs = "data-emptier=true data-target=" + id
end

#expanded(id, type: nil, expand_class: nil, collapse_class: nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/hooch/hooch_helper.rb', line 54

def expanded(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=" + expand_class if expand_class.present?
  attrs += " data-collapse-class=" + collapse_class if collapse_class.present?
  attrs
end

#expander(id, expand_class: nil, collapse_class: nil) ⇒ Object



32
33
34
35
36
37
# File 'lib/hooch/hooch_helper.rb', line 32

def expander(id, expand_class: nil, collapse_class: nil)
  attrs = "data-expander=true data-expand-id=" + id
  attrs += " data-expand-class=" + expand_class if expand_class.present?
  attrs += " data-collapse-class=" + collapse_class if collapse_class.present?
  attrs
end

#field_filler(target, value) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/hooch/hooch_helper.rb', line 143

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



151
152
153
154
155
156
157
# File 'lib/hooch/hooch_helper.rb', line 151

def field_filler_hash(target, value)
  {}.tap do |params|
    params['data-field-filler'] = true
    params['data-target'] = target
    params['data-value'] = value
  end
end

#history_pusher(key, value) ⇒ Object



167
168
169
170
171
172
173
# File 'lib/hooch/hooch_helper.rb', line 167

def history_pusher(key,value)
  {}.tap do |params|
    params['data-history-pusher'] = true
    params['data-key'] = key
    params['data-value'] = value
  end
end

#history_pusher_attrs(key, value) ⇒ Object



159
160
161
162
163
164
165
# File 'lib/hooch/hooch_helper.rb', line 159

def history_pusher_attrs(key,value)
  ''.tap do |attrs|
    attrs.concat 'data-history-pusher=true'
    attrs.concat " data-key=#{key}"
    attrs.concat " data-value=\"#{value}\""
  end.html_safe
end

#history_replacer(new_path) ⇒ Object



182
183
184
185
186
187
# File 'lib/hooch/hooch_helper.rb', line 182

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



175
176
177
178
179
180
# File 'lib/hooch/hooch_helper.rb', line 175

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


189
190
191
# File 'lib/hooch/hooch_helper.rb', line 189

def link
  "data-link=true"
end


27
28
29
30
# File 'lib/hooch/hooch_helper.rb', line 27

def modal_trigger(target)
  attrs = 'data-modal-trigger="true"'
  attrs += " data-content-target=\"#{target}\""
end

#prevent_double_clickObject



201
202
203
# File 'lib/hooch/hooch_helper.rb', line 201

def prevent_double_click
  "data-prevent-double-click=true"
end

#prevent_double_click_hashObject



205
206
207
# File 'lib/hooch/hooch_helper.rb', line 205

def prevent_double_click_hash
  {"data-prevent-double-click" => true}
end

#prevent_double_submitObject



193
194
195
# File 'lib/hooch/hooch_helper.rb', line 193

def prevent_double_submit
  "data-prevent-double-submit=true"
end

#prevent_double_submit_hashObject



197
198
199
# File 'lib/hooch/hooch_helper.rb', line 197

def prevent_double_submit_hash
  {"data-prevent-double-submit" => true}
end

#remover(id) ⇒ Object



69
70
71
# File 'lib/hooch/hooch_helper.rb', line 69

def remover(id)
  attrs = "data-remover=true data-target=" + id
end

#revealer(id, type: nil, highlander: false) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/hooch/hooch_helper.rb', line 84

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



73
74
75
76
77
78
79
80
81
82
# File 'lib/hooch/hooch_helper.rb', line 73

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



101
102
103
104
105
106
107
# File 'lib/hooch/hooch_helper.rb', line 101

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



93
94
95
96
97
98
99
# File 'lib/hooch/hooch_helper.rb', line 93

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



109
110
111
112
113
# File 'lib/hooch/hooch_helper.rb', line 109

def revealer_target_attrs(id)
  ''.tap do |attrs|
    attrs.concat "data-revealer-target=\"#{id}\""
  end.html_safe
end

#submit_proxy(target = nil) ⇒ Object



129
130
131
132
133
134
# File 'lib/hooch/hooch_helper.rb', line 129

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



136
137
138
139
140
141
# File 'lib/hooch/hooch_helper.rb', line 136

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



23
24
25
# File 'lib/hooch/hooch_helper.rb', line 23

def tab_content(id)
  attrs = 'data-tab-id=' + id
end

#tab_set(name, type: nil, default_tab: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/hooch/hooch_helper.rb', line 3

def tab_set(name, type: nil, default_tab: nil)
  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
end

#tab_trigger(target_id, push_state: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/hooch/hooch_helper.rb', line 13

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