Class: Middleman::Paginate::Extension::Pager

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman/paginate/extension.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path, suffix, current_page, total_pages, per_page) ⇒ Pager

Returns a new instance of Pager.



21
22
23
24
25
26
27
# File 'lib/middleman/paginate/extension.rb', line 21

def initialize(base_path, suffix, current_page, total_pages, per_page)
  @base_path = base_path
  @suffix = suffix
  @current_page = current_page
  @total_pages = total_pages
  @per_page = per_page
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



19
20
21
# File 'lib/middleman/paginate/extension.rb', line 19

def current_page
  @current_page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



19
20
21
# File 'lib/middleman/paginate/extension.rb', line 19

def per_page
  @per_page
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



19
20
21
# File 'lib/middleman/paginate/extension.rb', line 19

def total_pages
  @total_pages
end

Instance Method Details

#full_page_path(page = current_page) ⇒ Object



37
38
39
# File 'lib/middleman/paginate/extension.rb', line 37

def full_page_path(page = current_page)
  "#{@base_path}#{page == 1 ? '/index' : @suffix.gsub(/:num/, page.to_s)}.html"
end

#next_pageObject



29
30
31
# File 'lib/middleman/paginate/extension.rb', line 29

def next_page
  current_page < total_pages && current_page + 1
end

#page_path(page = current_page) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/middleman/paginate/extension.rb', line 41

def page_path(page = current_page)
  full_path = full_page_path(page)
  if full_path.end_with?("/index.html")
    full_path.gsub(/index\.html$/, '')
  else
    full_path
  end
end

#previous_pageObject



33
34
35
# File 'lib/middleman/paginate/extension.rb', line 33

def previous_page
  current_page > 1 && current_page - 1
end