Class: Trestle::Toolbar::Item
- Inherits:
-
Object
- Object
- Trestle::Toolbar::Item
- Defined in:
- lib/trestle/toolbar/item.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#menu ⇒ Object
readonly
Returns the value of attribute menu.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #button_classes ⇒ Object
- #button_label(content, options) ⇒ Object
- #button_style ⇒ Object
- #button_style_classes ⇒ Object
-
#initialize(template, label, icon: nil, style: nil, **options, &block) ⇒ Item
constructor
A new instance of Item.
- #options ⇒ Object
- #render ⇒ Object
- #render_menu ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(template, label, icon: nil, style: nil, **options, &block) ⇒ Item
Returns a new instance of Item.
8 9 10 11 12 13 14 15 16 |
# File 'lib/trestle/toolbar/item.rb', line 8 def initialize(template, label, icon: nil, style: nil, **, &block) @template = template @label, @options, @block = label, @menu = Menu.new(template) @menu.build(&block) if block_given? @icon, @style = icon, style end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
4 5 6 |
# File 'lib/trestle/toolbar/item.rb', line 4 def label @label end |
#menu ⇒ Object (readonly)
Returns the value of attribute menu.
4 5 6 |
# File 'lib/trestle/toolbar/item.rb', line 4 def @menu end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 |
# File 'lib/trestle/toolbar/item.rb', line 18 def ==(other) to_s == other.to_s end |
#button_classes ⇒ Object
47 48 49 50 51 52 |
# File 'lib/trestle/toolbar/item.rb', line 47 def classes = (@options[:class] || "").split(/\s/) classes.push(*) classes.push("has-icon") if @icon classes.uniq end |
#button_label(content, options) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/trestle/toolbar/item.rb', line 54 def (content, ) icon = icon(@icon) if @icon label = tag.span(content, class: "btn-label") safe_join([icon, label].compact, " ") end |
#button_style ⇒ Object
61 62 63 |
# File 'lib/trestle/toolbar/item.rb', line 61 def @style || "default" end |
#button_style_classes ⇒ Object
65 66 67 |
# File 'lib/trestle/toolbar/item.rb', line 65 def ["btn", "btn-#{}"] end |
#options ⇒ Object
43 44 45 |
# File 'lib/trestle/toolbar/item.rb', line 43 def @options.merge(class: ) end |
#render ⇒ Object
32 33 34 |
# File 'lib/trestle/toolbar/item.rb', line 32 def render raise NotImplementedError end |
#render_menu ⇒ Object
36 37 38 39 40 41 |
# File 'lib/trestle/toolbar/item.rb', line 36 def [ .render_toggle(class: ), .render_items ] end |
#to_s ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/trestle/toolbar/item.rb', line 22 def to_s if .items.any? tag.div(class: "btn-group", role: "group") do safe_join([render, ], "\n") end else render end end |