Sha256: 1f2b2ae3b6c00832136299d42fda7f79424f283110169b6cf37493cca51a4075

Contents?: true

Size: 1.75 KB

Versions: 47

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

47 entries across 47 versions & 2 rubygems

Version Path
lalala-4.0.0.dev.141 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.128 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.126 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.125 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.124 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.123 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.118 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.116 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.114 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.113 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.111 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.109 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb
lalala-4.0.0.dev.107 vendor/deps/active_admin/lib/active_admin/view_helpers/download_format_links_helper.rb