Class: Middleman::Webcomic::Pager

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-webcomic/pager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(articles, base_path = "/page", page_size = 5) ⇒ Pager

Returns a new instance of Pager.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/middleman-webcomic/pager.rb', line 6

def initialize(articles, base_path="/page", page_size=5)
  @all= articles
  @page_size= page_size
  @base_path= base_path
  @page_sets= @all.in_groups_of(page_size, false)
  @pages= []
  @current_page=1
  @page_sets.each do |art_ary|
    @pages << Thor::CoreExt::HashWithIndifferentAccess.new({
      'articles' => art_ary,
      'page' => @current_page,
      'uri' => "#{base_path}/#{current_page}",
      'pager' => self
    })
    @current_page += 1
  end
  @current_page= nil
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



4
5
6
# File 'lib/middleman-webcomic/pager.rb', line 4

def all
  @all
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



4
5
6
# File 'lib/middleman-webcomic/pager.rb', line 4

def base_url
  @base_url
end

#current_pageObject (readonly)

Returns the value of attribute current_page.



4
5
6
# File 'lib/middleman-webcomic/pager.rb', line 4

def current_page
  @current_page
end

#page_setsObject (readonly)

Returns the value of attribute page_sets.



4
5
6
# File 'lib/middleman-webcomic/pager.rb', line 4

def page_sets
  @page_sets
end

#pagesObject (readonly)

Returns the value of attribute pages.



4
5
6
# File 'lib/middleman-webcomic/pager.rb', line 4

def pages
  @pages
end

Instance Method Details

#[](key) ⇒ Object



46
47
48
# File 'lib/middleman-webcomic/pager.rb', line 46

def [](key)
  @pages[key]
end

#eachObject



37
38
39
40
41
42
43
44
# File 'lib/middleman-webcomic/pager.rb', line 37

def each
  @current_page=1
  @pages.each do |page_set|
    yield page_set
    @current_page += 1
  end
  @current_page= nil
end

#firstObject



29
30
31
# File 'lib/middleman-webcomic/pager.rb', line 29

def first
  @pages.first
end

#lastObject



33
34
35
# File 'lib/middleman-webcomic/pager.rb', line 33

def last
  @pages.last
end

#lengthObject



25
26
27
# File 'lib/middleman-webcomic/pager.rb', line 25

def length
  @pages.length
end