jm81-paginate 0.1.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,4 +1,10 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
1
6
  .project
2
7
  .loadpath
3
8
  *qt_temp*
4
9
  *~
10
+ *.gem
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ require File.join(File.dirname(__FILE__), 'lib', 'jm81-paginate', 'version')
3
4
 
4
5
  begin
5
6
  require 'jeweler'
6
7
  Jeweler::Tasks.new do |gem|
7
8
  gem.name = "jm81-paginate"
9
+ gem.version = Paginate::VERSION.dup
8
10
  gem.summary = "Pagination for DataMapper, ActiveRecord, and Array"
9
11
  gem.description = <<EOF
10
12
  This paginate library assists in paginating collections and results of database
data/TODO CHANGED
File without changes
@@ -1,19 +1,24 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{paginate}
8
- s.version = "0.1.6"
7
+ s.name = %q{jm81-paginate}
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jared Morgan"]
12
- s.date = %q{2009-09-20}
12
+ s.date = %q{2010-08-11}
13
+ s.description = %q{This paginate library assists in paginating collections and results of database
14
+ queries. It is particularly designed for use with DataMapper and ActiveRecord,
15
+ and for the Merb and Rails frameworks, but can be used in many other situations.
16
+ }
13
17
  s.email = %q{jmorgan@morgancreative.net}
14
18
  s.extra_rdoc_files = [
15
19
  "LICENSE",
16
- "README.md"
20
+ "README.md",
21
+ "TODO"
17
22
  ]
18
23
  s.files = [
19
24
  ".gitignore",
@@ -21,19 +26,21 @@ Gem::Specification.new do |s|
21
26
  "README.md",
22
27
  "Rakefile",
23
28
  "TODO",
24
- "VERSION",
29
+ "jm81-paginate.gemspec",
25
30
  "lib/helpers/merb.rb",
31
+ "lib/helpers/rails.rb",
26
32
  "lib/helpers/shared.rb",
27
- "lib/paginate.rb",
33
+ "lib/jm81-paginate.rb",
34
+ "lib/jm81-paginate/version.rb",
28
35
  "lib/paginate/ar.rb",
29
36
  "lib/paginate/dm.rb",
30
37
  "lib/paginate/simple.rb",
31
38
  "lib/paginators/orm.rb",
32
39
  "lib/paginators/simple.rb",
33
- "paginate.gemspec",
34
40
  "spec/fixtures/ar.rb",
35
41
  "spec/fixtures/dm.rb",
36
42
  "spec/helpers/merb_spec.rb",
43
+ "spec/helpers/rails_spec.rb",
37
44
  "spec/helpers/shared_spec.rb",
38
45
  "spec/paginate/ar_spec.rb",
39
46
  "spec/paginate/config_spec.rb",
@@ -45,34 +52,35 @@ Gem::Specification.new do |s|
45
52
  "spec/spec.opts",
46
53
  "spec/spec_helper.rb"
47
54
  ]
