Sha256: 099dae8eda6b7526209e6c1c836473c880e34909eac398253bd47fb654e20794

Contents?: true

Size: 1.75 KB

Versions: 7

Compression:

Stored size: 1.75 KB

Contents

module ActiveAdmin
  module ViewHelpers
    module DownloadFormatLinksHelper

      module ClassMethods

        # A ready only of formats to make available in index/paginated
        # collection view.
        # @return [Array]
        # @see add_format for information on adding custom download link
        # formats
        def formats
          @formats ||= [:csv, :xml, :json]
          @formats.clone
        end

        # Adds a mime type extension to the list of available formats.
        # You must register the extension prior to adding it to the list
        # of avilable formats. This should be used by plugins that want
        # to add additional formats to the download format links.
        # @param [Symbol] extension the mime extension to add
        # @return [Array] A copy of the updated formats array.
        def add_format extension
          unless formats.include?(extension)
            if Mime::Type.lookup_by_extension(extension).nil?
              raise ArgumentError, "The mime extension you defined: #{extension} is not registered. Please register it via Mime::Type.register before adding it to the available formats."
            end
          @formats << extension
          end
          formats
        end
      end

      # TODO: Refactor to new HTML DSL
      def build_download_format_links(formats = self.class.formats)
        links = formats.collect do |format|
          link_to format.to_s.upcase, { :format => format}.merge(request.query_parameters.except(:commit, :format))
        end
        div :class => "download_links" do
          text_node [I18n.t('active_admin.download'), links].flatten.join("&nbsp;").html_safe
        end
      end

      def self.included base
        base.extend ClassMethods
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
activeadmin-0.6.6 lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin-0.6.5 lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin-0.6.4 lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin-0.6.3 lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin-0.6.2 lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin-0.6.1 lib/active_admin/view_helpers/download_format_links_helper.rb
aa-rails4-0.6.0 lib/active_admin/view_helpers/download_format_links_helper.rb