Class: TwitterBootstrapFormalwear::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- TwitterBootstrapFormalwear::FormBuilder
- Includes:
- FormHelpers
- Defined in:
- lib/twitter_bootstrap_formalwear/form_builder.rb
Constant Summary collapse
- INPUTS =
[ :check_box, :radio_button, :select, *ActionView::Helpers::FormBuilder.instance_methods.grep(%r{ _(area|field|select)$ # all area, field, and select methods }mx).map(&:to_sym) ]
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.
-
#button(value = nil, options = {}) ⇒ Object
Renders a button with default classes to style it as a form button.
-
#controls(attribute, text = '', options = {}, &block) ⇒ Object
Generates a controls div element for the given
attribute
. -
#fieldset(legend = nil, options = {}) ⇒ Object
Wraps the contents of the block passed in a fieldset with optional
legend
text. -
#group(attribute = '', text = '', options = {}, &block) ⇒ Object
Generates a control-group div element for the given
attribute
, containing label and controls elements. -
#label(attribute, text = '', options = {}, &block) ⇒ Object
Generates a label element for the given
attribute
. -
#submit(value = nil, options = {}) ⇒ Object
Renders a submit tag with default classes to style it as a primary form button.
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
8 9 10 |
# File 'lib/twitter_bootstrap_formalwear/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_formalwear/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_formalwear/form_builder.rb', line 7 def template @template end |
Instance Method Details
#actions(&block) ⇒ Object
Wraps action buttons into their own styled container.
41 42 43 |
# File 'lib/twitter_bootstrap_formalwear/form_builder.rb', line 41 def actions(&block) template.content_tag(:div, :class => 'form-actions', &block) end |
#button(value = nil, options = {}) ⇒ Object
Renders a button with default classes to style it as a form button.
98 99 100 101 102 103 |
# File 'lib/twitter_bootstrap_formalwear/form_builder.rb', line 98 def (value = nil, = {}) super value, { :type => 'button', :class => 'btn', }.merge() end |
#controls(attribute, text = '', options = {}, &block) ⇒ Object
Generates a controls div element for the given attribute
.
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/twitter_bootstrap_formalwear/form_builder.rb', line 82 def controls(attribute, text = '', = {}, &block) text, attribute = attribute, nil if attribute.kind_of? String template.content_tag(:div, :class => 'controls') { template.fields_for( self.object_name, self.object, self..merge(:builder => TwitterBootstrapFormalwear::FormControls), &block ) } end |
#fieldset(legend = nil, options = {}) ⇒ Object
Wraps the contents of the block passed in a fieldset with optional legend
text.
31 32 33 34 35 36 |
# File 'lib/twitter_bootstrap_formalwear/form_builder.rb', line 31 def fieldset(legend = nil, = {}) template.content_tag(:fieldset, ) do template.concat template.content_tag(:legend, legend) unless legend.nil? yield end end |
#group(attribute = '', text = '', options = {}, &block) ⇒ Object
Generates a control-group div element for the given attribute
, containing label and controls elements.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/twitter_bootstrap_formalwear/form_builder.rb', line 49 def group(attribute = '', text = '', = {}, &block) text, attribute = attribute, nil if attribute.kind_of? String id = _wrapper_id attribute, 'control_group' classes = _wrapper_classes attribute, 'control-group' template.content_tag(:div, :id => id, :class => classes) do if !attribute.blank? template.concat self.label(attribute, text, , &block) end template.concat self.controls(attribute, text, , &block) end end |
#label(attribute, text = '', options = {}, &block) ⇒ Object
Generates a label element for the given attribute
. If text
is passed, uses that as the text for the label; otherwise humanizes the attribute
name.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/twitter_bootstrap_formalwear/form_builder.rb', line 67 def label(attribute, text = '', = {}, &block) text, attribute = attribute, nil if attribute.kind_of? String = .merge(:class => 'control-label') case when attribute && text then super(attribute, text, , &nil) when attribute then super(attribute, nil, , &nil) when text then template.label_tag(nil, text, , &nil) end end |
#submit(value = nil, options = {}) ⇒ Object
Renders a submit tag with default classes to style it as a primary form button.
109 110 111 112 113 114 |
# File 'lib/twitter_bootstrap_formalwear/form_builder.rb', line 109 def submit(value = nil, = {}) self. value, { :type => 'submit', :class => 'btn btn-primary', }.merge() end |