Class: Bootstrap::Component::Form

Inherits:
Bootstrap::Component show all
Defined in:
mod/bootstrap/lib/bootstrap/component/form.rb

Direct Known Subclasses

HorizontalForm

Instance Method Summary collapse

Methods inherited from Bootstrap::Component

#append, def_div_method, def_simple_tag_method, def_tag_method, #initialize, #insert, #prepend, #render, render, #wrap

Methods included from Delegate

#method_missing, #respond_to_missing?

Methods included from BasicTags

#html

Constructor Details

This class inherits a constructor from Bootstrap::Component

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Bootstrap::Delegate

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[:id] } if label opts[:type] = type opts end



22
23
24
25
26
27
28
# File 'mod/bootstrap/lib/bootstrap/component/form.rb', line 22

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



30
31
32
33
34
# File 'mod/bootstrap/lib/bootstrap/component/form.rb', line 30

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



40
41
42
43
44
45
# File 'mod/bootstrap/lib/bootstrap/component/form.rb', line 40

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! text if text
  end
end

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



36
37
38
# File 'mod/bootstrap/lib/bootstrap/component/form.rb', line 36

def label text=nil, &block
  @html.label text, &block
end

#render_content(*args) ⇒ Object



4
5
6
# File 'mod/bootstrap/lib/bootstrap/component/form.rb', line 4

def render_content *args
  form *args, &@build_block
end