Class: TwitterBootstrapFormFor::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- TwitterBootstrapFormFor::FormBuilder
- 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
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#object_name ⇒ Object
readonly
Returns the value of attribute object_name.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#actions(&block) ⇒ Object
Wraps action buttons into their own styled container.
-
#inline(label = nil, &block) ⇒ Object
Creates bootstrap wrapping before yielding a plain old rails builder to the supplied block.
-
#inputs(legend = nil, options = {}, &block) ⇒ Object
Wraps the contents of the block passed in a fieldset with optional
legend
text. -
#submit(value = nil, options = {}) ⇒ Object
Renders a submit tag with default classes to style it as a primary form button.
-
#toggles(label = nil, &block) ⇒ Object
Wraps groups of toggles (radio buttons, checkboxes) with a single label and the appropriate markup.
Instance Attribute Details
#object ⇒ Object (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_name ⇒ Object (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 |
#template ⇒ Object (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.content_tag(: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.content_tag(:div, :class => 'clearfix') do template.concat template.content_tag(:label, label) if label.present? template.concat template.content_tag(:div, :class => 'input') { template.content_tag(:div, :class => 'inline-inputs') do template.fields_for( self.object_name, self.object, self..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, = {}, &block) template.content_tag(:fieldset, ) do template.concat template.content_tag(: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, = {}) [:class] ||= 'btn primary' super value, 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.content_tag(:div, :class => 'clearfix') do template.concat template.content_tag(:label, label) template.concat template.content_tag(:div, :class => "input") { template.content_tag(:ul, :class => "inputs-list") { block.call } } end end |