Sha256: a38977b9e649e957dc607a59cff86dee4e1cba9ddd9dbe7763cd26d97ee85f49

Contents?: true

Size: 849 Bytes

Versions: 2

Compression:

Stored size: 849 Bytes

Contents

module Trestle
  module ToolbarsHelper
    def toolbar(name, &block)
      toolbar = (toolbars[name.to_s] ||= Toolbar.new)
      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

2 entries across 2 versions & 1 rubygems

Version Path
trestle-0.8.11 app/helpers/trestle/toolbars_helper.rb
trestle-0.8.10 app/helpers/trestle/toolbars_helper.rb