Class: Tenon::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
app/form_builders/tenon/form_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#output_bufferObject

Returns the value of attribute output_buffer.



4
5
6
# File 'app/form_builders/tenon/form_builder.rb', line 4

def output_buffer
  @output_buffer
end

Instance Method Details

#asset(method_name, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/form_builders/tenon/form_builder.rb', line 13

def asset(method_name, opts = {})
  defaults = {
    label: nil,
    wrapper_class: 'panel',
    # Remove button triggers cocoon's remove child event?
    remove_association: false
  }
  opts = defaults.merge(opts)
  @template.render 'tenon/fields/asset',
    f: self,
    label_tag: label(method_name, opts[:label]),
    method_name: method_name,
    proxy_attachment: object.send(method_name),
    opts: opts
end

#check_box(method_name, opts = {}) ⇒ Object



165
166
167
168
169
170
# File 'app/form_builders/tenon/form_builder.rb', line 165

def check_box(method_name, opts = {})
  @template.render 'tenon/fields/check_box',
    f: self,
    method_name: method_name,
    opts: opts
end

#collection_select(method_name, collection, value_method, text_method, opts = {}, html_opts = {}) ⇒ Object



197
198
199
200
201
202
203
204
205
206
# File 'app/form_builders/tenon/form_builder.rb', line 197

def collection_select(method_name, collection, value_method, text_method, opts = {}, html_opts = {})
  @template.render 'tenon/fields/collection_select',
    f: self,
    method_name: method_name,
    collection: collection,
    value_method: value_method,
    text_method: text_method,
    opts: opts,
    html_opts: html_opts
end

#color_field(method_name, opts = {}) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# File 'app/form_builders/tenon/form_builder.rb', line 134

def color_field(method_name, opts = {})
  defaults = {
    placeholder: '--'
  }
  opts = defaults.merge(opts)

  @template.render 'tenon/fields/color_field',
    f: self,
    method_name: method_name,
    opts: opts
end

#date_picker(method_name, opts = {}) ⇒ Object



208
209
210
211
212
213
# File 'app/form_builders/tenon/form_builder.rb', line 208

def date_picker(method_name, opts = {})
  @template.render 'tenon/fields/date_picker',
    f: self,
    method_name: method_name,
    opts: opts
end

#date_time_picker(method_name, opts = {}) ⇒ Object



215
216
217
218
219
220
# File 'app/form_builders/tenon/form_builder.rb', line 215

def date_time_picker(method_name, opts = {})
  @template.render 'tenon/fields/date_time_picker',
    f: self,
    method_name: method_name,
    opts: opts
end

#datetime_widget(method_name, options = {}) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'app/form_builders/tenon/form_builder.rb', line 228

def datetime_widget(method_name, options = {})
  label = label(method_name, options[:label], nil, nil)
  explanation = explanation(options[:explanation])

  on = (:tr) do
    [
      (:td, 'On: '),
      (:td, super_text_field("#{method_name}_date", class: 'datepicker', size: 12, value: @object.send(method_name) ? @object.send(method_name).strftime('%Y-%m-%d') : (options[:default_date] || Time.now.strftime('%Y-%m-%d'))))
    ].join('\n').html_safe
  end
  at = (:tr) do
    [
      (:td, 'At: '),
      (:td, super_text_field("#{method_name}_time", value: @object.send(method_name) ? @object.send(method_name).strftime('%l:%M%p').strip : (options[:default_time] || Time.now.strftime('%l:%M%p').strip), size: 7))
    ].join('\n').html_safe
  end
  table = (:table, on + at, class: 'datetime_select')

  content = label(method_name, options[:label], nil, nil)
  content += explanation(options[:explanation])
  content += (:div, table, class: 'inset datetime-widget')
end

#email_field(method_name, opts = {}) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'app/form_builders/tenon/form_builder.rb', line 69

