Class: Kiss::Form::Column

Inherits:
Object show all
Defined in:
lib/kiss/form.rb

Instance Method Summary collapse

Constructor Details

#initialize(form = nil) ⇒ Column

Returns a new instance of Column.



41
42
43
44
# File 'lib/kiss/form.rb', line 41

def initialize(form = nil)
  @_form = form
  @_components = []
end

Instance Method Details

#component_table_row_html(field) ⇒ Object

Renders HTML for specified form field.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kiss/form.rb', line 47

def component_table_row_html(field)
  field = fields[field.to_s] if (field.is_a?(Symbol) || field.is_a?(String))
  return field.element_html if field.is_a?(HiddenField)

  type = field.class.type
  prompt = field.prompt
  label = field.label
  errors = field.errors_html
  required = field.required ? %Q(<span class="kiss_form_required">#{@_form.mark_required}</span> ) : ''

  parts = [
	  prompt ? %Q(<tr class="kiss_form_prompt"><td class="kiss_form_label">#{required}</td><td>#{prompt.to_s}</td></tr>) : '',
    %Q(<tr class="kiss_form_#{type}"><td class="kiss_form_label#{errors ? ' error' : ''}">),
    !prompt ? (required + (label.blank? ? '' : label.to_s + ':' )) : '',
	  %Q(</td><td class="kiss_form_#{type}">),
		field.element_html, "</td></tr>"
	]
	if errors
	  parts += [
  	  '<tr class="kiss_form_error_row"><td class="kiss_form_required"></td><td>',
  	  errors,
  	  '</td></tr>'
  	]
	end
	parts.join
end

#components_htmlObject Also known as: fields_html

Renders HTML for form fields.



75
76
77
78
79
# File 'lib/kiss/form.rb', line 75

def components_html
  @_components.map do |component|
    component_table_row_html(component)
  end.join
end

#htmlObject



94
95
96
97
98
99
100
101
102
# File 'lib/kiss/form.rb', line 94

def html
  [
    '<td class="kiss_form_column">',
    table_html_open,
    components_html,
    table_html_close,
    '</td>'
  ].join
end

#table_closing_htmlObject Also known as: table_html_close

Renders close of form table.



89
90
91
# File 'lib/kiss/form.rb', line 89

def table_closing_html
  '</tbody></table>'
end

#table_opening_htmlObject Also known as: table_html_open

Renders open of form table.



83
84
85
# File 'lib/kiss/form.rb', line 83

def table_opening_html
  %Q(<table class="kiss_form_column" border=0 cellspacing=0><tbody>)
end