Module: Capybara::ActiveAdmin::Selectors::Table

Defined in:
lib/capybara/active_admin/selectors/table.rb

Overview

Selectors for table_for, it's rows and cells.

Instance Method Summary collapse

Instance Method Details

#table_cell_selector(column = nil) ⇒ Object

Returns selector.

Parameters:

  • column (String, nil) (defaults to: nil)

    column name.

Returns:

  • selector.



43
44
45
46
47
48
49
# File 'lib/capybara/active_admin/selectors/table.rb', line 43

def table_cell_selector(column = nil)
  return 'td.col' if column.nil?

  # Downcase, strip non-alphanumeric chars (e.g. '/'), convert spaces to '_', deduplicate '_'
  column = column.to_s.downcase.gsub(/[^a-z0-9\s]/, '').gsub(/\s+/, '_').squeeze('_')
  "td.col.col-#{column}"
end

#table_header_selector(text = nil, options = {}) ⇒ Object

Returns selector.

Parameters:

  • text (String) (defaults to: nil)

    column header text.

  • options (Hash) (defaults to: {})
  • column (Hash)

    a customizable set of options

  • sortable (Hash)

    a customizable set of options

  • sort_direction (Hash)

    a customizable set of options

Returns:

  • selector.



31
32
33
34
35
36
37
38
39
# File 'lib/capybara/active_admin/selectors/table.rb', line 31

def table_header_selector(text = nil, options = {})
  return 'thead > tr > th.col' if text.nil?

  column = (options[:column] || text).to_s.tr(' ', '_').downcase
  selector = "th.col.col-#{column}"
  selector += '.sortable' if options[:sortable]
  selector += ".sorted-#{options[:sort_direction].to_s.downcase}" if options[:sort_direction].present?
  "thead > tr > #{selector}"
end

#table_row_selector(record_id = nil) ⇒ Object

Returns selector.

Parameters:

  • record_id (String, Integer, nil) (defaults to: nil)

    record ID.

Returns:

  • selector.



19
20
21
22
23
# File 'lib/capybara/active_admin/selectors/table.rb', line 19

def table_row_selector(record_id = nil)
  return 'tbody > tr' if record_id.nil?

  %(tbody > tr[id$="_#{record_id}"])
end

#table_scope_selectorObject



55
56
57
# File 'lib/capybara/active_admin/selectors/table.rb', line 55

def table_scope_selector
  'li.scope'
end

#table_scopes_container_selectorObject



51
52
53
# File 'lib/capybara/active_admin/selectors/table.rb', line 51

def table_scopes_container_selector
  '.scopes > ul.table_tools_segmented_control'
end

#table_selector(resource_name = nil) ⇒ Object

Returns selector.

Parameters:

  • resource_name (String, nil) (defaults to: nil)

    active admin resource name.

Returns:

  • selector.



10
11
12
13
14
15
# File 'lib/capybara/active_admin/selectors/table.rb', line 10

def table_selector(resource_name = nil)
  return 'table.index_table' if resource_name.nil?

  resource_name = resource_name.to_s.gsub(' ', '_').pluralize.downcase
  "table#index_table_#{resource_name}"
end