mobile_pagination 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
26
26
 
27
27
 
28
28
  ## Usage
29
- Initializes with 4 options: `current_page, total_pages, query, path`
29
+ Initializes with 4 options: `current_page, total_pages, query, path`.
30
30
 
31
31
  ```ruby
32
32
  # in your view, you may have something like this:
@@ -49,15 +49,28 @@ def opts
49
49
  end
50
50
 
51
51
  def pagination
52
- @pagination ||= MobilePagination::Paginate.new(opts).html
52
+ @pagination ||= MobilePagination::Paginate.new(opts)
53
53
  end
54
54
 
55
55
  def pagination_html
56
- pagination.html
56
+ pagination.html # => returns paginated elements
57
57
  end
58
58
 
59
+ # Other public methods
60
+
61
+ previous_page_link # => path for the previous page
62
+ next_page_link # => path for the next page
63
+
64
+ previous_page? # => true or false
65
+ next_page? # => true or false
66
+ should_paginate? # => true or false
67
+
68
+ # Readers
69
+ current_page, total_pages query, path
59
70
  ```
60
71
 
72
+ Take a look at lib/mobile_pagination/paginate.rb for more information.
73
+
61
74
  ### Overrides
62
75
 
63
76
  If you don't like list items, you will need to override `MobilePagination::Templates`
@@ -69,7 +82,7 @@ module MobilePagination
69
82
  module Templates
70
83
 
71
84
  def first_page_html
72
- "<p'>
85
+ "<p>
73
86
  <a title='First Page' href='#{first_page_link}'>Luke's Page</a> |
74
87
  <p>"
75
88
  end
@@ -16,42 +16,50 @@ module MobilePagination
16
16
  @path = opts[:path] || '/'
17
17
  end
18
18
 
19
- def first_page_link
20
- "#{page_url}"
21
- end
22
-
23
19
  def previous_page_link
24
20
  previous == 1 ? "#{first_page_link}" : "#{page_url(previous)}"
25
21
  end
26
22
 
27
23
  def next_page_link
28
- "#{page_url(@current_page + 1)}" if @current_page < @total_pages
24
+ "#{page_url(@current_page + 1)}"
25
+ end
26
+
27
+ def first_page_link
28
+ "#{page_url}"
29
29
  end
30
30
 
31
31
  def last_page_link
32
32
  "#{page_url(@total_pages)}"
33
33
  end
34
34
 
35
- private
35
+ def previous_page?
36
+ @current_page > 1
37
+ end
36
38
 
37
- def should_paginate?
38
- @total_pages > 1
39
- end
39
+ def next_page?
40
+ @current_page < @total_pages
41
+ end
42
+
43
+ def should_paginate?
44
+ @total_pages > 1
45
+ end
46
+
47
+ private
40
48
 
41
- def first_page?
49
+ def display_first_page?
42
50
  @current_page != 1
43
51
  end
44
52
 
45
- def previous_page?
46
- @current_page > 2
53
+ def display_next_page?
54
+ display_last_page? && !second_to_last?
47
55
  end
48
56
 
49
- def next_page?
50
- last_page? && !second_to_last?
57
+ def display_last_page?
58
+ @current_page != @total_pages
51
59
  end
52
60
 
53
- def last_page?
54
- @current_page != @total_pages
61
+ def display_previous_page?
62
+ @current_page > 2
55
63
  end
56
64
 
57
65
  def second_to_last?
@@ -2,38 +2,44 @@ module MobilePagination
2
2
  module Templates
3
3
 
4
4
  def first_page_html
5
- "<li>
6
- <a title='First Page' href='#{first_page_link}'>First Page</a> |
7
- </li>"
5
+ generate_pagination_link title: 'First Page',
6
+ href: first_page_link,
7
+ text: 'First Page'
8
8
  end
9
9
 
10
10
  def previous_page_html
11
- "<li>
12
- <a title='Previous Page' href='#{previous_page_link}'>Previous Page</a> |
13
- </li>"
11
+ generate_pagination_link title: 'Previous Page',
12
+ href: previous_page_link,
13
+ text: 'Previous Page'
14
14
  end
15
15
 
16
16
  def next_page_html
17
- "<li>
18
- <a title='Next Page' href='#{next_page_link}'>Next Page</a> |
19
- </li>"
17
+ generate_pagination_link title: 'Next Page',
18
+ href: next_page_link,
19
+ text: 'Next Page'
20
20
  end
21
21
 
22
22
  def last_page_html
23
- "<li>
24
- <a title='Last Page' href='#{last_page_link}'>Last Page</a>
25
- </li>"
23
+ generate_pagination_link title: 'Last Page',
24
+ href: last_page_link,
25
+ text: 'Last Page'
26
26
  end
27
27
 
28
28
  def html
29
29
  return '' unless should_paginate?
30
30
  ''.tap do |markup|
31
- markup << first_page_html if first_page?
32
- markup << previous_page_html if previous_page?
33
- markup << next_page_html if next_page?
34
- markup << last_page_html if last_page?
31
+ markup << first_page_html if display_first_page?
32
+ markup << previous_page_html if display_previous_page?
33
+ markup << next_page_html if display_next_page?
34
+ markup << last_page_html if display_last_page?
35
35
  end
36
36
  end
37
37
 
38
+ def generate_pagination_link(opts)
39
+ "<li>
40
+ <a title='#{opts[:title]}' href='#{opts[:href]}'>#{opts[:text]}</a>
41
+ </li>"
42
+ end
43
+
38
44
  end
39
- end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module MobilePagination
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobile_pagination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: