Class: OkonomiUiKit::Components::DropdownButton::DropdownBuilder
- Inherits:
-
Object
- Object
- OkonomiUiKit::Components::DropdownButton::DropdownBuilder
- Defined in:
- app/helpers/okonomi_ui_kit/components/dropdown_button.rb
Instance Attribute Summary collapse
-
#is_first ⇒ Object
readonly
Returns the value of attribute is_first.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #button_tag(content_or_options = nil, options = nil, &block) ⇒ Object
- #button_to(name = nil, options = {}, html_options = {}, &block) ⇒ Object
- #divider ⇒ Object
-
#initialize(view) ⇒ DropdownBuilder
constructor
A new instance of DropdownBuilder.
- #link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
- #menu_items ⇒ Object
- #primary_item ⇒ Object
Constructor Details
#initialize(view) ⇒ DropdownBuilder
Returns a new instance of DropdownBuilder.
56 57 58 59 60 |
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 56 def initialize(view) @view = view @items = [] @is_first = true end |
Instance Attribute Details
#is_first ⇒ Object (readonly)
Returns the value of attribute is_first.
54 55 56 |
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 54 def is_first @is_first end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
54 55 56 |
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 54 def items @items end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
54 55 56 |
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 54 def view @view end |
Instance Method Details
#button_tag(content_or_options = nil, options = nil, &block) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 104 def ( = nil, = nil, &block) # Handle the different argument patterns for button_tag if .is_a?(Hash) = content = nil else content = end ||= {} # Handle icon extraction icon = .delete(:icon) if .is_a?(Hash) # Ensure type is button for button_tag [:type] ||= "button" item = { type: :button_tag, name: content, options: , block: block, is_first: @is_first, icon: icon } @items << item @is_first = false end |
#button_to(name = nil, options = {}, html_options = {}, &block) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 83 def (name = nil, = {}, = {}, &block) # Handle icon extraction if .is_a?(Hash) icon = .delete(:icon) else icon = nil end item = { type: :button, name: name, options: , html_options: , block: block, is_first: @is_first, icon: icon } @items << item @is_first = false end |
#divider ⇒ Object
133 134 135 |
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 133 def divider @items << { type: :divider } end |
#link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 62 def link_to(name = nil, = nil, = nil, &block) # Handle icon extraction if .is_a?(Hash) icon = .delete(:icon) else icon = nil end item = { type: :link, name: name, options: , html_options: || {}, block: block, is_first: @is_first, icon: icon } @items << item @is_first = false end |
#menu_items ⇒ Object
141 142 143 |
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 141 def @items end |
#primary_item ⇒ Object
137 138 139 |
# File 'app/helpers/okonomi_ui_kit/components/dropdown_button.rb', line 137 def primary_item @items.find { |item| item[:is_first] && item[:type] != :divider } end |