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, options = {}, &block) ⇒ Item
constructor
A new instance of Item.
- #options ⇒ Object
- #render ⇒ Object
- #render_menu ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(template, label, options = {}, &block) ⇒ Item
Returns a new instance of Item.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/trestle/toolbar/item.rb', line 8 def initialize(template, label, ={}, &block) @template = template @label, @options, @block = label, @menu = Menu.new(template) @menu.build(&block) if block_given? @icon = .delete(:icon) @style = .delete(: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
19 20 21 |
# File 'lib/trestle/toolbar/item.rb', line 19 def ==(other) to_s == other.to_s end |
#button_classes ⇒ Object
48 49 50 51 52 53 |
# File 'lib/trestle/toolbar/item.rb', line 48 def classes = (@options[:class] || "").split(/\s/) classes.push(*) classes.push("has-icon") if @icon classes.uniq end |
#button_label(content, options) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/trestle/toolbar/item.rb', line 55 def (content, ) icon = icon(@icon) if @icon label = content_tag(:span, content, class: "btn-label") safe_join([icon, label].compact, " ") end |
#button_style ⇒ Object
62 63 64 |
# File 'lib/trestle/toolbar/item.rb', line 62 def @style || "default" end |
#button_style_classes ⇒ Object
66 67 68 |
# File 'lib/trestle/toolbar/item.rb', line 66 def ["btn", "btn-#{}"] end |
#options ⇒ Object
44 45 46 |
# File 'lib/trestle/toolbar/item.rb', line 44 def @options.merge(class: ) end |
#render ⇒ Object
33 34 35 |
# File 'lib/trestle/toolbar/item.rb', line 33 def render raise NotImplementedError end |
#render_menu ⇒ Object
37 38 39 40 41 42 |
# File 'lib/trestle/toolbar/item.rb', line 37 def [ .render_toggle(class: ), .render_items ] end |
#to_s ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/trestle/toolbar/item.rb', line 23 def to_s if .items.any? content_tag(:div, class: "btn-group", role: "group") do safe_join([render, ], "\n") end else render end end |