def email_field(method_name, opts = {})
  defaults = {
    placeholder: '--'
  }
  opts = defaults.merge(opts)

  @template.render 'tenon/fields/email_field',
    f: self,
    method_name: method_name,
    opts: opts
end

#inline_check_box(method_name, opts = {}) ⇒ Object



172
173
174
175
176
177
# File 'app/form_builders/tenon/form_builder.rb', line 172

def inline_check_box(method_name, opts = {})
  @template.render 'tenon/fields/inline_check_box',
    f: self,
    method_name: method_name,
    opts: opts
end

#inline_radio_button(method_name, value, opts = {}) ⇒ Object



188
189
190
191
192
193
194
# File 'app/form_builders/tenon/form_builder.rb', line 188

def inline_radio_button(method_name, value, opts = {})
  @template.render 'tenon/fields/inline_radio_button',
  f: self,
  method_name: method_name,
  value: value,
  opts: opts
end

#label(method_name, label, required = false, inline = false, language = nil, language_title = nil) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'app/form_builders/tenon/form_builder.rb', line 257

def label(method_name, label, required = false, inline = false, language = nil, language_title = nil)
  if label == false
    ''.html_safe
  else
    label ||= method_name.to_s.titleize
    label = language_title ? label + " (#{language_title.to_s.titleize})" : label
    label_class = ['input-block__label']
    label_class = ['input-block__label--inline'] if inline
    if required
      label += (:span, 'Required', class: 'input-block__required-msg')
    end
    super(get_method(method_name, language), label.html_safe, class: label_class.join(' '))
  end
end

#nested_fields(object, params = {}) ⇒ Object



251
252
253
254
255
# File 'app/form_builders/tenon/form_builder.rb', line 251

def nested_fields(object, params = {})
  fields_for object.to_s.pluralize do |nf|
    @template.render "#{object}_fields", { f: nf }.merge(params)
  end
end

#number_field(method_name, opts = {}) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'app/form_builders/tenon/form_builder.rb', line 95

def number_field(method_name, opts = {})
  defaults = {
    placeholder: '--'
  }
  opts = defaults.merge(opts)

  @template.render 'tenon/fields/number_field',
    f: self,
    method_name: method_name,
    opts: opts
end

#password_field(method_name, opts = {}) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'app/form_builders/tenon/form_builder.rb', line 82

def password_field(method_name, opts = {})
  defaults = {
    placeholder: '--'
  }
  opts = defaults.merge(opts)

  @template.render 'tenon/fields/password_field',
    f: self,
    method_name: method_name,
    opts: opts
end

#phone_field(method_name, opts = {}) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
# File 'app/form_builders/tenon/form_builder.rb', line 108

def phone_field(method_name, opts = {})
  defaults = {
    placeholder: '--'
  }
  opts = defaults.merge(opts)

  @template.render 'tenon/fields/phone_field',
    f: self,
    method_name: method_name,
    opts: opts
end

#radio_button(method_name, value, opts = {}) ⇒ Object



180
181
182
183
184
185
186
# File 'app/form_builders/tenon/form_builder.rb', line 180

def radio_button(method_name, value, opts = {})
  @template.render 'tenon/fields/radio_button',
    f: self,
    method_name: method_name,
    value: value,
    opts: opts
end

#rich_text(method_name, opts = {}) ⇒ Object Also known as: me_text



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/form_builders/tenon/form_builder.rb', line 29

def rich_text(method_name, opts = {})
  defaults = {
    placeholder: '--'
  }
  opts = defaults.merge(opts)

  @template.render 'tenon/fields/rich_text',
    f: self,
    method_name: method_name,
    label_tag: label(method_name, opts[:label]),
    opts: opts
end

#select(method_name, choices, opts = {}, html_opts = {}) ⇒ Object



155
156
157
158
159
160
161
162
# File 'app/form_builders/tenon/form_builder.rb', line 155

def select(method_name, choices, opts = {}, html_opts = {})
  @template.render 'tenon/fields/select',
    f: self,
    method_name: method_name,
    choices: choices,
    opts: opts,
    html_opts: html_opts
