Class: Interview::Dropdown

Inherits:
Control
  • Object
show all
Includes:
HasControls
Defined in:
lib/interview/dropdown.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, #siblings

Methods inherited from Control

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

Constructor Details

#initialize(params = {}) ⇒ Dropdown

Returns a new instance of Dropdown.



7
8
9
10
# File 'lib/interview/dropdown.rb', line 7

def initialize(params={})
  @html_class = []
  super
end

Instance Attribute Details

#captionObject

Returns the value of attribute caption.



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

def caption
  @caption
end

#html_classObject

Returns the value of attribute html_class.



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

def html_class
  @html_class
end

#imageObject

Returns the value of attribute image.



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

def image
  @image
end

#styleObject

Returns the value of attribute style.



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

def style
  @style
end

Instance Method Details

#renderObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/interview/dropdown.rb', line 12

def render
  html = Builder::XmlMarkup.new
  html_class = @html_class.dup
  html_class << 'dropdown'
  html.div class: html_class.join(' ') do
    html_class = 'dropdown-toggle'
    html_class += ' btn btn-default' if @style == 'button'
    html.a class: html_class, href: '#', :'data-toggle' => 'dropdown' do
      html.span '', class: "glyphicon glyphicon-#{@image}" if @image
      html.text! ' ' if @image and @caption
      html.text! @caption if @caption
      html.text! ' ' if @caption
      html.span '', class: 'caret'
    end
    html.ul class: 'dropdown-menu' do
      @controls.each do |control|
        html.li do
          html << control.render
        end
      end
    end
  end
  return html.target!
end