Sha256: 3a8259a0b4c9496abb3b122bf6fb4ddbcc8a04e199cfb7b6cb3f2bc18cf9aad4

Contents?: true

Size: 901 Bytes

Versions: 4

Compression:

Stored size: 901 Bytes

Contents

module Trestle
  module ToolbarsHelper
    def toolbar(name, options={}, &block)
      toolbar = (toolbars[name.to_s] ||= Toolbar.new)
      toolbar.clear! if options[:clear]
      toolbar.prepend(&block) if block_given?
      toolbar
    end

    def toolbars
      @_toolbars ||= {}
    end

    def render_toolbar(toolbar, *args)
      result = toolbar.groups(self, *args).map do |items|
        if items.many?
          content_tag(:div, class: "btn-group", role: "group") do
            safe_join(items, "\n")
          end
        else
          items.first
        end
      end

      safe_join(result, "\n")
    end

    def deprecated_toolbar(name)
      if content_for?(:"#{name}_toolbar")
        ActiveSupport::Deprecation.warn("Using content_for(:#{name}_toolbar) is deprecated. Please use toolbar(:#{name}) instead.")
        content_for(:"#{name}_toolbar")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trestle-0.9.1 app/helpers/trestle/toolbars_helper.rb
trestle-0.9.0 app/helpers/trestle/toolbars_helper.rb
trestle-0.8.13 app/helpers/trestle/toolbars_helper.rb
trestle-0.8.12 app/helpers/trestle/toolbars_helper.rb