Sha256: 3f83f93a985a6b0aeb8d1118fa15639a88fd5ebff8a3ed8d47bebb20fac9364e

Contents?: true

Size: 1.42 KB

Versions: 26

Compression:

Stored size: 1.42 KB

Contents

module ActiveAdmin
  module ViewHelpers
    module DownloadFormatLinksHelper

      def build_download_format_links(formats = self.class.formats)
        params = request.query_parameters.except :format, :commit
        div class: "download_links" do
          span I18n.t('active_admin.download')
          formats.each do |format|
            a format.upcase, href: url_for(params: params, format: format)
          end
        end
      end

      def self.included base
        base.extend ClassMethods
      end

      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 to the list of available formats available for data
        # export. You must register the extension prior to adding it here.
        # @param [Symbol] format the mime type to add
        # @return [Array] A copy of the updated formats array.
        def add_format(format)
          unless Mime::Type.lookup_by_extension format
            raise ArgumentError, "Please register the #{format} mime type with `Mime::Type.register`"
          end
          @formats << format unless formats.include? format
          formats
        end
      end

    end
  end
end

Version data entries

26 entries across 26 versions & 4 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/download_format_links_helper.rb
yousty-activeadmin-1.0.17.pre lib/active_admin/view_helpers/download_format_links_helper.rb
yousty-activeadmin-1.0.16.pre lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/download_format_links_helper.rb
yousty-activeadmin-1.0.15.pre lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin-1.0.0.pre5 lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin-orac-1.0.0.pre4 lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin-orac-1.0.0 lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin-orac-1.0.0.pre.orac lib/active_admin/view_helpers/download_format_links_helper.rb
yousty-activeadmin-1.0.14.pre lib/active_admin/view_helpers/download_format_links_helper.rb
yousty-activeadmin-1.0.13.pre lib/active_admin/view_helpers/download_format_links_helper.rb
yousty-activeadmin-1.0.12.pre lib/active_admin/view_helpers/download_format_links_helper.rb
yousty-activeadmin-1.0.11.pre lib/active_admin/view_helpers/download_format_links_helper.rb
yousty-activeadmin-1.0.10.pre lib/active_admin/view_helpers/download_format_links_helper.rb
yousty-activeadmin-1.0.9.pre lib/active_admin/view_helpers/download_format_links_helper.rb
yousty-activeadmin-1.0.8.pre lib/active_admin/view_helpers/download_format_links_helper.rb
activeadmin-1.0.0.pre4 lib/active_admin/view_helpers/download_format_links_helper.rb