Class: Shoehorn::Components::Dropdown

Inherits:
Base
  • Object
show all
Defined in:
lib/shoehorn/components/dropdown.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#options, #output_buffer

Instance Method Summary collapse

Constructor Details

#initialize(elements, options = {}) ⇒ Dropdown

Returns a new instance of Dropdown.



5
6
7
8
# File 'lib/shoehorn/components/dropdown.rb', line 5

def initialize(elements, options = {})
  super
  @elements = elements
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



3
4
5
# File 'lib/shoehorn/components/dropdown.rb', line 3

def collection
  @collection
end

Instance Method Details

#to_sObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/shoehorn/components/dropdown.rb', line 10

def to_s
  div_options = {:class => build_class}
  output_buffer << (:div, div_options.reverse_merge(options[:html_options])) do
    html=''
    html << build_dropdown

    html << (:ul, :class => 'dropdown-menu') do
      menu = ''
      @elements.each do |e|
        menu << (:li, e.to_s)
      end
      menu.html_safe
    end

    html.html_safe
  end
  super
end