Module: PaginationRenderLogic::Digg

Defined in:
lib/pagination_render_logic/digg.rb

Overview

Provides logic for building digg style pagination First Previous 1 2 3 … 22 23 24 25 26 [27] 28 29 30 31 32 … 48 49 50 Next Last

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#after_first_pageObject

Returns the value of attribute after_first_page.



5
6
7
# File 'lib/pagination_render_logic/digg.rb', line 5

def after_first_page
  @after_first_page
end

#arround_current_pageObject

Returns the value of attribute arround_current_page.



5
6
7
# File 'lib/pagination_render_logic/digg.rb', line 5

def arround_current_page
  @arround_current_page
end

#current_pageObject

Returns the value of attribute current_page.



5
6
7
# File 'lib/pagination_render_logic/digg.rb', line 5

def current_page
  @current_page
end

#first_page_sectionObject

Returns the value of attribute first_page_section.



5
6
7
# File 'lib/pagination_render_logic/digg.rb', line 5

def first_page_section
  @first_page_section
end

#last_page_sectionObject

Returns the value of attribute last_page_section.



5
6
7
# File 'lib/pagination_render_logic/digg.rb', line 5

def last_page_section
  @last_page_section
end

#middle_sectionObject

Returns the value of attribute middle_section.



5
6
7
# File 'lib/pagination_render_logic/digg.rb', line 5

def middle_section
  @middle_section
end

#total_pagesObject

Returns the value of attribute total_pages.



5
6
7
# File 'lib/pagination_render_logic/digg.rb', line 5

def total_pages
  @total_pages
end

Instance Method Details

#config(args = {}) ⇒ Object



9
10
11
12
13
14
# File 'lib/pagination_render_logic/digg.rb', line 9

def config(args = {})
  @total_pages = args[:total_pages] || 0
  @after_first_page = args[:after_first_page] || 3
  @arround_current_page = args[:arround_current_page] || 5
  @current_page = args[:current_page] || 1
end

#config!(args = {}) ⇒ Object



16
17
18
19
# File 'lib/pagination_render_logic/digg.rb', line 16

def config!(args = {})
  config(args)
  setup
end

#first_pageObject



54
55
56
# File 'lib/pagination_render_logic/digg.rb', line 54

def first_page
  1
end

#has_first_page?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/pagination_render_logic/digg.rb', line 50

def has_first_page?
  @current_page > 1
end

#has_first_page_section?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/pagination_render_logic/digg.rb', line 70

def has_first_page_section?
  not @first_page_section.empty?
end

#has_last_page?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/pagination_render_logic/digg.rb', line 42

def has_last_page?
  @current_page < @total_pages
end

#has_last_page_section?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/pagination_render_logic/digg.rb', line 74

def has_last_page_section?
  not @last_page_section.empty?
end

#has_links?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/pagination_render_logic/digg.rb', line 66

def has_links?
  @total_pages > 1
end

#has_next_page?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/pagination_render_logic/digg.rb', line 34

def has_next_page?
  @current_page < @total_pages
end

#has_previous_page?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/pagination_render_logic/digg.rb', line 58

def has_previous_page?
  @current_page > 1
end

#last_pageObject



46
47
48
# File 'lib/pagination_render_logic/digg.rb', line 46

def last_page
  @total_pages
end

#next_pageObject



38
39
40
# File 'lib/pagination_render_logic/digg.rb', line 38

def next_page
  @current_page + 1
end

#previous_pageObject



62
63
64
# File 'lib/pagination_render_logic/digg.rb', line 62

def previous_page
  @current_page - 1
end

#setupObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pagination_render_logic/digg.rb', line 21

def setup
  @middle_section = ([current_page - arround_current_page, 1].max..[current_page + arround_current_page, total_pages].min).to_a
  @first_page_section = (1..[after_first_page, total_pages].min).to_a
  @last_page_section = ([1, total_pages - after_first_page + 1].max..total_pages).to_a
  if (total_pages / 2) > current_page
    merge_left
    merge_right
  else
    merge_right
    merge_left
  end
end