will_paginate-bootstrap 0.2.3 → 0.2.4
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/README.markdown +17 -3
- data/example/app.rb +39 -5
- data/lib/bootstrap_pagination/bootstrap_renderer.rb +14 -10
- data/lib/bootstrap_pagination/version.rb +1 -1
- data/spec/pagination_spec.rb +24 -9
- metadata +4 -4
data/README.markdown
CHANGED
@@ -20,15 +20,29 @@ As with will_paginate itself, Rails and Sinatra are supported.
|
|
20
20
|
1. Load the Bootstrap CSS in your template.
|
21
21
|
2. In your view, use the `renderer: BootstrapPagination::Rails` option with the `will_paginate` helper, for example:
|
22
22
|
|
23
|
-
|
23
|
+
```ruby
|
24
|
+
<%= will_paginate @collection, renderer: BootstrapPagination::Rails %>
|
25
|
+
```
|
24
26
|
|
25
27
|
### Sinatra
|
26
28
|
|
27
29
|
1. Load the Bootstrap CSS in your template.
|
28
30
|
2. `require "will_paginate-bootstrap"` in your Sinatra app.
|
29
|
-
3. In your view, use the
|
31
|
+
3. In your view, use the `renderer: BootstrapPagination::Sinatra` option with the `will_paginate` helper, for example:
|
30
32
|
|
31
|
-
|
33
|
+
```ruby
|
34
|
+
<%= will_paginate @collection, renderer: BootstrapPagination::Sinatra %>
|
35
|
+
```
|
36
|
+
|
37
|
+
## Bootstrap 3
|
38
|
+
|
39
|
+
For Bootstrap 3, the markup required has changed slightly from version 2. You can pass the `bootstrap` option with a value >= 3 when calling `will_paginate` to generate Bootstrap 3 compatible markup. For example:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
<%= will_paginate @collection, renderer: BootstrapPagination::Rails, bootstrap: 3 %>
|
43
|
+
```
|
44
|
+
|
45
|
+
By default version 2 compatible markup will be generated.
|
32
46
|
|
33
47
|
## Compatibility
|
34
48
|
|
data/example/app.rb
CHANGED
@@ -2,18 +2,39 @@ require "sinatra"
|
|
2
2
|
require "will_paginate-bootstrap"
|
3
3
|
require "will_paginate/collection"
|
4
4
|
|
5
|
+
CDN_PATHS = {
|
6
|
+
2 => "//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css",
|
7
|
+
3 => "//netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/css/bootstrap.min.css"
|
8
|
+
}
|
9
|
+
|
10
|
+
$menu = <<EOHTML
|
11
|
+
<html>
|
12
|
+
<head>
|
13
|
+
<title>will_paginate-boostrap Example App</title>
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
<ul>
|
17
|
+
<h1>Which Twitter Boostrap version?</h1>
|
18
|
+
<li><a href="/2">Bootstrap 2</a></li>
|
19
|
+
<li><a href="/3">Bootstrap 3</a></li>
|
20
|
+
</ul>
|
21
|
+
</body>
|
22
|
+
</html>
|
23
|
+
EOHTML
|
24
|
+
|
5
25
|
$template = <<EOHTML
|
6
26
|
<html>
|
7
27
|
<head>
|
8
|
-
<
|
28
|
+
<title>will_paginate-boostrap Example App</title>
|
29
|
+
<link href="<%= href %>" rel="stylesheet">
|
9
30
|
</head>
|
10
31
|
<body>
|
11
|
-
<%= will_paginate @collection, :
|
32
|
+
<%= will_paginate @collection, renderer: BootstrapPagination::Sinatra, bootstrap: version %>
|
12
33
|
</body>
|
13
34
|
</html>
|
14
35
|
EOHTML
|
15
36
|
|
16
|
-
|
37
|
+
def build_collection
|
17
38
|
page = if params[:page].to_i > 0
|
18
39
|
params[:page].to_i
|
19
40
|
else
|
@@ -21,5 +42,18 @@ get "/" do
|
|
21
42
|
end
|
22
43
|
|
23
44
|
@collection = WillPaginate::Collection.new page, 10, 100000
|
24
|
-
|
25
|
-
|
45
|
+
end
|
46
|
+
|
47
|
+
get "/" do
|
48
|
+
erb $menu
|
49
|
+
end
|
50
|
+
|
51
|
+
get "/2" do
|
52
|
+
build_collection
|
53
|
+
erb $template, locals: {href: CDN_PATHS[2], version: 2}
|
54
|
+
end
|
55
|
+
|
56
|
+
get "/3" do
|
57
|
+
build_collection
|
58
|
+
erb $template, locals: {href: CDN_PATHS[3], version: 3}
|
59
|
+
end
|
@@ -3,7 +3,7 @@ require "bootstrap_pagination/version"
|
|
3
3
|
module BootstrapPagination
|
4
4
|
# Contains functionality shared by all renderer classes.
|
5
5
|
module BootstrapRenderer
|
6
|
-
ELLIPSIS =
|
6
|
+
ELLIPSIS = "…"
|
7
7
|
|
8
8
|
def to_html
|
9
9
|
list_items = pagination.map do |item|
|
@@ -13,40 +13,44 @@ module BootstrapPagination
|
|
13
13
|
else
|
14
14
|
send(item)
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end.join(@options[:link_separator])
|
17
17
|
|
18
|
-
|
18
|
+
if @options[:bootstrap].to_i >= 3
|
19
|
+
tag("ul", list_items, class: "pagination")
|
20
|
+
else
|
21
|
+
html_container(tag("ul", list_items))
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
protected
|
22
26
|
|
23
27
|
def page_number(page)
|
24
28
|
if page == current_page
|
25
|
-
tag(
|
29
|
+
tag("li", tag("span", page), class: "active")
|
26
30
|
else
|
27
|
-
tag(
|
31
|
+
tag("li", link(page, page, :rel => rel_value(page)))
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def gap
|
32
|
-
tag(
|
36
|
+
tag("li", link(ELLIPSIS, "#"), class: "disabled")
|
33
37
|
end
|
34
38
|
|
35
39
|
def previous_page
|
36
40
|
num = @collection.current_page > 1 && @collection.current_page - 1
|
37
|
-
previous_or_next_page(num, @options[:previous_label],
|
41
|
+
previous_or_next_page(num, @options[:previous_label], "prev")
|
38
42
|
end
|
39
43
|
|
40
44
|
def next_page
|
41
45
|
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
|
42
|
-
previous_or_next_page(num, @options[:next_label],
|
46
|
+
previous_or_next_page(num, @options[:next_label], "next")
|
43
47
|
end
|
44
48
|
|
45
49
|
def previous_or_next_page(page, text, classname)
|
46
50
|
if page
|
47
|
-
tag(
|
51
|
+
tag("li", link(text, page), class: classname)
|
48
52
|
else
|
49
|
-
tag(
|
53
|
+
tag("li", tag("span", text), class: "%s disabled" % classname)
|
50
54
|
end
|
51
55
|
end
|
52
56
|
end
|
data/spec/pagination_spec.rb
CHANGED
@@ -24,11 +24,12 @@ describe "Bootstrap Renderer" do
|
|
24
24
|
let(:collection_size) { 15 }
|
25
25
|
let(:page) { (collection_size / 2.0).to_i }
|
26
26
|
let(:collection) { 1.upto(collection_size).to_a }
|
27
|
+
let(:version) { nil }
|
27
28
|
|
28
29
|
let(:output) do
|
29
30
|
will_paginate(
|
30
31
|
collection.paginate(:page => page, :per_page => 1),
|
31
|
-
:
|
32
|
+
renderer: MockRenderer, bootstrap: version
|
32
33
|
)
|
33
34
|
end
|
34
35
|
|
@@ -42,14 +43,6 @@ describe "Bootstrap Renderer" do
|
|
42
43
|
html.must_be_kind_of Nokogiri::HTML::DocumentFragment
|
43
44
|
end
|
44
45
|
|
45
|
-
it "has an outer pagination div" do
|
46
|
-
html.at_css('div.pagination').wont_be_nil
|
47
|
-
end
|
48
|
-
|
49
|
-
it "has an unordered list within the pagination div" do
|
50
|
-
html.at_css('div.pagination ul').wont_be_nil
|
51
|
-
end
|
52
|
-
|
53
46
|
it "has an active list item" do
|
54
47
|
html.at_css('ul li.active').wont_be_nil
|
55
48
|
end
|
@@ -77,4 +70,26 @@ describe "Bootstrap Renderer" do
|
|
77
70
|
it "uses a span element for the active page" do
|
78
71
|
html.at_css('ul li.active span').wont_be_nil
|
79
72
|
end
|
73
|
+
|
74
|
+
describe "with markup for v2" do
|
75
|
+
it "has an outer pagination div" do
|
76
|
+
html.at_css('div.pagination').wont_be_nil
|
77
|
+
end
|
78
|
+
|
79
|
+
it "has an unordered list within the pagination div" do
|
80
|
+
html.at_css('div.pagination ul').wont_be_nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "with markup for v3" do
|
85
|
+
let(:version) { 3 }
|
86
|
+
|
87
|
+
it "has no outer pagination div" do
|
88
|
+
html.at_css('div.pagination').must_be_nil
|
89
|
+
end
|
90
|
+
|
91
|
+
it "has an unordered list with the pagination class" do
|
92
|
+
html.at_css('ul.pagination').wont_be_nil
|
93
|
+
end
|
94
|
+
end
|
80
95
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: will_paginate-bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: will_paginate
|
@@ -64,7 +64,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
segments:
|
66
66
|
- 0
|
67
|
-
hash:
|
67
|
+
hash: 719611630819413183
|
68
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
69
|
none: false
|
70
70
|
requirements:
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
version: '0'
|
74
74
|
segments:
|
75
75
|
- 0
|
76
|
-
hash:
|
76
|
+
hash: 719611630819413183
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project: will_paginate-bootstrap
|
79
79
|
rubygems_version: 1.8.23
|