ruby_pagination_logic 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +3 -0
- data/README.md +52 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/ruby_pagination_logic.rb +33 -0
- data/test/helper.rb +18 -0
- data/test/test_ruby_pagination_logic.rb +7 -0
- metadata +136 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.1"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
Based on [CC-BY-SA 3.0](http://creativecommons.org/licenses/by-sa/3.0/).
|
2
|
+
|
3
|
+
You must give attribution in source code, although not on website (if you're using it for your website). If you make any modifications, please publish it under the this license, CC-BY-SA 3.0, and give attribution.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# ruby_pagination_logic
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
$ sudo gem install ruby_pagination_logic
|
6
|
+
|
7
|
+
## Example use
|
8
|
+
|
9
|
+
# With DataMapper and Sinatra
|
10
|
+
# @app.rb
|
11
|
+
[...]
|
12
|
+
require "pagination.rb"
|
13
|
+
get '/page/:page' do |page|
|
14
|
+
@page = page.to_i
|
15
|
+
limit = 5
|
16
|
+
offset = RPL::paginate @page, limit
|
17
|
+
|
18
|
+
@post = Post.all :limit => limit, :offset => offset, :order => 'date'
|
19
|
+
|
20
|
+
haml :posts
|
21
|
+
end
|
22
|
+
|
23
|
+
# @views/posts.haml
|
24
|
+
%section{:class => "articles"}
|
25
|
+
- @post.reverse.each do |post|
|
26
|
+
%article
|
27
|
+
%h2
|
28
|
+
=post.title
|
29
|
+
= post.date
|
30
|
+
%div
|
31
|
+
= post.text
|
32
|
+
%a{:href => "/page/#{RPL::next @page}"}
|
33
|
+
Next
|
34
|
+
|
35
|
+
**Author**: John Ankarström.
|
36
|
+
[Source.](http://github.com/jocap/jpl)
|
37
|
+
|
38
|
+
## Contributing to ruby_pagination_logic
|
39
|
+
|
40
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
41
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
42
|
+
* Fork the project
|
43
|
+
* Start a feature/bugfix branch
|
44
|
+
* Commit and push until you are happy with your contribution
|
45
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
46
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
Based on [CC-BY-SA 3.0](http://creativecommons.org/licenses/by-sa/3.0/).
|
51
|
+
|
52
|
+
You must give attribution in source code, although not on website (if you're using it for your website). If you make any modifications, please publish it under the this license, CC-BY-SA 3.0, and give attribution.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "ruby_pagination_logic"
|
16
|
+
gem.homepage = "http://github.com/jocap/ruby_pagination_logic"
|
17
|
+
gem.license = "CC-BY-SA"
|
18
|
+
gem.summary = %Q{Ruby Pagination Logic is a tiny library providing you the pagination logic for any Ruby application.}
|
19
|
+
gem.description = %Q{Ruby Pagination Logic provides you the pagination logic, while being lightweight and easy to use.}
|
20
|
+
gem.email = "jocapriconne@gmail.com"
|
21
|
+
gem.authors = ["John Ankarström"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "ruby_pagination_logic #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Pagination Logic for Ruby.
|
2
|
+
# === by John Ankarström ===
|
3
|
+
|
4
|
+
# http://jocap.github.com/Ruby-Pagination-Logic
|
5
|
+
# See LICENSE.txt.
|
6
|
+
|
7
|
+
class RPL
|
8
|
+
|
9
|
+
def self.paginate(page = 1, limit = 10)
|
10
|
+
if page > 1
|
11
|
+
offset = limit * (page - 1)
|
12
|
+
return offset
|
13
|
+
else
|
14
|
+
return 0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.next(page)
|
19
|
+
begin
|
20
|
+
return page + 1
|
21
|
+
rescue NoMethodError => e
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.prev(page)
|
27
|
+
begin
|
28
|
+
return page - 1
|
29
|
+
rescue NoMethodError => e
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'ruby_pagination_logic'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_pagination_logic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "John Ankarstr\xC3\xB6m"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-05 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
name: shoulda
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 23
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
version: 1.0.0
|
47
|
+
type: :development
|
48
|
+
name: bundler
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 1
|
58
|
+
segments:
|
59
|
+
- 1
|
60
|
+
- 5
|
61
|
+
- 1
|
62
|
+
version: 1.5.1
|
63
|
+
type: :development
|
64
|
+
name: jeweler
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
type: :development
|
78
|
+
name: rcov
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id004
|
81
|
+
description: Ruby Pagination Logic provides you the pagination logic, while being lightweight and easy to use.
|
82
|
+
email: jocapriconne@gmail.com
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
files:
|
91
|
+
- .document
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- Rakefile
|
95
|
+
- VERSION
|
96
|
+
- lib/ruby_pagination_logic.rb
|
97
|
+
- test/helper.rb
|
98
|
+
- test/test_ruby_pagination_logic.rb
|
99
|
+
- README.md
|
100
|
+
has_rdoc: true
|
101
|
+
homepage: http://github.com/jocap/ruby_pagination_logic
|
102
|
+
licenses:
|
103
|
+
- CC-BY-SA
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
version: "0"
|
127
|
+
requirements: []
|
128
|
+
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 1.3.7
|
131
|
+
signing_key:
|
132
|
+
specification_version: 3
|
133
|
+
summary: Ruby Pagination Logic is a tiny library providing you the pagination logic for any Ruby application.
|
134
|
+
test_files:
|
135
|
+
- test/helper.rb
|
136
|
+
- test/test_ruby_pagination_logic.rb
|