sinatra-pagin 0.0.2 → 0.0.3
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/Changelog.md +5 -0
- data/README.md +43 -18
- data/VERSION +1 -1
- data/lib/sinatra/pagin.rb +7 -5
- data/sinatra-pagin.gemspec +4 -4
- data/spec/pagin_spec.rb +6 -1
- metadata +57 -21
data/Changelog.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### sinatra-pagin - 0.0.3 / 2010-08-01
|
2
|
+
|
3
|
+
* #href_for_pagin now accepts overrides for the base uri to be used when attaching the page/#
|
4
|
+
* Helper registration is now manual, i've removed the registration call.
|
5
|
+
|
1
6
|
### sinatra-pagin - 0.0.2 / 2010-02-15
|
2
7
|
|
3
8
|
* Added a new helper method `href_for_pagin` to help facilitate creating pagination hrefs for use with pagin.
|
data/README.md
CHANGED
@@ -3,30 +3,29 @@ Sinatra::Pagin*
|
|
3
3
|
|
4
4
|
Small utility to process paginated urls without modifying the mapped paths in your Sinatra app
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
### FEATURES/PROBLEMS:
|
6
|
+
## Overview/Usage:
|
9
7
|
|
10
|
-
* Parses ../page/# off your urls to allow simple route mappings
|
11
|
-
* Saves page # for internal use
|
12
8
|
|
13
|
-
|
9
|
+
#### Basics:
|
14
10
|
|
15
11
|
Given you have mapped paths as such:
|
16
12
|
|
17
13
|
get "/" do
|
18
14
|
"hello world"
|
19
15
|
end
|
20
|
-
|
21
|
-
# => "http://example.org/"
|
16
|
+
#=> "http://example.org/"
|
22
17
|
|
23
18
|
get "/a/pathed/path" do
|
24
19
|
"foo bar"
|
25
20
|
end
|
26
|
-
|
27
|
-
|
21
|
+
#=> "http://example.org/a/pathed/path"
|
22
|
+
|
23
|
+
Without changing those paths, you can run a paginated url.
|
24
|
+
|
25
|
+
require 'sinatra/pagin
|
26
|
+
Sinatra::Application.register Sinatra::Pagin
|
28
27
|
|
29
|
-
|
28
|
+
###
|
30
29
|
|
31
30
|
http://example.org/page/2
|
32
31
|
# => get "/"
|
@@ -34,18 +33,39 @@ Without changing those paths, you can run a paginated url.
|
|
34
33
|
http://example.org/a/pathed/path/page/45
|
35
34
|
# => get "/a/pathed/path"
|
36
35
|
|
37
|
-
|
36
|
+
*This is based on "pretty" style urls, page parameters sent in via the query string (.../?page=2) will be processed by Sinatra's usual params.
|
37
|
+
|
38
|
+
#### Helpers:
|
39
|
+
|
40
|
+
`page` returns the parsed "page" number.
|
38
41
|
|
39
42
|
http://example.org/page/2
|
40
43
|
|
41
44
|
get "/" do
|
42
45
|
"hello world, you asked for page #{page}"
|
43
46
|
end
|
44
|
-
|
45
47
|
# => hello world, you asked for page 2
|
46
48
|
|
47
49
|
`page` returns 1 as a default.
|
48
50
|
|
51
|
+
##
|
52
|
+
|
53
|
+
`href_for_pagin(total_pages, direction => :next)` href builder to build pagin valid hrefs for next & previous links based on the currently requested uri.
|
54
|
+
|
55
|
+
- total_pages => Integer (Required)
|
56
|
+
- direction => Symbol [:next | :prev] \(Defaults to => :next)
|
57
|
+
|
58
|
+
---
|
59
|
+
http://example.org/2009/10/page/2
|
60
|
+
|
61
|
+
href_for_pagin 4, :next
|
62
|
+
#=> /2009/10/page/3
|
63
|
+
|
64
|
+
href_for_pagin 4, :prev
|
65
|
+
#=> /2009/10/page/1
|
66
|
+
|
67
|
+
## Additional notes:
|
68
|
+
|
49
69
|
It also supports `.:format` in your path.
|
50
70
|
|
51
71
|
get "/a/pathed/path.:format" do
|
@@ -56,22 +76,27 @@ It also supports `.:format` in your path.
|
|
56
76
|
# => path_info == /a/pathed/path.js
|
57
77
|
# => page == 45
|
58
78
|
|
59
|
-
|
79
|
+
## Requirements:
|
60
80
|
|
61
81
|
* [Sinatra](http://www.sinatrarb.com/)
|
62
82
|
|
63
|
-
|
83
|
+
## Install:
|
64
84
|
|
65
85
|
Install the gem:
|
66
86
|
|
67
87
|
sudo gem install sinatra-pagin
|
68
88
|
|
69
|
-
Require in your app:
|
89
|
+
Require & Register in your app:
|
70
90
|
|
71
91
|
require 'sinatra/pagin'
|
72
92
|
|
73
|
-
|
74
|
-
|
93
|
+
Sinatra::Application.register Sinatra::Pagin
|
94
|
+
|
95
|
+
## Integrity
|
96
|
+
|
97
|
+
[Checked by Integrity](http://ci.damncarousel.com)
|
98
|
+
|
99
|
+
## License:
|
75
100
|
|
76
101
|
(The MIT License)
|
77
102
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/sinatra/pagin.rb
CHANGED
@@ -26,8 +26,12 @@ module Sinatra
|
|
26
26
|
@page || 1
|
27
27
|
end
|
28
28
|
|
29
|
-
def href_for_pagin(total_pages, direction = :next)
|
30
|
-
|
29
|
+
def href_for_pagin(total_pages, direction = :next, override = nil)
|
30
|
+
if override.nil?
|
31
|
+
path_info = request.path_info.gsub(/\/$/, '') # clear off the last slash just in case
|
32
|
+
else
|
33
|
+
path_info = override
|
34
|
+
end
|
31
35
|
page_num = 1
|
32
36
|
|
33
37
|
case
|
@@ -41,6 +45,4 @@ module Sinatra
|
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
44
|
-
|
45
|
-
Sinatra::Application.register Pagin
|
46
|
-
end
|
48
|
+
end
|
data/sinatra-pagin.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra-pagin}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Yung Hwa Kwon"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-01}
|
13
13
|
s.description = %q{Small utility to process paginated urls without modifying the mapped paths in your Sinatra app}
|
14
14
|
s.email = %q{yung.kwon@nowk.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.homepage = %q{http://github.com/nowk/sinatra-pagin}
|
32
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
33
33
|
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.
|
34
|
+
s.rubygems_version = %q{1.3.7}
|
35
35
|
s.summary = %q{Small utility to process paginated urls without modifying the mapped paths in your Sinatra app}
|
36
36
|
s.test_files = [
|
37
37
|
"spec/pagin_spec.rb",
|
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
43
|
s.specification_version = 3
|
44
44
|
|
45
|
-
if Gem::Version.new(Gem::
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
46
|
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.4"])
|
47
47
|
s.add_development_dependency(%q<rspec>, [">= 1.2.8"])
|
48
48
|
s.add_development_dependency(%q<webrat>, [">= 0.7.0"])
|
data/spec/pagin_spec.rb
CHANGED
@@ -194,6 +194,11 @@ describe 'Sinatra' do
|
|
194
194
|
page 3
|
195
195
|
href_for_pagin(3, :next).should == "/2009/10/page/3"
|
196
196
|
end
|
197
|
+
|
198
|
+
it "allows for the base path to be overridden" do
|
199
|
+
page 2
|
200
|
+
href_for_pagin(3, :next, '/base/path').should == '/base/path/page/3'
|
201
|
+
end
|
197
202
|
end
|
198
203
|
|
199
204
|
context "within an actual app" do
|
@@ -244,4 +249,4 @@ describe 'Sinatra' do
|
|
244
249
|
end
|
245
250
|
end
|
246
251
|
end
|
247
|
-
end
|
252
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-pagin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Yung Hwa Kwon
|
@@ -9,49 +15,73 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-08-01 00:00:00 -04:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: sinatra
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 51
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
33
|
+
- 4
|
23
34
|
version: 0.9.4
|
24
|
-
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: rspec
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 2
|
49
|
+
- 8
|
33
50
|
version: 1.2.8
|
34
|
-
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
35
53
|
- !ruby/object:Gem::Dependency
|
36
54
|
name: webrat
|
37
|
-
|
38
|
-
|
39
|
-
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
40
58
|
requirements:
|
41
59
|
- - ">="
|
42
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
- 7
|
65
|
+
- 0
|
43
66
|
version: 0.7.0
|
44
|
-
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
45
69
|
- !ruby/object:Gem::Dependency
|
46
70
|
name: rack-test
|
47
|
-
|
48
|
-
|
49
|
-
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
50
74
|
requirements:
|
51
75
|
- - ">="
|
52
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 15
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
- 5
|
81
|
+
- 2
|
53
82
|
version: 0.5.2
|
54
|
-
|
83
|
+
type: :development
|
84
|
+
version_requirements: *id004
|
55
85
|
description: Small utility to process paginated urls without modifying the mapped paths in your Sinatra app
|
56
86
|
email: yung.kwon@nowk.net
|
57
87
|
executables: []
|
@@ -82,21 +112,27 @@ rdoc_options:
|
|
82
112
|
require_paths:
|
83
113
|
- lib
|
84
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
85
116
|
requirements:
|
86
117
|
- - ">="
|
87
118
|
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
120
|
+
segments:
|
121
|
+
- 0
|
88
122
|
version: "0"
|
89
|
-
version:
|
90
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
91
125
|
requirements:
|
92
126
|
- - ">="
|
93
127
|
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
129
|
+
segments:
|
130
|
+
- 0
|
94
131
|
version: "0"
|
95
|
-
version:
|
96
132
|
requirements: []
|
97
133
|
|
98
134
|
rubyforge_project:
|
99
|
-
rubygems_version: 1.3.
|
135
|
+
rubygems_version: 1.3.7
|
100
136
|
signing_key:
|
101
137
|
specification_version: 3
|
102
138
|
summary: Small utility to process paginated urls without modifying the mapped paths in your Sinatra app
|