Module: ActiveAdmin::Resource::PagePresenters

Included in:
Page, ActiveAdmin::Resource
Defined in:
lib/active_admin/resource/page_presenters.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) default_index_class

for setting default css class in admin ui



6
7
8
# File 'lib/active_admin/resource/page_presenters.rb', line 6

def default_index_class
  @default_index
end

- (Class) find_index_class(symbol_or_class) (protected)

Returns the actual class for renderering the main content on the index page. To set this, use the :as option in the page_presenter block.

Parameters:

  • symbol_or_class (Symbol, Class)

    The component symbol or class

Returns:

  • (Class)


71
72
73
74
75
76
77
78
# File 'lib/active_admin/resource/page_presenters.rb', line 71

def find_index_class(symbol_or_class)
  case symbol_or_class
  when Symbol
    ::ActiveAdmin::Views.const_get("IndexAs" + symbol_or_class.to_s.camelcase)
  when Class
    symbol_or_class
  end
end

- (Object) get_page_presenter(action, type = nil)

Returns a stored page config

Parameters:

  • action (Symbol, String)

    The action to get the config for

  • type (String) (defaults to: nil)

    The string specified in the presenters index_name method



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_admin/resource/page_presenters.rb', line 36

def get_page_presenter(action, type=nil)

  if action.to_s == "index" && type && page_presenters[:index].kind_of?(Hash)
    page_presenters[:index][type.to_sym]
  elsif action.to_s == "index" && page_presenters[:index].kind_of?(Hash)
    page_presenters[:index].default
  else
    page_presenters[action.to_sym]
  end

end

- (Object) page_presenters

A hash of page configurations for the controller indexed by action name



11
12
13
# File 'lib/active_admin/resource/page_presenters.rb', line 11

def page_presenters
  @page_presenters ||= {}
end

- (Object) set_index_presenter(index_as, page_presenter) (protected)

Stores a config for all index actions supplied

Parameters:

  • index_as (Symbol)

    The index type to store in the configuration

  • page_presenter (PagePresenter)

    The intance of PagePresenter to store



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/active_admin/resource/page_presenters.rb', line 54

def set_index_presenter(index_as, page_presenter)
  page_presenters[:index] ||= {}

  #set first index as default value or the index with default param set to to true
  if page_presenters[:index].empty? || page_presenter[:default] == true
    page_presenters[:index].default = page_presenter
    @default_index = find_index_class(page_presenter[:as])
  end

  page_presenters[:index][index_as] = page_presenter
end

- (Object) set_page_presenter(action, page_presenter)

Sets a page config for a given action

Parameters:

  • action (String, Symbol)

    The action to store this configuration for

  • page_presenter (PagePresenter)

    The instance of PagePresenter to store



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_admin/resource/page_presenters.rb', line 19

def set_page_presenter(action, page_presenter)

  if action.to_s == "index" && page_presenter[:as]
    index_class = find_index_class(page_presenter[:as])
    page_presenter_key = index_class.index_name.to_sym
    set_index_presenter page_presenter_key, page_presenter
  else
    page_presenters[action.to_sym] = page_presenter
  end

end