lib/trestle/toolbar/item.rb in trestle-0.10.0 vs lib/trestle/toolbar/item.rb in trestle-0.10.1

- old
+ new

@@ -1,30 +1,29 @@ module Trestle class Toolbar class Item attr_reader :label, :menu - delegate :admin_link_to, :button_tag, :content_tag, :safe_join, :icon, to: :@template + delegate :admin_link_to, :button_tag, :tag, :safe_join, :icon, to: :@template - def initialize(template, label, options={}, &block) + def initialize(template, label, icon: nil, style: nil, **options, &block) @template = template @label, @options, @block = label, options @menu = Menu.new(template) @menu.build(&block) if block_given? - @icon = options.delete(:icon) - @style = options.delete(:style) + @icon, @style = icon, style end def ==(other) to_s == other.to_s end def to_s if menu.items.any? - content_tag(:div, class: "btn-group", role: "group") do + tag.div(class: "btn-group", role: "group") do safe_join([render, render_menu], "\n") end else render end @@ -52,11 +51,11 @@ classes.uniq end def button_label(content, options) icon = icon(@icon) if @icon - label = content_tag(:span, content, class: "btn-label") + label = tag.span(content, class: "btn-label") safe_join([icon, label].compact, " ") end def button_style @@ -75,35 +74,27 @@ end class Link < Item attr_reader :instance_or_url - def initialize(template, label, instance_or_url={}, options={}, &block) - if instance_or_url.is_a?(Hash) - super(template, label, instance_or_url, &block) - else - super(template, label, options, &block) - @instance_or_url = instance_or_url - end + def initialize(template, label, instance_or_url=nil, **options, &block) + super(template, label, **options, &block) + @instance_or_url = instance_or_url end def render - if @instance_or_url - admin_link_to(button_label(label, options), instance_or_url, options) - else - admin_link_to(button_label(label, options), options) - end + admin_link_to(button_label(label, options), instance_or_url, **options) end end class Dropdown < Button def options super.merge(type: "button", data: { bs_toggle: "dropdown" }) end def label safe_join([ - super, content_tag(:span, "", class: "caret") + super, tag.span("", class: "caret") ], " ") end def button_style_classes super + ["dropdown-toggle"]