lib/mobile_pagination/paginate.rb in mobile_pagination-0.0.2 vs lib/mobile_pagination/paginate.rb in mobile_pagination-0.0.3
- old
+ new
@@ -33,18 +33,30 @@
def should_paginate?
@total_pages > 1
end
+ def first_page?
+ @current_page != 1
+ end
+
def previous_page?
- @current_page > 1
+ @current_page > 2
end
def next_page?
- not next_page_link.nil?
+ last_page? && !second_to_last?
end
+ def last_page?
+ @current_page != @total_pages
+ end
+
+ def second_to_last?
+ @current_page == (@total_pages - 1)
+ end
+
def current(page)
page = page.nil? ? 1 : page.to_i
page > @total_pages ? @total_pages : page
end
@@ -54,16 +66,16 @@
def page_url(page=nil)
page.nil? ? "#{@path}#{qs_without_key}" : "#{@path}#{qs_with_key(page)}"
end
-
def qs_with_key(page)
"?#{hash_to_query(opts_with_key(page))}"
end
def qs_without_key
- "?#{hash_to_query(opts_without_key)}"
+ str = "#{hash_to_query(opts_without_key)}"
+ str.insert(0, '?') unless str.empty?
end
def opts_with_key(page)
@query_params.merge({ MobilePagination.configuration.page_key => page })
end
\ No newline at end of file