Class: Interview::Form

Inherits:
Control show all
Includes:
HasControls
Defined in:
lib/interview/form.rb

Instance Attribute Summary collapse

Attributes included from HasControls

#controls

Attributes inherited from Control

#parent

Instance Method Summary collapse

Methods included from HasControls

#add_control, #add_controls, included, #initialize, #siblings

Methods inherited from Control

#ancestors, build, definition, #find_attribute, #find_attribute!, inherited, #initialize, #set_attributes, #set_defaults

Instance Attribute Details

#alignObject

Returns the value of attribute align.



5
6
7
# File 'lib/interview/form.rb', line 5

def align
  @align
end

#form_builderObject (readonly)

Returns the value of attribute form_builder.



6
7
8
# File 'lib/interview/form.rb', line 6

def form_builder
  @form_builder
end

#multi_createObject

Returns the value of attribute multi_create.



5
6
7
# File 'lib/interview/form.rb', line 5

def multi_create
  @multi_create
end

#redirect_toObject

Returns the value of attribute redirect_to.



5
6
7
# File 'lib/interview/form.rb', line 5

def redirect_to
  @redirect_to
end

#skip_submitObject

Returns the value of attribute skip_submit.



5
6
7
# File 'lib/interview/form.rb', line 5

def skip_submit
  @skip_submit
end

Instance Method Details

#renderObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/interview/form.rb', line 8

def render
  object = find_attribute!(:object)
  html_options = case @align
    when 'horizontal' then { class: 'form-horizontal' }
    when 'inline' then { class: 'form-inline' }
    else {}
  end
  return h.form_for(object, role: 'form', html: html_options) do |form_builder|
    @form_builder = form_builder
    html = Builder::XmlMarkup.new(indent: 2)
    
    render_default_controls(html)
    
    @controls.each do |control|
      html << control.render
      html.text! ' ' if @align == 'inline'
    end
    
    if @align == 'horizontal'
      html.div class: 'form-group' do
        html.div class: 'col-sm-offset-3 col-sm-9' do
          render_submit(html)
        end
      end
    else
      render_submit(html)
    end
    
    html.target!.html_safe
  end
end