48
- s.has_rdoc = true
49
55
  s.homepage = %q{http://github.com/jm81/paginate}
50
56
  s.rdoc_options = ["--charset=UTF-8"]
51
57
  s.require_paths = ["lib"]
52
- s.rubygems_version = %q{1.3.1}
58
+ s.rubygems_version = %q{1.3.7}
53
59
  s.summary = %q{Pagination for DataMapper, ActiveRecord, and Array}
54
60
  s.test_files = [
55
- "spec/fixtures/ar.rb",
56
- "spec/fixtures/dm.rb",
57
- "spec/helpers/merb_spec.rb",
61
+ "spec/spec_helper.rb",
62
+ "spec/shared.rb",
63
+ "spec/paginators/orm_spec.rb",
64
+ "spec/paginators/simple_spec.rb",
58
65
  "spec/helpers/shared_spec.rb",
59
- "spec/paginate/ar_spec.rb",
60
- "spec/paginate/config_spec.rb",
66
+ "spec/helpers/merb_spec.rb",
67
+ "spec/helpers/rails_spec.rb",
61
68
  "spec/paginate/dm_spec.rb",
69
+ "spec/paginate/config_spec.rb",
62
70
  "spec/paginate/simple_spec.rb",
63
- "spec/paginators/orm_spec.rb",
64
- "spec/paginators/simple_spec.rb",
65
- "spec/shared.rb",
66
- "spec/spec_helper.rb"
71
+ "spec/paginate/ar_spec.rb",
72
+ "spec/fixtures/dm.rb",
73
+ "spec/fixtures/ar.rb"
67
74
  ]
68
75
 
69
76
  if s.respond_to? :specification_version then
70
77
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
71
- s.specification_version = 2
78
+ s.specification_version = 3
72
79
 
73
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
80
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
74
81
  else
75
82
  end
76
83
  else
77
84
  end
78
85
  end
86
+
data/lib/helpers/merb.rb CHANGED
@@ -45,7 +45,7 @@ module Paginate
45
45
  if current == 1
46
46
  html << tag(:span, '&laquo;', :class => 'pageDisabled pagePrevious')
47
47
  else
48
- html << tag(:a, '&laquo;', :href => page_url(current - 1), :class => 'pagePrevious')
48
+ html << tag(:a, '&laquo;', :href => url_for_pagination(current - 1), :class => 'pagePrevious')
49
49
  end
50
50
 
51
51
  page_set(current, pages, padding).each do |page|
@@ -55,32 +55,18 @@ module Paginate
55
55
  when current
56
56
  html << tag(:span, page, :class => 'pageCurrent')
57
57
  else
58
- html << tag(:a, page, :href => page_url(page), :class => 'pageNumber')
58
+ html << tag(:a, page, :href => url_for_pagination(page), :class => 'pageNumber')
59
59
  end
60
60
  end
61
61
 
62
62
  if current == pages
63
63
  html << tag(:span, '&raquo;', :class => 'pageDisabled pageNext')
64
64
  else
65
- html << tag(:a, '&raquo;', :href => page_url(current + 1), :class => 'pageNext')
65
+ html << tag(:a, '&raquo;', :href => url_for_pagination(current + 1), :class => 'pageNext')
66
66
  end
67
67
  html
68
68
  end
69
69
  end
70
-
71
- # +page_url+ generates a URL (for page links), given a page number and
72
- # optionally a path and query string. By default, the path is the path
73
- # of the current request, and the query_string is also that of the
74
- # current request. This allows for order and condition related fields
75
- # in the query string to be used in the page link.
76
- def page_url(page, path = request.path, q = request.query_string)
77
- # Remove any current reference to page in the query string
78
- q.to_s.gsub!(/page=(-?[\d]+)(&?)/, '')
79
- # Assemble new link
80
- link = "#{path}?page=#{page}&#{q}"
81
- link = link[0..-2] if link[-1..-1] == '&' # Strip trailing ampersand
82
- link
83
- end
84
70
  end
85
71
  end
86
72
  end
@@ -0,0 +1,72 @@
1
+ module Paginate
2
+ module Helpers
3
+ # Pagination helpers for Rails applications. See Paginate::Helpers::Shared
4
+ # for additional methods
5
+ module Rails
6
+ include Shared
7
+
8
+ # A quick method for creating pagination links, using a view partial,
9
+ # (layouts/_page_links, by default).
10
+ # Arguments:
11
+ #
12
+ # - +collection+: an enumerable collection with #current_page and
13
+ # #pages methods.
14
+ # - +partial_name+: location of the partial to use
15
+ # - +padding+: Maximum number of page links before and after current_page.
16
+ def pagination_partial(collection, partial_name = "layout/page_links", padding = 3)
17
+ padding ||= 3
18
+ render(:partial => partial_name, :locals => {:current_page => collection.current_page, :pages => collection.pages, :padding => padding})
19
+ end
20
+
21
+ # Returns links for pages, given a +collection+ and optional
22
+ # +padding+ (see Shared#page_set). Returned html will be along the lines
23
+ # of:
24
+ #
25
+ # <div class="pageLinks">' +
26
+ # <span class="pagePrevious"><a href="/list?page=4">&laquo;</a></span>
27
+ # <span class="pageSpacer">...</span>
28
+ # <span class="pageNumber"><a href="/list?page=3">3</a></span>
29
+ # <span class="pageNumber"><a href="/list?page=4">4</a></span>
30
+ # <span class="pageCurrent">5</span>
31
+ # <span class="pageNumber"><a href="/list?page=6">6</a></span>
32
+ # <span class="pageNumber"><a href="/list?page=7">7</a></span>
33
+ # <span class="pageSpacer">...</span>
34
+ # <span class="pageNext"><a href="/list?page=6">&raquo;</a></span>
35
+ # </div>
36
+ #
37
+ # CSS classes are pageSpacer, pageNumber, pageDisabled, pageCurrent,
38
+ # pagePrevious, and pageNext. pageLinks is the class of the enclosing div.
39
+ def page_links(collection, padding = 3)
40
+ current = collection.current_page
41
+ pages = collection.pages
42
+
43
+ content_tag(:div, {:class => 'pageLinks'}, false) do
44
+ html = ''.html_safe
45
+ if current == 1
46
+ html << content_tag(:span, :class => 'pageDisabled pagePrevious') { '&laquo;' }
47
+ else
48
+ html << content_tag(:a, :href => url_for_pagination(current - 1), :class => 'pagePrevious') { '&laquo;' }
49
+ end
50
+
51
+ page_set(current, pages, padding).each do |page|
52
+ case page
53
+ when 0
54
+ html << content_tag(:span, :class => 'pageSpacer') { '...' }
55
+ when current
56
+ html << content_tag(:span, :class => 'pageCurrent') { page.to_s }
57
+ else
58
+ html << content_tag(:a, :href => url_for_pagination(page), :class => 'pageNumber') { page.to_s }
59
+ end
60
+ end
61
+
62
+ if current == pages
63
+ html << content_tag(:span, :class => 'pageDisabled pageNext') { '&raquo;' }
64
+ else
65
+ html << content_tag(:a, :href => url_for_pagination(current + 1), :class => 'pageNext') { '&raquo;' }
66
+ end
67
+ html
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -38,6 +38,20 @@ module Paginate
38
38
  # Join Arrays together
39
39
  leader + (first..last).to_a + footer
40
40
  end
41
+
42
+ # Generate a URL (for page links), given a page number and
43
+ # optionally a path and query string. By default, the path is the path
44
+ # of the current request, and the query_string is also that of the
45
+ # current request. This allows for order and condition related fields
46
+ # in the query string to be used in the page link.
47
+ def url_for_pagination(page, path = request.path, q = request.query_string)
48
+ # Remove any current reference to page in the query string
49
+ q.to_s.gsub!(/page=(-?[\d]+)(&?)/, '')
50
+ # Assemble new link
51
+ link = "#{path}?page=#{page}&#{q}"
52
+ link = link[0..-2] if link[-1..-1] == '&' # Strip trailing ampersand
53
+ link
54
+ end
41
55
  end
42
56
  end
43
57
  end
@@ -0,0 +1,3 @@
1
+ module Paginate
2
+ VERSION = '0.2.0'.freeze
3
+ end
@@ -1,6 +1,4 @@
1
1
  module Paginate
2
- VERSION = '0.1.6'
3
-
4
2
  DEFAULTS = {
5
3
  :default_limit => 10
6
4
  }
@@ -29,6 +27,6 @@ end
29
27
  end
30
28
 
31
29
  # Require Helper Modules
32
- %w{ shared merb }.each do |file|
30
+ %w{ shared merb rails }.each do |file|
33
31
  require 'helpers/' + file
34
32
  end
data/lib/paginate/ar.rb CHANGED
File without changes
data/lib/paginate/dm.rb CHANGED
File without changes
File without changes
File without changes
File without changes
data/spec/fixtures/ar.rb CHANGED
File without changes
data/spec/fixtures/dm.rb CHANGED
File without changes
@@ -28,38 +28,4 @@ describe Paginate::Helpers::Merb do
28
28
  @object.pagination_partial(collection, 'partial_name', 4)
29
29
  end
30
30
  end
31
-
32
- describe '#page_url' do
33
- it 'should add page query option' do
34
- @object.page_url(5, 'path', '').should ==
35
- 'path?page=5'
36
- end
37
-
38
- it 'should leave other query options' do
39
- @object.page_url(5, 'path', 'limit=10&something=text').should ==
40
- 'path?page=5&limit=10&something=text'
41
- end
42
-
43
- it 'should remove existing page option' do
44
- # middle
45
- @object.page_url(5, 'path', 'limit=10&page=10&something=text').should ==
46
- 'path?page=5&limit=10&something=text'
47
-
48
- # start
49
- @object.page_url(5, 'path', 'page=10&limit=10&something=text').should ==
50
- 'path?page=5&limit=10&something=text'
51
-
52
- # end
53
- @object.page_url(5, 'path', 'limit=10&something=text&page=10').should ==
54
- 'path?page=5&limit=10&something=text'
55
- end
56
-
57
- it 'should remove existing negative page option' do
58
- @object.page_url(5, 'path', 'limit=10&page=-10&something=text').should ==
59
- 'path?page=5&limit=10&something=text'
60
-
61
- @object.page_url(5, 'path', 'page=-5&limit=10&something=text').should ==
62
- 'path?page=5&limit=10&something=text'
63
- end
64
- end
65
31
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Paginate::Helpers::Rails do
4
+ before(:all) do
5
+ @klass = Class.new
6
+ @klass.__send__(:include, Paginate::Helpers::Rails)
7
+ @object = @klass.new
8
+ end
9
+
10
+ it 'should include #page_set method from Shared' do
11
+ @object.page_set(5, 10, 2).should ==
12
+ [1,0,3,4,5,6,7,0,10]
13
+ end
14
+
15
+ # Being lazy and just using a mock here.
16
+ describe '#pagination_partial' do
17
+ it 'should call render(:partial)' do
18
+ collection = (1..50).to_a
19
+ collection.extend(Paginate::Simple)
20
+ collection = collection.paginate(:page => 5, :limit => 5)
21
+ vars = {
22
+ :current_page => 5,
23
+ :pages => 10,
24
+ :padding => 4
25
+ }
26
+
27
+ @object.should_receive(:render).with(:partial => 'partial_name', :locals => vars)
28
+ @object.pagination_partial(collection, 'partial_name', 4)
29
+ end
30
+ end
31
+ end
@@ -58,4 +58,38 @@ describe Paginate::Helpers::Shared do
58
58
  [1]
59
59
  end
60
60
  end
61
+
62
+ describe '#url_for_pagination' do
63
+ it 'should add page query option' do
64
+ @object.url_for_pagination(5, 'path', '').should ==
65
+ 'path?page=5'
66
+ end
67
+
68
+ it 'should leave other query options' do
69
+ @object.url_for_pagination(5, 'path', 'limit=10&something=text').should ==
70
+ 'path?page=5&limit=10&something=text'
71
+ end
72
+
73
+ it 'should remove existing page option' do
74
+ # middle
75
+ @object.url_for_pagination(5, 'path', 'limit=10&page=10&something=text').should ==
76
+ 'path?page=5&limit=10&something=text'
77
+
78
+ # start
79
+ @object.url_for_pagination(5, 'path', 'page=10&limit=10&something=text').should ==
80
+ 'path?page=5&limit=10&something=text'
81
+
82
+ # end
83
+ @object.url_for_pagination(5, 'path', 'limit=10&something=text&page=10').should ==
84
+ 'path?page=5&limit=10&something=text'
85
+ end
86
+
87
+ it 'should remove existing negative page option' do
88
+ @object.url_for_pagination(5, 'path', 'limit=10&page=-10&something=text').should ==
89
+ 'path?page=5&limit=10&something=text'
90
+
91
+ @object.url_for_pagination(5, 'path', 'page=-5&limit=10&something=text').should ==
92
+ 'path?page=5&limit=10&something=text'
93
+ end
94
+ end
61
95
  end
@@ -1,3 +1,4 @@
1
+ require 'spec_helper'
1
2
  require 'active_record'
2
3
 
3
4
  # Setup AR connection, schema
@@ -12,7 +13,6 @@ ActiveRecord::Schema.define do
12
13
  end
13
14
  end
14
15
 
15
- require 'spec_helper'
16
16
  require 'fixtures/ar'
17
17
 
18
18
  describe 'Paginate::AR' do
File without changes
@@ -1,6 +1,7 @@
1
+ require 'spec_helper'
1
2
  require 'dm-core'
2
3
  require 'dm-aggregates'
3
- require 'spec_helper'
4
+ require 'dm-migrations'
4
5
  require 'fixtures/dm'
5
6
 
6
7
  describe Paginate::DM do
File without changes
File without changes
File without changes
data/spec/shared.rb CHANGED
File without changes
data/spec/spec.opts CHANGED
File without changes
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "rubygems"
2
- require "spec"
1
+ require 'rubygems'
2
+ require 'spec'
3
3
 
4
- require 'paginate'
4
+ require 'jm81-paginate'
5
5
  require 'shared'
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jm81-paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Jared Morgan
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-10-11 00:00:00 -05:00
18
+ date: 2010-08-11 00:00:00 -05:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -26,25 +32,28 @@ extensions: []
26
32
  extra_rdoc_files:
27
33
  - LICENSE
28
34
  - README.md
35
+ - TODO
29
36
  files:
30
37
  - .gitignore
31
38
  - LICENSE
32
39
  - README.md
33
40
  - Rakefile
34
41
  - TODO
35
- - VERSION
42
+ - jm81-paginate.gemspec
36
43
  - lib/helpers/merb.rb
44
+ - lib/helpers/rails.rb
37
45
  - lib/helpers/shared.rb
38
- - lib/paginate.rb
46
+ - lib/jm81-paginate.rb
47
+ - lib/jm81-paginate/version.rb
39
48
  - lib/paginate/ar.rb
40
49
  - lib/paginate/dm.rb
41
50
  - lib/paginate/simple.rb
42
51
  - lib/paginators/orm.rb
43
52
  - lib/paginators/simple.rb
44
- - paginate.gemspec
45
53
  - spec/fixtures/ar.rb
46
54
  - spec/fixtures/dm.rb
47
55
  - spec/helpers/merb_spec.rb
56
+ - spec/helpers/rails_spec.rb
48
57
  - spec/helpers/shared_spec.rb
49
58
  - spec/paginate/ar_spec.rb
50
59
  - spec/paginate/config_spec.rb
@@ -65,34 +74,41 @@ rdoc_options:
65
74
  require_paths:
66
75
  - lib
67
76
  required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
68
78
  requirements:
69
79
  - - ">="
70
80
  - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
71
84
  version: "0"
72
- version:
73
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
74
87
  requirements:
75
88
  - - ">="
76
89
  - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
77
93
  version: "0"
78
- version:
79
94
  requirements: []
80
95
 
81
96
  rubyforge_project:
82
- rubygems_version: 1.3.5
97
+ rubygems_version: 1.3.7
83
98
  signing_key:
84
99
  specification_version: 3
85
100
  summary: Pagination for DataMapper, ActiveRecord, and Array
86
101
  test_files:
87
- - spec/fixtures/ar.rb
88
- - spec/fixtures/dm.rb
89
- - spec/helpers/merb_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/shared.rb
104
+ - spec/paginators/orm_spec.rb
105
+ - spec/paginators/simple_spec.rb
90
106
  - spec/helpers/shared_spec.rb
91
- - spec/paginate/ar_spec.rb
92
- - spec/paginate/config_spec.rb
107
+ - spec/helpers/merb_spec.rb
108
+ - spec/helpers/rails_spec.rb
93
109
  - spec/paginate/dm_spec.rb
110
+ - spec/paginate/config_spec.rb
94
111
  - spec/paginate/simple_spec.rb
95
- - spec/paginators/orm_spec.rb
96
- - spec/paginators/simple_spec.rb
97
- - spec/shared.rb
98
- - spec/spec_helper.rb
112
+ - spec/paginate/ar_spec.rb
113
+ - spec/fixtures/dm.rb
114
+ - spec/fixtures/ar.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.6