will_paginate-bootstrap 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +9 -4
- data/Rakefile +7 -0
- data/lib/bootstrap_pagination/action_view.rb +2 -2
- data/lib/bootstrap_pagination/bootstrap_renderer.rb +55 -0
- data/lib/bootstrap_pagination/sinatra.rb +3 -3
- data/lib/bootstrap_pagination/version.rb +1 -1
- data/spec/pagination_spec.rb +72 -0
- metadata +15 -5
data/Gemfile
CHANGED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Nicholas Dainty
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
CHANGED
@@ -11,13 +11,18 @@ As with will_paginate itself, Rails and Sinatra are supported.
|
|
11
11
|
### Rails
|
12
12
|
|
13
13
|
1. Load the Bootstrap CSS in your template.
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
2. `require "will_paginate/bootstrap"` (`config/initializers/will_paginate.rb` would be a good place to put this).
|
15
|
+
3. In your view, use the `:renderer => BootstrapPagination::Rails` option with the `will_paginate` helper, for example:
|
16
|
+
|
17
|
+
`<%= will_paginate @collection, :renderer => BootstrapPagination::Rails %>`
|
17
18
|
|
18
19
|
### Sinatra
|
19
20
|
|
20
|
-
|
21
|
+
1. Load the Bootstrap CSS in your template.
|
22
|
+
2. `require "will_paginate/bootstrap"` in your Sinatra app.
|
23
|
+
3. In your view, use the `:renderer => BootstrapPagination::Sinatra` option with the `will_paginate` helper, for example:
|
24
|
+
|
25
|
+
`<%= will_paginate @collection, :renderer => BootstrapPagination::Sinatra %>`
|
21
26
|
|
22
27
|
## Compatibility
|
23
28
|
|
data/Rakefile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require "will_paginate/view_helpers/action_view"
|
2
|
-
require "bootstrap_pagination/
|
2
|
+
require "bootstrap_pagination/bootstrap_renderer"
|
3
3
|
|
4
4
|
module BootstrapPagination
|
5
5
|
# A custom renderer class for WillPaginate that produces markup suitable for use with Twitter Bootstrap.
|
6
6
|
class Rails < WillPaginate::ActionView::LinkRenderer
|
7
|
-
include
|
7
|
+
include BootstrapRenderer
|
8
8
|
end
|
9
9
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "bootstrap_pagination/version"
|
4
|
+
|
5
|
+
module BootstrapPagination
|
6
|
+
# Contains functionality shared by all renderer classes.
|
7
|
+
module BootstrapRenderer
|
8
|
+
ELLIPSIS = '…'
|
9
|
+
|
10
|
+
def to_html
|
11
|
+
list_items = pagination.map do |item|
|
12
|
+
case item
|
13
|
+
when Fixnum
|
14
|
+
page_number(item)
|
15
|
+
else
|
16
|
+
send(item)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
html_container(tag('ul', list_items.join(@options[:link_separator])))
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def page_number(page)
|
26
|
+
if page == current_page
|
27
|
+
tag('li', link(page, page), :class => 'active')
|
28
|
+
else
|
29
|
+
tag('li', link(page, page, :rel => rel_value(page)))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def gap
|
34
|
+
tag('li', link(ELLIPSIS, '#'), :class => 'disabled')
|
35
|
+
end
|
36
|
+
|
37
|
+
def previous_page
|
38
|
+
num = @collection.current_page > 1 && @collection.current_page - 1
|
39
|
+
previous_or_next_page(num, @options[:previous_label], 'prev')
|
40
|
+
end
|
41
|
+
|
42
|
+
def next_page
|
43
|
+
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
|
44
|
+
previous_or_next_page(num, @options[:next_label], 'next')
|
45
|
+
end
|
46
|
+
|
47
|
+
def previous_or_next_page(page, text, classname)
|
48
|
+
if page
|
49
|
+
tag('li', link(text, page), :class => classname)
|
50
|
+
else
|
51
|
+
tag('li', link(text, '#'), :class => "%s disabled" % classname)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require "will_paginate/view_helpers/
|
2
|
-
require "bootstrap_pagination/
|
1
|
+
require "will_paginate/view_helpers/sinatra"
|
2
|
+
require "bootstrap_pagination/bootstrap_renderer"
|
3
3
|
|
4
4
|
module BootstrapPagination
|
5
5
|
# A custom renderer class for WillPaginate that produces markup suitable for use with Twitter Bootstrap.
|
6
6
|
class Sinatra < WillPaginate::Sinatra::LinkRenderer
|
7
|
-
include
|
7
|
+
include BootstrapRenderer
|
8
8
|
end
|
9
9
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'will_paginate/array'
|
4
|
+
require 'will_paginate/view_helpers/link_renderer'
|
5
|
+
require 'bootstrap_pagination/bootstrap_renderer'
|
6
|
+
|
7
|
+
include WillPaginate::ViewHelpers
|
8
|
+
|
9
|
+
# Renderer class that's not tied to any web framework.
|
10
|
+
class MockRenderer < WillPaginate::ViewHelpers::LinkRenderer
|
11
|
+
include BootstrapPagination::BootstrapRenderer
|
12
|
+
|
13
|
+
HASH = '#'
|
14
|
+
|
15
|
+
def url(args)
|
16
|
+
HASH
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Bootstrap Renderer" do
|
21
|
+
before do
|
22
|
+
# Render pagination for the middle page so that we can test for the presence of
|
23
|
+
# start, prev and next links. We should also be able to test for test for the
|
24
|
+
# presence of a "gap" item if the collection size is large enough.
|
25
|
+
collection_size = 15
|
26
|
+
page = (collection_size / 2.0).to_i
|
27
|
+
|
28
|
+
@collection = 1.upto(collection_size).to_a
|
29
|
+
@output = will_paginate(@collection.paginate(:page => page, :per_page => 1), :renderer => MockRenderer)
|
30
|
+
@html = Nokogiri::HTML.fragment(@output)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns a string" do
|
34
|
+
@output.must_be_kind_of String
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns a string containing HTML" do
|
38
|
+
@html.must_be_kind_of Nokogiri::HTML::DocumentFragment
|
39
|
+
end
|
40
|
+
|
41
|
+
it "has an outer pagination div" do
|
42
|
+
@html.at_css('div.pagination').wont_be_nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has an unordered list within the pagination div" do
|
46
|
+
@html.at_css('div.pagination ul').wont_be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "has an active list item" do
|
50
|
+
@html.at_css('ul li.active').wont_be_nil
|
51
|
+
end
|
52
|
+
|
53
|
+
it "has a gap item with class disabled" do
|
54
|
+
@html.at_css('ul li.disabled').wont_be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it "has one item with rel start value" do
|
58
|
+
@html.css('[rel~=start]').size.must_equal 1
|
59
|
+
end
|
60
|
+
|
61
|
+
it "has two items with rel prev value" do
|
62
|
+
@html.css('[rel~=prev]').size.must_equal 2
|
63
|
+
end
|
64
|
+
|
65
|
+
it "has two items with rel next value" do
|
66
|
+
@html.css('[rel~=next]').size.must_equal 2
|
67
|
+
end
|
68
|
+
|
69
|
+
it "has anchors within each list item" do
|
70
|
+
@html.css('ul li').each { |li| li.at_css('a').wont_be_nil }
|
71
|
+
end
|
72
|
+
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: will_paginate
|
16
|
-
requirement: &
|
16
|
+
requirement: &70312336639340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 3.0.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70312336639340
|
25
25
|
description: This gem integrates the Twitter Bootstrap pagination component with the
|
26
26
|
will_paginate pagination gem. Supports Rails and Sinatra.
|
27
27
|
email:
|
@@ -32,14 +32,17 @@ extra_rdoc_files: []
|
|
32
32
|
files:
|
33
33
|
- .gitignore
|
34
34
|
- Gemfile
|
35
|
+
- MIT-LICENSE
|
35
36
|
- README.markdown
|
36
37
|
- Rakefile
|
37
38
|
- lib/bootstrap_pagination/action_view.rb
|
39
|
+
- lib/bootstrap_pagination/bootstrap_renderer.rb
|
38
40
|
- lib/bootstrap_pagination/link_renderer.rb
|
39
41
|
- lib/bootstrap_pagination/sinatra.rb
|
40
42
|
- lib/bootstrap_pagination/version.rb
|
41
43
|
- lib/will_paginate/bootstrap.rb
|
42
44
|
- pagination.png
|
45
|
+
- spec/pagination_spec.rb
|
43
46
|
- will_paginate-bootstrap.gemspec
|
44
47
|
homepage: https://github.com/nickpad/will_paginate-bootstrap
|
45
48
|
licenses: []
|
@@ -53,16 +56,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
56
|
- - ! '>='
|
54
57
|
- !ruby/object:Gem::Version
|
55
58
|
version: '0'
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
hash: 4530517534669726234
|
56
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
63
|
none: false
|
58
64
|
requirements:
|
59
65
|
- - ! '>='
|
60
66
|
- !ruby/object:Gem::Version
|
61
67
|
version: '0'
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
hash: 4530517534669726234
|
62
71
|
requirements: []
|
63
72
|
rubyforge_project: will_paginate-bootstrap
|
64
73
|
rubygems_version: 1.8.11
|
65
74
|
signing_key:
|
66
75
|
specification_version: 3
|
67
76
|
summary: Integrates the Twitter Bootstrap pagination component with will_paginate
|
68
|
-
test_files:
|
77
|
+
test_files:
|
78
|
+
- spec/pagination_spec.rb
|