Class: DynamicScaffold::List::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_scaffold/list/pagination.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Pagination

Returns a new instance of Pagination.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dynamic_scaffold/list/pagination.rb', line 16

def initialize(options)
  options = {
    per_page: 25,
    window: 0,                # kaminari options
    outer_window: 0,          # kaminari options
    left: 0,                  # kaminari options
    right: 0,                 # kaminari options
    param_name: :page,        # kaminari options
    total_count: true,        # Whether to display total count on active page like `2 / 102`
    end_buttons: true,        # Whether to display buttons to the first and last page.
    neighbor_buttons: true,   # Whether to display buttons to the next and prev page.
    gap_buttons: false,       # Whether to display gap buttons.
    highlight_current: false # Whether to highlight the current page.
  }.merge(options)
  @kaminari_options = options.extract!(:window, :outer_window, :left, :right, :param_name)
  @param_name = @kaminari_options[:param_name]
  options.each {|name, value| instance_variable_set("@#{name}", value) }
end

Instance Attribute Details

#end_buttonsObject (readonly)

Returns the value of attribute end_buttons.



6
7
8
# File 'lib/dynamic_scaffold/list/pagination.rb', line 6

def end_buttons
  @end_buttons
end

#gap_buttonsObject (readonly)

Returns the value of attribute gap_buttons.



6
7
8
# File 'lib/dynamic_scaffold/list/pagination.rb', line 6

def gap_buttons
  @gap_buttons
end

#highlight_currentObject (readonly)

Returns the value of attribute highlight_current.



6
7
8
# File 'lib/dynamic_scaffold/list/pagination.rb', line 6

def highlight_current
  @highlight_current
end

#kaminari_optionsObject (readonly)

Returns the value of attribute kaminari_options.



6
7
8
# File 'lib/dynamic_scaffold/list/pagination.rb', line 6

def kaminari_options
  @kaminari_options
end

#neighbor_buttonsObject (readonly)

Returns the value of attribute neighbor_buttons.



6
7
8
# File 'lib/dynamic_scaffold/list/pagination.rb', line 6

def neighbor_buttons
  @neighbor_buttons
end

#param_nameObject (readonly)

Returns the value of attribute param_name.



6
7
8
# File 'lib/dynamic_scaffold/list/pagination.rb', line 6

def param_name
  @param_name
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



6
7
8
# File 'lib/dynamic_scaffold/list/pagination.rb', line 6

def per_page
  @per_page
end

#total_countObject (readonly)

Returns the value of attribute total_count.



6
7
8
# File 'lib/dynamic_scaffold/list/pagination.rb', line 6

def total_count
  @total_count
end

Instance Method Details

#page_class(page, _records) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/dynamic_scaffold/list/pagination.rb', line 41

def page_class(page, _records)
  if page.inside_window?
    'inner'
  elsif page.left_outer?
    'left-outer'
  elsif page.right_outer?
    'right-outer'
  end
end

#page_number(page, records) ⇒ Object



35
36
37
38
39
# File 'lib/dynamic_scaffold/list/pagination.rb', line 35

def page_number(page, records)
  return page unless total_count

  "#{page} / #{records.total_pages}"
end