Class: Jekyll_Tagger::Pager

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll_tagger/pager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items, page_size, url_maker) ⇒ Pager

Returns a new instance of Pager.



5
6
7
8
9
10
11
12
# File 'lib/jekyll_tagger/pager.rb', line 5

def initialize(items,page_size,url_maker)
  @items      = items
  @page_size  = page_size
  @url_maker  = url_maker

  @item_count = items.count
  @page_count = @page_size != 0 ? ((@item_count / @page_size) + (@item_count % @page_size > 0 ? 1 : 0)) : 1
end

Instance Attribute Details

#index=(value) ⇒ Object (writeonly)

Sets the attribute index

Parameters:

  • value

    the value to set the attribute index to.



4
5
6
# File 'lib/jekyll_tagger/pager.rb', line 4

def index=(value)
  @index = value
end

#item_countObject (readonly)

Returns the value of attribute item_count.



3
4
5
# File 'lib/jekyll_tagger/pager.rb', line 3

def item_count
  @item_count
end

#itemsObject (readonly)

Returns the value of attribute items.



3
4
5
# File 'lib/jekyll_tagger/pager.rb', line 3

def items
  @items
end

#page_countObject (readonly)

Returns the value of attribute page_count.



3
4
5
# File 'lib/jekyll_tagger/pager.rb', line 3

def page_count
  @page_count
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



3
4
5
# File 'lib/jekyll_tagger/pager.rb', line 3

def page_size
  @page_size
end

#url_makerObject (readonly)

Returns the value of attribute url_maker.



3
4
5
# File 'lib/jekyll_tagger/pager.rb', line 3

def url_maker
  @url_maker
end

Instance Method Details

#page_first(number) ⇒ Object



47
48
49
# File 'lib/jekyll_tagger/pager.rb', line 47

def page_first(number)
  return PageInfo.new(self,1,number==1)
end

#page_items(kk) ⇒ Object



14
15
16
# File 'lib/jekyll_tagger/pager.rb', line 14

def page_items(kk)
  return @page_size != 0 ? @items[((kk-1)*@page_size)..(kk*@page_size-1)] : @items
end

#page_last(number) ⇒ Object



50
51
52
# File 'lib/jekyll_tagger/pager.rb', line 50

def page_last(number)
  return PageInfo.new(self,@page_count,number==@page_count)
end

#page_list(number, page_show, current) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jekyll_tagger/pager.rb', line 18

def page_list(number,page_show,current)
  pages = []
  ps = page_show-1
  s1 = current - ps/2
  s2 = current + ps/2 + ps%2
  if s1 < 1
    s2 += (1 - s1)
    s1  = 1
  end
  if s2 > page_count
    s1 -= (s2 - page_count)
    s2  = page_count
    if s1 < 1
      s1 = 1
    end
  end
  for kk in (s1)..(s2)
    pages.push(PageInfo.new(self,kk,kk==current))
  end
  return pages
end

#page_next(number) ⇒ Object



40
41
42
# File 'lib/jekyll_tagger/pager.rb', line 40

def page_next(number)
  return PageInfo.new(self,number+1,false)
end

#page_prev(number) ⇒ Object



43
44
45
# File 'lib/jekyll_tagger/pager.rb', line 43

def page_prev(number)
  return PageInfo.new(self,number-1,false)
end