Class: Bootstrap3Helper::Tabs::Dropdown
- Defined in:
- lib/bootstrap3_helper/tabs/dropdown.rb
Overview
Used to rapidly build dropdown menus for Bootstrap tabs.
Instance Method Summary collapse
-
#initialize(template, name = '', &block) ⇒ Dropdown
constructor
Creates a new Tabs::Dropdown object.
-
#item(name, args = {}) ⇒ Object
Adds a new item to the dropdown object.
-
#to_s ⇒ String
Used to render out the object and get the HTML representation.
Methods inherited from Component
#concat, #content_tag, #parse_arguments, #uuid
Constructor Details
#initialize(template, name = '', &block) ⇒ Dropdown
Creates a new Tabs::Dropdown object.
20 21 22 23 24 25 |
# File 'lib/bootstrap3_helper/tabs/dropdown.rb', line 20 def initialize(template, name = '', &block) super(template) @name = name @content = block || proc { '' } end |
Instance Method Details
#item(name, args = {}) ⇒ Object
Note:
You can opt out of passing in a block and the li will use the name attribute for the menu item.
Adds a new item to the dropdown object.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bootstrap3_helper/tabs/dropdown.rb', line 41 def item(name, args = {}) id = args.fetch(:id, nil) klass = args.fetch(:class, '') data = args.fetch(:data, nil) active = klass.include? 'active' content_tag( :li, id: id, class: klass, data: data ) do content_tag( :a, href: "##{name}", role: 'tab', data: { toggle: 'tab' }, aria: { controls: name, expanded: active } ) do block_given? ? yield : name.to_s.titleize end end end |
#to_s ⇒ String
Used to render out the object and get the HTML representation.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bootstrap3_helper/tabs/dropdown.rb', line 70 def to_s content = content_tag( :a, @name, href: '#', class: 'dropdown-toggle', data: { toggle: 'dropdown' }, aria: { expanded: false } ) content += content_tag :ul, id: @id, class: 'dropdown-menu ' do @content.call(self) end end |