paginate-simple 0.1.1 → 0.1.2

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.
@@ -25,53 +25,58 @@ and its usage.
25
25
  Usage:
26
26
  In order to create a singleton pagination object we need to create a class Paginator that
27
27
  will extend this module and change some of its built in logic like this:
28
- class Paginator
29
- extend PaginateSimple
28
+
29
+
30
+ class Paginator
31
+ extend PaginateSimple
30
32
 
31
- def self.current_page(page)
32
- super page.to_i # allow strings to be passed like "1" as well
33
+ def self.current_page=(page)
34
+ super page.to_i # allow strings to be passed like "1" as well
35
+ end
33
36
  end
34
- end
35
37
 
36
38
  If we need to have more than one Paginator we will include the module instead and
37
39
  then instantiate the object as needed.
38
- class Paginator
39
- include PaginateSimple
40
+
41
+
42
+ class Paginator
43
+ include PaginateSimple
40
44
 
41
- def current_page(page)
42
- super page.to_i # allow strings to be passed like "1" as well
45
+ def current_page=(page)
46
+ super page.to_i # allow strings to be passed like "1" as well
47
+ end
43
48
  end
44
- end
45
49
 
46
- @paginator = Paginator.new
47
- @paginator.config :total => 100 , :page => 1, :per_page => 10
50
+ @paginator = Paginator.new
51
+ @paginator.config :total => 100 , :page => 1, :per_page => 10
48
52
 
49
- @another_paginator = Paginator.new
50
- @another_paginator.config :total => 100 , :page => 1, :per_page => 3
53
+ @another_paginator = Paginator.new
54
+ @another_paginator.config :total => 100 , :page => 1, :per_page => 3
51
55
 
52
56
  By default no helper for the paginator exists. But to write one is quite simple.
53
57
  Here is the example of a paginator helper that i use in my blog.
54
58
 
55
- require 'sinatra/base'
56
-
57
- module Sinatra
58
- module PaginationHelper
59
- def paginate(resource)
60
- data = []
61
- data << '<div class="pagination">'
62
- data << "<a href =\"/#{resource}/?page=#{Paginator.previous_page}\">Prev</a>" if Paginator.has_previous_page?
63
- data << ' | ' if Paginator.has_previous_page? and Paginator.has_next_page?
64
- data << "<a href =\"/#{resource}/?page=#{Paginator.next_page}\">Next</a>" if Paginator.has_next_page?
65
- data << '</div>'
66
- data.join(' ')
59
+ require 'sinatra/base'
60
+
61
+ module Sinatra
62
+ module PaginationHelper
63
+ def paginate(resource)
64
+ data = []
65
+ data << '<div class="pagination">'
66
+ data << "<a href =\"/#{resource}/?page=#{Paginator.previous_page}\">Prev</a>" if Paginator.has_previous_page?
67
+ data << ' | ' if Paginator.has_previous_page? and Paginator.has_next_page?
68
+ data << "<a href =\"/#{resource}/?page=#{Paginator.next_page}\">Next</a>" if Paginator.has_next_page?
69
+ data << '</div>'
70
+ data.join(' ')
71
+ end
67
72
  end
68
- end
69
73
 
70
- helpers PaginationHelper
71
- end
74
+ helpers PaginationHelper
75
+ end
72
76
 
73
77
  and i use it like this in my haml file
74
- = paginate 'posts'
78
+
79
+ = paginate 'posts'
75
80
 
76
81
  == Contributing to paginate-simple
77
82
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -45,7 +45,9 @@ module PaginateSimple
45
45
  end
46
46
 
47
47
  def current_page=(page)
48
- raise ArgumentError if page < 1
48
+ raise TypeError, "The page must be an 'Integer' like object" if not page.respond_to? :to_i
49
+ page = page.to_i
50
+ raise ArgumentError, "The page must be greater than 1, #{page} given" if page < 1
49
51
  @current_page = page
50
52
  end
51
53
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{paginate-simple}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["filip"]
12
- s.date = %q{2011-03-05}
12
+ s.date = %q{2011-03-08}
13
13
  s.description = %q{It is just a plain Pagination module that provides pagination logic.}
14
14
  s.email = %q{github.sirfilip@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.homepage = %q{http://github.com/sirfilip/paginate-simple}
33
33
  s.licenses = ["MIT"]
34
34
  s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.5.3}
35
+ s.rubygems_version = %q{1.6.1}
36
36
  s.summary = %q{Simple pagination solution independent from any ORM.}
37
37
  s.test_files = [
38
38
  "test/helper.rb"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: paginate-simple
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - filip
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-05 00:00:00 +01:00
13
+ date: 2011-03-08 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -103,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
- hash: -3688072682752233478
106
+ hash: 379335850999288304
107
107
  segments:
108
108
  - 0
109
109
  version: "0"
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  requirements: []
117
117
 
118
118
  rubyforge_project:
119
- rubygems_version: 1.5.3
119
+ rubygems_version: 1.6.1
120
120
  signing_key:
121
121
  specification_version: 3
122
122
  summary: Simple pagination solution independent from any ORM.