Class: Uberkit::Forms::Builder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
ActionView::Helpers::CaptureHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper, ActionView::Helpers::UrlHelper
Defined in:
lib/uberkit/forms/builder.rb

Instance Method Summary collapse

Instance Method Details

#array_from_classes(html_classes) ⇒ Object



78
79
80
# File 'lib/uberkit/forms/builder.rb', line 78

def array_from_classes(html_classes)
  html_classes ? html_classes.split(" ") : []
end

#check_box(field, options = {}, *args) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/uberkit/forms/builder.rb', line 50

def check_box(field, options = {}, *args)
  label_text = options.delete(:label) || field.to_s.titleize
  help = options.delete(:help)
  required = options.delete(:required)
  description = options.delete(:description)
  title = options.delete(:title)
  reverse_field(label_text, field, super(field, options, *args), {:required => required, :help => help, :description => description, :title => title})
end

#custom(options = {}, &block) ⇒ Object



72
73
74
75
76
# File 'lib/uberkit/forms/builder.rb', line 72

def custom(options = {}, &block)
  concat("<div class='field_row#{' labelless' unless options[:label]}'>#{"<label#{" for='#{options[:for]}'" if options[:for]}>#{options[:label] + ":" if options[:label]}</label>" if options[:label]}<div class='pseudo_field'>",block.binding)
  yield
  concat("</div> <br/></div>",block.binding)
end

#fieldset(legend = nil, &block) ⇒ Object



82
83
84
85
86
# File 'lib/uberkit/forms/builder.rb', line 82

def fieldset(legend=nil,&block)
  concat("<fieldset>#{"<legend>#{legend}</legend>" if legend}")
  yield
  concat("</fieldset>")
end

#generic_field(label_text, field, content, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/uberkit/forms/builder.rb', line 20

def generic_field(label_text,field,content,options = {})
  required = options.delete(:required)
  (:div, :class => "field_row#{' required' if required}#{' labelless' if label_text == ""}") do
    ret = label(field, (label_text || field.to_s.titleize).to_s + ":") unless label_text == ""
    ret << content
    ret << (:span, options.delete(:help), :class => "help") if options[:help]
    ret << (:span, options.delete(:description), :class => "description") if options[:description]
    ret << "<br/>"
    ret
  end
end

#is_haml?Boolean

Returns:

  • (Boolean)


96
# File 'lib/uberkit/forms/builder.rb', line 96

def is_haml?; false end

#output_bufferObject



88
89
90
# File 'lib/uberkit/forms/builder.rb', line 88

def output_buffer
  @template.output_buffer
end

#output_buffer=(buf) ⇒ Object



92
93
94
# File 'lib/uberkit/forms/builder.rb', line 92

def output_buffer=(buf)
  @template.output_buffer = buf
end

#radio_button(field, tag_value, options = {}) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/uberkit/forms/builder.rb', line 59

def radio_button(field, tag_value, options = {})
  label_text = options.delete(:label) || tag_value.to_s.titleize
  help = options.delete(:help)
  required = options.delete(:required)
  description = options.delete(:description)
  title = options.delete(:title)
  reverse_field(label_text, field, super(field, tag_value, options), {:required => required, :help => help, :description => description, :title => title} )
end

#reverse_field(label_text, field, content, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/uberkit/forms/builder.rb', line 32

def reverse_field(label_text, field, content, options = {})
  (:div, :class => "reverse_field#{' required' if options[:required]}#{' labelless' if options[:title].blank?}") do
    result = ""
    unless options[:title].blank?
      result << (:span, options[:title], :class => "pseudo_label")
    end
    result << (:div, :class => "pseudo_field") do
      ret = content
      ret << label(field, label_text)
      ret << (:span, options[:help], :class => 'help') unless options[:help].blank?
      ret << (:span, options[:description], :class => 'description') unless options[:description].blank?
      ret << "<br/>"
      ret
    end
    result
  end
end

#submit(text) ⇒ Object



68
69
70
# File 'lib/uberkit/forms/builder.rb', line 68

def submit(text)
  (:button, text, :type => "submit")
end