Class: Card::Bootstrap::Component::Form
- Inherits:
-
Component
- Object
- Component
- Card::Bootstrap::Component::Form
- Defined in:
- lib/card/bootstrap/component/form.rb
Overview
support class for bootstrap forms
Direct Known Subclasses
Instance Method Summary collapse
-
#form(opts = {}, &block) ⇒ Object
def_tag_method :form, nil, optional_classes: { horizontal: "form-horizontal", inline: "form-inline" } def_div_method :group, "form-group" def_tag_method :label, nil def_tag_method :input, "form-control" do |opts, extra_args| type, label = extra_args prepend { label label, for: opts } if label opts = type opts end.
- #group(text = nil, &block) ⇒ Object
- #input(type, text: nil, label: nil, id: nil) ⇒ Object
- #label(text = nil) ⇒ Object
- #render_content ⇒ Object
Instance Method Details
#form(opts = {}, &block) ⇒ Object
def_tag_method :form, nil, optional_classes: { horizontal: "form-horizontal", inline: "form-inline" } def_div_method :group, "form-group" def_tag_method :label, nil def_tag_method :input, "form-control" do |opts, extra_args| type, label = extra_args prepend { label label, for: opts } if label opts = type opts end
24 25 26 27 28 29 30 |
# File 'lib/card/bootstrap/component/form.rb', line 24 def form opts={}, &block add_class opts, "form-horizontal" if opts.delete(:horizontal) add_class opts, "form-inline" if opts.delete(:inline) @html.form opts do instance_exec(&block) end end |
#group(text = nil, &block) ⇒ Object
32 33 34 35 36 |
# File 'lib/card/bootstrap/component/form.rb', line 32 def group text=nil, &block @html.div text, class: "form-group" do instance_exec(&block) end end |
#input(type, text: nil, label: nil, id: nil) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/card/bootstrap/component/form.rb', line 42 def input type, text: nil, label: nil, id: nil @html.input id: id, class: "form-control", type: type do @html.label label, for: id if label @html << text if text end end |
#label(text = nil) ⇒ Object
38 39 40 |
# File 'lib/card/bootstrap/component/form.rb', line 38 def label(text=nil, &) @html.label(text, &) end |
#render_content ⇒ Object
6 7 8 |
# File 'lib/card/bootstrap/component/form.rb', line 6 def render_content(*) form(*, &@build_block) end |