Class: Bootstrap4Helper::Dropdown::Menu
- Defined in:
- lib/bootstrap4_helper/dropdown/menu.rb
Overview
Builds a menu component for use in dropdowns.
Instance Method Summary collapse
-
#divider ⇒ String
Builds a divider element.
-
#header(text, opts = {}, &block) ⇒ String
Builds a Header component.
-
#initialize(template, opts = {}, &block) ⇒ Menu
constructor
Class constructor.
-
#item(target, opts = {}) ⇒ String
Use this method when you are using the item in the menu as trigger for tab content.
-
#link(name = nil, options = nil, html_options = nil, &block) ⇒ String
Use this method when the ‘item`, `link` in the item in the menu is nothing more than a hyperlink.
-
#text(text, opts = {}, &block) ⇒ String
Builds a Text component.
-
#to_s ⇒ String
String representation of the object.
Methods inherited from Component
#capture, #concat, #config, #content_tag, #parse_arguments, #uuid
Constructor Details
#initialize(template, opts = {}, &block) ⇒ Menu
Class constructor
15 16 17 18 19 20 21 22 |
# File 'lib/bootstrap4_helper/dropdown/menu.rb', line 15 def initialize(template, opts = {}, &block) super(template) @id = opts.fetch(:id, uuid) @class = opts.fetch(:class, '') @data = opts.fetch(:data, {}) @content = block || proc { '' } end |
Instance Method Details
#divider ⇒ String
Builds a divider element
97 98 99 |
# File 'lib/bootstrap4_helper/dropdown/menu.rb', line 97 def divider content_tag :div, '', class: 'dropdown-divider' end |
#header(text, opts = {}, &block) ⇒ String
Builds a Header component
89 90 91 |
# File 'lib/bootstrap4_helper/dropdown/menu.rb', line 89 def header(text, opts = {}, &block) build_sub_component :h6, text, 'header', opts, &block end |
#item(target, opts = {}) ⇒ String
Use this method when you are using the item in the menu as trigger for tab content.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bootstrap4_helper/dropdown/menu.rb', line 49 def item(target, opts = {}) id = opts.fetch(:id, nil) klass = opts.fetch(:class, '') data = opts.fetch(:data, {}).merge(toggle: 'tab') aria = opts.fetch(:aria, {}) content_tag( :a, id: id, class: "dropdown-item #{klass}", href: "##{target}", aria: aria, data: data ) do block_given? ? yield : target.to_s.titleize end end |
#link(name = nil, options = nil, html_options = nil, &block) ⇒ String
Use this method when the ‘item`, `link` in the item in the menu is nothing more than a hyperlink.
32 33 34 35 36 |
# File 'lib/bootstrap4_helper/dropdown/menu.rb', line 32 def link(name = nil, = nil, = nil, &block) = ( || {}).merge(class: 'dropdown-item') @template.link_to(name, , , &block) end |
#text(text, opts = {}, &block) ⇒ String
Builds a Text component
76 77 78 |
# File 'lib/bootstrap4_helper/dropdown/menu.rb', line 76 def text(text, opts = {}, &block) build_sub_component :span, text, 'item-text', opts, &block end |
#to_s ⇒ String
String representation of the object.
105 106 107 108 109 |
# File 'lib/bootstrap4_helper/dropdown/menu.rb', line 105 def to_s content_tag :div, id: @id, class: "dropdown-menu #{@class}", data: @data do @content.call(self) end end |