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 +17 -4
- data/lib/mobile_pagination/paginate.rb +24 -16
- data/lib/mobile_pagination/templates.rb +23 -17
- data/lib/mobile_pagination/version.rb +1 -1
- metadata +1 -1
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)
|
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)}"
|
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
|
-
|
35
|
+
def previous_page?
|
36
|
+
@current_page > 1
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
49
|
+
def display_first_page?
|
42
50
|
@current_page != 1
|
43
51
|
end
|
44
52
|
|
45
|
-
def
|
46
|
-
|
53
|
+
def display_next_page?
|
54
|
+
display_last_page? && !second_to_last?
|
47
55
|
end
|
48
56
|
|
49
|
-
def
|
50
|
-
|
57
|
+
def display_last_page?
|
58
|
+
@current_page != @total_pages
|
51
59
|
end
|
52
60
|
|
53
|
-
def
|
54
|
-
@current_page
|
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
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
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
|
32
|
-
markup << previous_page_html if
|
33
|
-
markup << next_page_html if
|
34
|
-
markup << last_page_html if
|
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
|