Class: TwitterBootstrapFormFor::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
FormHelpers
Defined in:
lib/twitter_bootstrap_form_for/form_builder.rb

Constant Summary collapse

INPUTS =
[
  :select,
  *ActionView::Helpers::FormBuilder.instance_methods.grep(%r{
    _(area|field|select)$ # all area, field, and select methods
  }mx).map(&:to_sym)
]
TOGGLES =
[
  :check_box,
  :radio_button,
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



8
9
10
# File 'lib/twitter_bootstrap_form_for/form_builder.rb', line 8

def object
  @object
end

#object_nameObject (readonly)

Returns the value of attribute object_name.



9
10
11
# File 'lib/twitter_bootstrap_form_for/form_builder.rb', line 9

def object_name
  @object_name
end

#templateObject (readonly)

Returns the value of attribute template.



7
8
9
# File 'lib/twitter_bootstrap_form_for/form_builder.rb', line 7

def template
  @template
end

Instance Method Details

#actions(&block) ⇒ Object

Wraps action buttons into their own styled container.



53
54
55
# File 'lib/twitter_bootstrap_form_for/form_builder.rb', line 53

def actions(&block)
  template.(:div, :class => 'actions', &block)
end

#inline(label = nil, &block) ⇒ Object

Creates bootstrap wrapping before yielding a plain old rails builder to the supplied block.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/twitter_bootstrap_form_for/form_builder.rb', line 71

def inline(label = nil, &block)
  template.(:div, :class => 'clearfix') do
    template.concat template.(:label, label) if label.present?
    template.concat template.(:div, :class => 'input') {
      template.(:div, :class => 'inline-inputs') do
        template.fields_for(
          self.object_name,
          self.object,
          self.options.merge(:builder => ActionView::Base.default_form_builder),
          &block
        )
      end
    }
  end
end

#inputs(legend = nil, options = {}, &block) ⇒ Object

Wraps the contents of the block passed in a fieldset with optional legend text.



29
30
31
32
33
34
# File 'lib/twitter_bootstrap_form_for/form_builder.rb', line 29

def inputs(legend = nil, options = {}, &block)
  template.(:fieldset, options) do
    template.concat template.(:legend, legend) unless legend.nil?
    block.call
  end
end

#submit(value = nil, options = {}) ⇒ Object

Renders a submit tag with default classes to style it as a primary form button.



61
62
63
64
65
# File 'lib/twitter_bootstrap_form_for/form_builder.rb', line 61

def submit(value = nil, options = {})
  options[:class] ||= 'btn primary'

  super value, options
end

#toggles(label = nil, &block) ⇒ Object

Wraps groups of toggles (radio buttons, checkboxes) with a single label and the appropriate markup. All toggle buttons should be rendered inside of here, and will not look correct unless they are.



41
42
43
44
45
46
47
48
# File 'lib/twitter_bootstrap_form_for/form_builder.rb', line 41

def toggles(label = nil, &block)
  template.(:div, :class => 'clearfix') do
    template.concat template.(:label, label)
    template.concat template.(:div, :class => "input") {
      template.(:ul, :class => "inputs-list") { block.call }
    }
  end
end