end

#super_check_boxObject



164
# File 'app/form_builders/tenon/form_builder.rb', line 164

alias_method :super_check_box, :check_box

#super_collection_selectObject



196
# File 'app/form_builders/tenon/form_builder.rb', line 196

alias_method :super_collection_select, :collection_select

#super_color_fieldObject



133
# File 'app/form_builders/tenon/form_builder.rb', line 133

alias_method :super_color_field, :color_field

#super_email_fieldObject



68
# File 'app/form_builders/tenon/form_builder.rb', line 68

alias_method :super_email_field, :email_field

#super_labelObject



5
# File 'app/form_builders/tenon/form_builder.rb', line 5

alias_method :super_label, :label

#super_number_fieldObject



94
# File 'app/form_builders/tenon/form_builder.rb', line 94

alias_method :super_number_field, :number_field

#super_password_fieldObject



81
# File 'app/form_builders/tenon/form_builder.rb', line 81

alias_method :super_password_field, :password_field

#super_phone_fieldObject



107
# File 'app/form_builders/tenon/form_builder.rb', line 107

alias_method :super_phone_field, :phone_field

#super_radio_buttonObject



179
# File 'app/form_builders/tenon/form_builder.rb', line 179

alias_method :super_radio_button, :radio_button

#super_selectObject



154
# File 'app/form_builders/tenon/form_builder.rb', line 154

alias_method :super_select, :select

#super_text_areaObject



146
# File 'app/form_builders/tenon/form_builder.rb', line 146

alias_method :super_text_area, :text_area

#super_text_fieldObject



43
# File 'app/form_builders/tenon/form_builder.rb', line 43

alias_method :super_text_field, :text_field

#super_url_fieldObject



120
# File 'app/form_builders/tenon/form_builder.rb', line 120

alias_method :super_url_field, :url_field

#tenon_content(method_name) ⇒ Object



7
8
9
10
11
# File 'app/form_builders/tenon/form_builder.rb', line 7

def tenon_content(method_name)
  @template.render 'tenon/tenon_content/tenon_content',
    f: self,
    field: method_name
end

#text_area(method_name, opts = {}) ⇒ Object



147
148
149
150
151
152
# File 'app/form_builders/tenon/form_builder.rb', line 147

def text_area(method_name, opts = {})
  @template.render 'tenon/fields/text_area',
    f: self,
    method_name: method_name,
    opts: opts
end

#text_area_content(method_name, options = {}, language = nil, language_title = nil) ⇒ Object



222
223
224
225
226
# File 'app/form_builders/tenon/form_builder.rb', line 222

def text_area_content(method_name, options = {}, language = nil, language_title = nil)
  label = label(method_name, options[:label], language, language_title)
  explanation = explanation(options[:explanation])
  label + explanation + super_text_area(get_method(method_name, language), options)
end

#text_field(method_name, opts = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'app/form_builders/tenon/form_builder.rb', line 44

def text_field(method_name, opts = {})
  defaults = {
    placeholder: '--'
  }
  opts = defaults.merge(opts)

  @template.render 'tenon/fields/text_field',
    f: self,
    method_name: method_name,
    opts: opts
end

#title_text_field(method_name, opts = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'app/form_builders/tenon/form_builder.rb', line 56

def title_text_field(method_name, opts = {})
  defaults = {
    placeholder: '--'
  }
  opts = defaults.merge(opts)

  @template.render 'tenon/fields/title_text_field',
    f: self,
    method_name: method_name,
    opts: opts
end

#url_field(method_name, opts = {}) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
# File 'app/form_builders/tenon/form_builder.rb', line 121

def url_field(method_name, opts = {})
  defaults = {
    placeholder: '--'
  }
  opts = defaults.merge(opts)

  @template.render 'tenon/fields/url_field',
    f: self,
    method_name: method_name,
    opts: opts
end