Sha256: 31e8d8c422b4004ccacfcf6cb67f3e3723f9d8daf0cd085d2e408e41f8582162

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'active_support/core_ext/hash'
require 'admino/table/presenter'
require 'admino/query/base_presenter'

module Admino
  module ActionViewExtension
    module Internals
      def self.present_query(query, context, options)
        presenter_klass = options.fetch(:presenter, Admino::Query::BasePresenter)
        presenter_klass.new(query, context)
      end
    end

    def table_for(collection, options = {}, &block)
      options.symbolize_keys!
      options.assert_valid_keys(:presenter, :class, :html)
      presenter_klass = options.fetch(:presenter, Admino::Table::Presenter)
      presenter = presenter_klass.new(collection, options[:class], self)
      html_options = options.fetch(:html, {})
      presenter.to_html(html_options, &block)
    end

    def filters_for(query, options = {}, &block)
      options.symbolize_keys!
      options.assert_valid_keys(:presenter)
      Internals.present_query(query, self, options).filter_groups.each(&block)
    end

    def sortings_for(query, options = {}, &block)
      options.symbolize_keys!
      options.assert_valid_keys(:presenter)
      Internals.present_query(query, self, options).sorting.scopes.each(&block)
    end

    def search_form_for(query, options = {}, &block)
      options.symbolize_keys!
      options.assert_valid_keys(:presenter)
      Internals.present_query(query, self, options).form(&block)
    end

    def simple_search_form_for(query, options = {}, &block)
      options.symbolize_keys!
      options.assert_valid_keys(:presenter)
      Internals.present_query(query, self, options).simple_form(&block)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
admino-0.0.13 lib/admino/action_view_extension.rb