just_paginate 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +38 -3
- data/just_paginate.gemspec +1 -1
- data/lib/just_paginate.rb +3 -4
- metadata +7 -9
- data/lib/just_paginate/common.rb +0 -6
- data/lib/just_paginate/version.rb +0 -3
data/README.md
CHANGED
@@ -2,16 +2,50 @@
|
|
2
2
|
DESCRIPTION:
|
3
3
|
===========
|
4
4
|
|
5
|
-
just_paginate is a framework-agnostic approach to creating paginated
|
5
|
+
just_paginate is a framework-agnostic approach to creating paginated
|
6
|
+
webpages. It has no external dependencies and works with any web
|
7
|
+
framework.
|
6
8
|
|
9
|
+
Consists of two main methods, paginate and page_navigation.
|
7
10
|
|
8
|
-
|
11
|
+
JustPaginate.paginate helps you slice up your collections and, given a
|
12
|
+
page number, entities per page and totoal entity count, gives you the
|
13
|
+
correct range of indexes you need to get. You supply a block where you
|
14
|
+
specify how elements with those indices are to be gathered. Your block
|
15
|
+
needs to return those elements. The JustPaginate method then returns
|
16
|
+
the objects that you sliced in your block, as well as the total number
|
17
|
+
of pages in the pagination.
|
9
18
|
|
19
|
+
JustPaginate.page_navigation generates html for a page-navigator
|
20
|
+
widget that will let you navigate arbitrarily large page ranges: if
|
21
|
+
the range is larger than what can be displayed, it truncates the range
|
22
|
+
of pages. You supply it with current page number, and total number of
|
23
|
+
pages. You pass in a block which, given the page number, will let you
|
24
|
+
construct a html link to that page number.
|
25
|
+
|
26
|
+
Note: There is also a JustPaginate.page_value helper method that will
|
27
|
+
take an arbitrary object, and try to translate it to a (default) page
|
28
|
+
number. If you are using Rails you can simply pass the param
|
29
|
+
specifying current page and JustPaginate will do its best to translate
|
30
|
+
it to a page number integer.
|
10
31
|
|
11
32
|
|
12
33
|
EXAMPLES:
|
13
34
|
======
|
14
35
|
|
36
|
+
Say we have a Rails app, with an index page of paginated Projects. You
|
37
|
+
could do this in the controller, to select the 20 projects for the
|
38
|
+
current page:
|
39
|
+
|
40
|
+
@page = JustPaginate.page_value(params[:page])
|
41
|
+
@project_count = Project.count
|
42
|
+
@projects, @total_pages = JustPaginate.paginate(@page, 20, @project_count) do |index_range|
|
43
|
+
Project.all.slice(index_range)
|
44
|
+
end
|
45
|
+
|
46
|
+
And in the index.html.erb file, to generate the page navigation:
|
47
|
+
|
48
|
+
<%= JustPaginate.page_navigation(@page, @total_pages) { |page_no| "/projects/?page=#{page_no}" } -%>
|
15
49
|
|
16
50
|
|
17
51
|
INSTALL:
|
@@ -19,7 +53,8 @@ INSTALL:
|
|
19
53
|
|
20
54
|
`sudo gem install just_paginate`
|
21
55
|
|
22
|
-
|
56
|
+
Or simply stick just_paginate into your Gemfile and use Bundler to
|
57
|
+
pull it down.
|
23
58
|
|
24
59
|
|
25
60
|
LICENSE:
|
data/just_paginate.gemspec
CHANGED
data/lib/just_paginate.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require "just_paginate/version"
|
2
|
-
require "just_paginate/common"
|
3
|
-
|
4
1
|
module JustPaginate
|
5
2
|
|
3
|
+
VERSION = "0.0.2"
|
4
|
+
|
6
5
|
def self.page_value(page)
|
7
6
|
if page.nil?
|
8
7
|
1
|
@@ -39,7 +38,7 @@ module JustPaginate
|
|
39
38
|
end
|
40
39
|
|
41
40
|
def self.page_links(curr_page, total_page_count, &page_link_constructor)
|
42
|
-
page_labels(curr_page, total_page_count).map do |label|
|
41
|
+
page_labels(curr_page, total_page_count).map do |label|
|
43
42
|
page_element = ""
|
44
43
|
|
45
44
|
if label == "..."
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: just_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-10-03 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &19779880 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *19779880
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: shoulda
|
27
|
-
requirement: &
|
27
|
+
requirement: &19779240 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *19779240
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: shoulda-context
|
38
|
-
requirement: &
|
38
|
+
requirement: &19778580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *19778580
|
47
47
|
description: Framework-agnostic support for paginating collections of things, and
|
48
48
|
linking to paginated things in your webpage
|
49
49
|
email:
|
@@ -58,8 +58,6 @@ files:
|
|
58
58
|
- Rakefile
|
59
59
|
- just_paginate.gemspec
|
60
60
|
- lib/just_paginate.rb
|
61
|
-
- lib/just_paginate/common.rb
|
62
|
-
- lib/just_paginate/version.rb
|
63
61
|
- test/test_helper.rb
|
64
62
|
- test/test_just_paginate.rb
|
65
63
|
homepage: https://gitorious.org/gitorious/just_paginate
|
data/lib/just_paginate/common.rb
DELETED