Class: Bootstrap3Helper::Tabs::Menu
- Defined in:
- lib/bootstrap3_helper/tabs/menu.rb
Overview
Used to rapidly generated Bootstrap Tabs Menu Components.
Instance Method Summary collapse
-
#dropdown(name, args = {}) {|dropdown| ... } ⇒ Object
Used to create menu items that are Dropdowns.
-
#initialize(template, args = {}, &block) ⇒ Menu
constructor
Creates a new Tabs::Menu object.
-
#item(name, args = {}) ⇒ Object
Adds a new menu item to the object.
-
#to_s ⇒ String
Used to render out the contents of the menu.
Methods inherited from Component
#concat, #content_tag, #parse_arguments, #uuid
Constructor Details
#initialize(template, args = {}, &block) ⇒ Menu
Creates a new Tabs::Menu object.
19 20 21 22 23 24 25 26 |
# File 'lib/bootstrap3_helper/tabs/menu.rb', line 19 def initialize(template, args = {}, &block) super(template) @id = args.fetch(:id, nil) @class = args.fetch(:class, '') @type = args.fetch(:type, :tabs) @content = block || proc { '' } end |
Instance Method Details
#dropdown(name, args = {}) {|dropdown| ... } ⇒ Object
Used to create menu items that are Dropdowns
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/bootstrap3_helper/tabs/menu.rb', line 78 def dropdown(name, args = {}, &block) id = args.fetch(:id, nil) data = args.fetch(:data, nil) klass = args.fetch(:class, '') dropdown = Tabs::Dropdown.new(@template, name, &block) content = content_tag :li, id: id, class: 'dropdown' + klass, data: data do dropdown.to_s.html_safe end end |
#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 menu item to the object.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bootstrap3_helper/tabs/menu.rb', line 42 def item(name, args = {}) id = args.fetch(:id, nil) data = args.fetch(:data, nil) klass = args.fetch(:class, '') active = klass.include? 'active' li = content_tag( :li, id: id, class: klass, data: data, role: 'presentation' ) do content_tag( :a, href: "##{name}", role: 'tab', tabindex: -1, data: { toggle: 'tab' }, aria: { controls: "##{name}", expanded: active, selected: active } ) do block_given? ? yield : name.to_s.titleize end end end |
#to_s ⇒ String
Used to render out the contents of the menu.
93 94 95 96 97 |
# File 'lib/bootstrap3_helper/tabs/menu.rb', line 93 def to_s content_tag :ul, id: @id, class: "nav nav-#{@type} " + @class, role: 'tablist' do @content.call(self) end end |