hobo_will_paginate-bootstrap 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +14 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +62 -0
- data/Rakefile +8 -0
- data/example/app.rb +32 -0
- data/lib/bootstrap_pagination/action_view.rb +9 -0
- data/lib/bootstrap_pagination/bootstrap_renderer.rb +65 -0
- data/lib/bootstrap_pagination/sinatra.rb +9 -0
- data/lib/bootstrap_pagination/version.rb +3 -0
- data/lib/will_paginate-bootstrap.rb +1 -0
- data/lib/will_paginate/bootstrap.rb +9 -0
- data/pagination.png +0 -0
- data/spec/pagination_spec.rb +99 -0
- data/will_paginate-bootstrap.gemspec +23 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 567638c2ae72697c3e96d4810f5f69b49b5151a6
|
4
|
+
data.tar.gz: ddbaf899549f83c1a623a0af4313be028507d1db
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d86c19a9830fdfa1cee53c88d70159be1d6a266eb0f15a3073ffe789666a80d336384e4cfb4266505c0af3e41b4541baa4432e6e3b1bc4da4220ffc0111cdff7
|
7
|
+
data.tar.gz: 9deb73f2b5264afc2d86b9eb54eeb8af48fce50b79941fc86165859ae7a99a7c91c2e0f9753d10c6a5c01584fb0493bc3341a43fb2b2ff1f65ce721e41528e30
|
data/Gemfile
ADDED
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
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# will_paginate-bootstrap
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/nickpad/will_paginate-bootstrap.png)](https://codeclimate.com/github/nickpad/will_paginate-bootstrap)
|
4
|
+
|
5
|
+
![Bootstrap Pagination Component](https://raw.github.com/nickpad/will_paginate-bootstrap/master/pagination.png)
|
6
|
+
|
7
|
+
This gem integrates the [Twitter Bootstrap](http://twitter.github.com/bootstrap/) [pagination component](http://twitter.github.com/bootstrap/components.html#pagination) with the [will_paginate](https://github.com/mislav/will_paginate) pagination gem.
|
8
|
+
|
9
|
+
Just like will_paginate, Rails and Sinatra are supported.
|
10
|
+
|
11
|
+
## Install
|
12
|
+
|
13
|
+
* `gem install will_paginate-bootstrap`, *or*
|
14
|
+
* For projects using Bundler, add `gem 'will_paginate-bootstrap'` to your `Gemfile` (and then run `bundle install`).
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
### Rails
|
19
|
+
|
20
|
+
1. Load the Bootstrap CSS in your template.
|
21
|
+
2. In your view, use the `renderer: BootstrapPagination::Rails` option with the `will_paginate` helper, for example:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
<%= will_paginate @collection, renderer: BootstrapPagination::Rails %>
|
25
|
+
```
|
26
|
+
|
27
|
+
### Sinatra
|
28
|
+
|
29
|
+
1. Load the Bootstrap CSS in your template.
|
30
|
+
2. `require "will_paginate-bootstrap"` in your Sinatra app.
|
31
|
+
3. In your view, use the `renderer: BootstrapPagination::Sinatra` option with the `will_paginate` helper, for example:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
<%= will_paginate @collection, renderer: BootstrapPagination::Sinatra %>
|
35
|
+
```
|
36
|
+
|
37
|
+
## Compatibility
|
38
|
+
|
39
|
+
Starting at version 1.0, this gem no longer supports Bootstrap 2.
|
40
|
+
|
41
|
+
<table>
|
42
|
+
<tr>
|
43
|
+
<th>Ruby</th>
|
44
|
+
<td>>= 1.9.2</td>
|
45
|
+
</tr>
|
46
|
+
<tr>
|
47
|
+
<th>will_paginate</th>
|
48
|
+
<td>>= 3.0.3</td>
|
49
|
+
</tr>
|
50
|
+
<tr>
|
51
|
+
<th>Twitter Bootstrap</th>
|
52
|
+
<td>>= 3.0.0</td>
|
53
|
+
</tr>
|
54
|
+
</table>
|
55
|
+
|
56
|
+
## Legacy Bootstrap 2 Support
|
57
|
+
|
58
|
+
Use version 0.2.5, in your GemFile use
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
gem 'will_paginate-bootstrap', '0.2.5'
|
62
|
+
```
|
data/Rakefile
ADDED
data/example/app.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "sinatra"
|
2
|
+
require "will_paginate-bootstrap"
|
3
|
+
require "will_paginate/collection"
|
4
|
+
|
5
|
+
CDN_PATH = "//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"
|
6
|
+
|
7
|
+
$template = <<EOHTML
|
8
|
+
<html>
|
9
|
+
<head>
|
10
|
+
<title>will_paginate-boostrap Example App</title>
|
11
|
+
<link href="<%= CDN_PATH %>" rel="stylesheet">
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
<%= will_paginate @collection, renderer: BootstrapPagination::Sinatra %>
|
15
|
+
</body>
|
16
|
+
</html>
|
17
|
+
EOHTML
|
18
|
+
|
19
|
+
def build_collection
|
20
|
+
page = if params[:page].to_i > 0
|
21
|
+
params[:page].to_i
|
22
|
+
else
|
23
|
+
1
|
24
|
+
end
|
25
|
+
|
26
|
+
@collection = WillPaginate::Collection.new page, 10, 100000
|
27
|
+
end
|
28
|
+
|
29
|
+
get "/" do
|
30
|
+
build_collection
|
31
|
+
erb $template
|
32
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "will_paginate/view_helpers/action_view"
|
2
|
+
require "bootstrap_pagination/bootstrap_renderer"
|
3
|
+
|
4
|
+
module BootstrapPagination
|
5
|
+
# A custom renderer class for WillPaginate that produces markup suitable for use with Twitter Bootstrap.
|
6
|
+
class Rails < WillPaginate::ActionView::LinkRenderer
|
7
|
+
include BootstrapRenderer
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "bootstrap_pagination/version"
|
2
|
+
|
3
|
+
module BootstrapPagination
|
4
|
+
# Contains functionality shared by all renderer classes.
|
5
|
+
module BootstrapRenderer
|
6
|
+
ELLIPSIS = "…"
|
7
|
+
|
8
|
+
def to_html
|
9
|
+
list_items = pagination.map do |item|
|
10
|
+
case item
|
11
|
+
when Fixnum
|
12
|
+
page_number(item)
|
13
|
+
else
|
14
|
+
send(item)
|
15
|
+
end
|
16
|
+
end.join(@options[:link_separator])
|
17
|
+
|
18
|
+
tag("ul", list_items, class: ul_class)
|
19
|
+
end
|
20
|
+
|
21
|
+
def container_attributes
|
22
|
+
super.except(*[:link_options])
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def page_number(page)
|
28
|
+
link_options = @options[:link_options] || {}
|
29
|
+
|
30
|
+
if page == current_page
|
31
|
+
tag("li", tag("span", page), class: "active")
|
32
|
+
else
|
33
|
+
tag("li", link(page, page, link_options.merge(rel: rel_value(page))))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def previous_or_next_page(page, text, classname)
|
38
|
+
link_options = @options[:link_options] || {}
|
39
|
+
|
40
|
+
if page
|
41
|
+
tag("li", link(text, page, link_options), class: classname)
|
42
|
+
else
|
43
|
+
tag("li", tag("span", text), class: "%s disabled" % classname)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def gap
|
48
|
+
tag("li", link(ELLIPSIS, "#"), class: "disabled")
|
49
|
+
end
|
50
|
+
|
51
|
+
def previous_page
|
52
|
+
num = @collection.current_page > 1 && @collection.current_page - 1
|
53
|
+
previous_or_next_page(num, @options[:previous_label], "prev")
|
54
|
+
end
|
55
|
+
|
56
|
+
def next_page
|
57
|
+
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
|
58
|
+
previous_or_next_page(num, @options[:next_label], "next")
|
59
|
+
end
|
60
|
+
|
61
|
+
def ul_class
|
62
|
+
["pagination", @options[:class]].compact.join(" ")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "will_paginate/view_helpers/sinatra"
|
2
|
+
require "bootstrap_pagination/bootstrap_renderer"
|
3
|
+
|
4
|
+
module BootstrapPagination
|
5
|
+
# A custom renderer class for WillPaginate that produces markup suitable for use with Twitter Bootstrap.
|
6
|
+
class Sinatra < WillPaginate::Sinatra::LinkRenderer
|
7
|
+
include BootstrapRenderer
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "will_paginate/bootstrap"
|
data/pagination.png
ADDED
Binary file
|
@@ -0,0 +1,99 @@
|
|
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
|
+
# Render pagination for the middle page so that we can test for the presence of
|
22
|
+
# start, prev and next links. We should also be able to test for test for the
|
23
|
+
# presence of a "gap" item if the collection size is large enough.
|
24
|
+
let(:collection_size) { 15 }
|
25
|
+
let(:page) { (collection_size / 2.0).to_i }
|
26
|
+
let(:collection) { 1.upto(collection_size).to_a }
|
27
|
+
let(:link_options) { nil }
|
28
|
+
let(:class_opt) { nil }
|
29
|
+
|
30
|
+
let(:output) do
|
31
|
+
will_paginate(
|
32
|
+
collection.paginate(:page => page, :per_page => 1),
|
33
|
+
renderer: MockRenderer, link_options: link_options,
|
34
|
+
class: class_opt
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:html) { Nokogiri::HTML.fragment(output) }
|
39
|
+
|
40
|
+
it "returns a string" do
|
41
|
+
output.must_be_kind_of String
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns a string containing HTML" do
|
45
|
+
html.must_be_kind_of Nokogiri::HTML::DocumentFragment
|
46
|
+
end
|
47
|
+
|
48
|
+
it "has an active list item" do
|
49
|
+
html.at_css('ul li.active').wont_be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "has a gap item with class disabled" do
|
53
|
+
html.at_css('ul li.disabled').wont_be_nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it "has one item with rel start value" do
|
57
|
+
html.css('[rel~=start]').size.must_equal 1
|
58
|
+
end
|
59
|
+
|
60
|
+
it "has two items with rel prev value" do
|
61
|
+
html.css('[rel~=prev]').size.must_equal 2
|
62
|
+
end
|
63
|
+
|
64
|
+
it "has two items with rel next value" do
|
65
|
+
html.css('[rel~=next]').size.must_equal 2
|
66
|
+
end
|
67
|
+
|
68
|
+
it "has an anchor within each non-active list item" do
|
69
|
+
html.css('ul li:not(.active)').each { |li| li.at_css('a').wont_be_nil }
|
70
|
+
end
|
71
|
+
|
72
|
+
it "uses a span element for the active page" do
|
73
|
+
html.at_css('ul li.active span').wont_be_nil
|
74
|
+
end
|
75
|
+
|
76
|
+
it "has no outer pagination div" do
|
77
|
+
html.at_css('div.pagination').must_be_nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it "has an unordered list with the pagination class" do
|
81
|
+
html.at_css('ul.pagination').wont_be_nil
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "when specifying a custom class" do
|
85
|
+
let(:class_opt) { "pagination-lg" }
|
86
|
+
|
87
|
+
it "applies the class to the ul" do
|
88
|
+
html.at_css("ul.pagination.pagination-lg").wont_be_nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "with link attribute specified" do
|
93
|
+
let(:link_options) { {"data-remote" => true} }
|
94
|
+
|
95
|
+
it "includes the link attribute" do
|
96
|
+
html.at_css('li.prev a')["data-remote"].must_equal "true"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "bootstrap_pagination/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "hobo_will_paginate-bootstrap"
|
7
|
+
s.version = BootstrapPagination::VERSION
|
8
|
+
s.authors = ["Nick Dainty"]
|
9
|
+
s.email = ["nick@npad.co.uk"]
|
10
|
+
s.homepage = "https://github.com/nickpad/will_paginate-bootstrap"
|
11
|
+
s.summary = %q{Integrates the Twitter Bootstrap pagination component with will_paginate}
|
12
|
+
s.description = %q{This gem integrates the Twitter Bootstrap pagination component with the will_paginate pagination gem. Supports Rails and Sinatra.}
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.rubyforge_project = "will_paginate-bootstrap"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_runtime_dependency "hobo_will_paginate"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hobo_will_paginate-bootstrap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Dainty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hobo_will_paginate
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: This gem integrates the Twitter Bootstrap pagination component with the
|
28
|
+
will_paginate pagination gem. Supports Rails and Sinatra.
|
29
|
+
email:
|
30
|
+
- nick@npad.co.uk
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- Gemfile
|
37
|
+
- MIT-LICENSE
|
38
|
+
- README.markdown
|
39
|
+
- Rakefile
|
40
|
+
- example/app.rb
|
41
|
+
- lib/bootstrap_pagination/action_view.rb
|
42
|
+
- lib/bootstrap_pagination/bootstrap_renderer.rb
|
43
|
+
- lib/bootstrap_pagination/sinatra.rb
|
44
|
+
- lib/bootstrap_pagination/version.rb
|
45
|
+
- lib/will_paginate-bootstrap.rb
|
46
|
+
- lib/will_paginate/bootstrap.rb
|
47
|
+
- pagination.png
|
48
|
+
- spec/pagination_spec.rb
|
49
|
+
- will_paginate-bootstrap.gemspec
|
50
|
+
homepage: https://github.com/nickpad/will_paginate-bootstrap
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project: will_paginate-bootstrap
|
70
|
+
rubygems_version: 2.1.11
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Integrates the Twitter Bootstrap pagination component with will_paginate
|
74
|
+
test_files: []
|