Module: Awestruct::Extensions::Paginator::Paginated

Defined in:
lib/awestruct/extensions/paginator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page



9
10
11
# File 'lib/awestruct/extensions/paginator.rb', line 9

def current_page
  @current_page
end

#current_page_indexObject

Returns the value of attribute current_page_index



10
11
12
# File 'lib/awestruct/extensions/paginator.rb', line 10

def current_page_index
  @current_page_index
end

#next_pageObject

Returns the value of attribute next_page



7
8
9
# File 'lib/awestruct/extensions/paginator.rb', line 7

def next_page
  @next_page
end

#pagesObject

Returns the value of attribute pages



11
12
13
# File 'lib/awestruct/extensions/paginator.rb', line 11

def pages
  @pages
end

#previous_pageObject

Returns the value of attribute previous_page



8
9
10
# File 'lib/awestruct/extensions/paginator.rb', line 8

def previous_page
  @previous_page
end

#windowObject

Returns the value of attribute window



6
7
8
# File 'lib/awestruct/extensions/paginator.rb', line 6

def window
  @window
end

Instance Method Details



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/awestruct/extensions/paginator.rb', line 13

def links
  html = %Q(<div class="pagination-links">)
  unless ( previous_page.nil? )
    html += %Q(<a href="#{previous_page.url}" class="previous-link">Previous</a> )
  end
  first_skip = false
  second_skip = false
  pages.each_with_index do |page, i|
    if ( i == current_page_index )
      html += %Q(<span class="current-page">#{i+1}</span> )
    elsif ( i <= window )
      html += %Q(<a href="#{page.url}" class="page-link">#{i+1}</a> )
    elsif ( ( i > window ) && ( i < ( current_page_index - window ) ) && ! first_skip  )
      html += %Q(<span class="skip">...</span>)
      first_skip = true
    elsif ( ( i > ( current_page_index + window ) ) && ( i < ( ( pages.size - window ) - 1 ) ) && ! second_skip )
      html += %Q(<span class="skip">...</span>)
      second_skip = true
    elsif ( ( i >= ( current_page_index - window ) ) && ( i <= ( current_page_index + window ) ) )
      html += %Q(<a href="#{page.url}" class="page-link">#{i+1}</a> )
    elsif ( i >= ( ( pages.size - window ) - 1 ) )
      html += %Q(<a href="#{page.url}" class="page-link">#{i+1}</a> )
    end
  end
  unless ( next_page.nil? )
    html += %Q(<a href="#{next_page.url}" class="next-link">Next</a> )
  end
  html += %Q(</div>)
  html
end