spinels-will_paginate-bootstrap 0.2.5.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f2e619c33a7349b0a0cd4a2374112a788bf3e7543bf05dcbb92432cf64b35d10
4
+ data.tar.gz: 5a022b5a74e7f83985f3912079d9839a42237003abd2098213a5ccbde6157653
5
+ SHA512:
6
+ metadata.gz: 56891b6d798b9b57a3543ae7139d7e7a90f66e38a9bcf1ce50a5781438076b3372e5e8ee2be480e5ac7a19b10cd6d7ca0f7141094300677a0355ec3dd88fb570
7
+ data.tar.gz: 6e003dd2da2bb1a734355c991953c445b23f37c024e2d8bd6fb81a8604a98db7bfd8c0c8d1e2c2b784c201b0a0c21e975cf4de5b1d437c8abe24b807165d97e1
@@ -0,0 +1,24 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+
6
+ jobs:
7
+ test:
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ os:
12
+ - ubuntu-latest
13
+ ruby:
14
+ - 2.7
15
+ - 3.2
16
+ - ruby-head
17
+ runs-on: ${{ matrix.os }}
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ bundler-cache: true
24
+ - run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in will_paginate-bootstrap.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "rake"
8
+ gem "nokogiri"
9
+ gem "minitest"
10
+ gem "minitest-global_expectations"
11
+ end
12
+
13
+ group :example_app do
14
+ gem "sinatra"
15
+ end
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
+ As with will_paginate itself, Rails and Sinatra are supported.
10
+
11
+ ## Install
12
+
13
+ * `gem install spinels-will_paginate-bootstrap`, *or*
14
+ * For projects using Bundler, add `gem 'spinels-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
+ ## 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.
46
+
47
+ ## Compatibility
48
+
49
+ <table>
50
+ <tr>
51
+ <th>Ruby</th>
52
+ <td>>= 1.9.2</td>
53
+ </tr>
54
+ <tr>
55
+ <th>will_paginate</th>
56
+ <td>>= 3.0.3</td>
57
+ </tr>
58
+ <tr>
59
+ <th>Bootstrap</th>
60
+ <td>>= 2.0.0</td>
61
+ </tr>
62
+ </table>
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "spec/*_spec.rb"
6
+ end
7
+
8
+ task :default => :test
data/example/app.rb ADDED
@@ -0,0 +1,59 @@
1
+ require "sinatra"
2
+ require "will_paginate-bootstrap"
3
+ require "will_paginate/collection"
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
+
25
+ $template = <<EOHTML
26
+ <html>
27
+ <head>
28
+ <title>will_paginate-boostrap Example App</title>
29
+ <link href="<%= href %>" rel="stylesheet">
30
+ </head>
31
+ <body>
32
+ <%= will_paginate @collection, renderer: BootstrapPagination::Sinatra, bootstrap: version %>
33
+ </body>
34
+ </html>
35
+ EOHTML
36
+
37
+ def build_collection
38
+ page = if params[:page].to_i > 0
39
+ params[:page].to_i
40
+ else
41
+ 1
42
+ end
43
+
44
+ @collection = WillPaginate::Collection.new page, 10, 100000
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
@@ -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,63 @@
1
+ require "bootstrap_pagination/version"
2
+
3
+ module BootstrapPagination
4
+ # Contains functionality shared by all renderer classes.
5
+ module BootstrapRenderer
6
+ ELLIPSIS = "&hellip;"
7
+
8
+ def to_html
9
+ list_items = pagination.map do |item|
10
+ case item
11
+ when Integer
12
+ page_number(item)
13
+ else
14
+ send(item)
15
+ end
16
+ end.join(@options[:link_separator])
17
+
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
23
+ end
24
+
25
+ def container_attributes
26
+ super.except(*[:link_options])
27
+ end
28
+
29
+ protected
30
+
31
+ def page_number(page)
32
+ link_options = @options[:link_options] || {}
33
+ if page == current_page
34
+ tag("li", tag("span", page), class: "active")
35
+ else
36
+ tag("li", link(page, page, link_options.merge(rel: rel_value(page))))
37
+ end
38
+ end
39
+
40
+ def gap
41
+ tag("li", link(ELLIPSIS, "#"), class: "disabled")
42
+ end
43
+
44
+ def previous_page
45
+ num = @collection.current_page > 1 && @collection.current_page - 1
46
+ previous_or_next_page(num, @options[:previous_label], "prev")
47
+ end
48
+
49
+ def next_page
50
+ num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
51
+ previous_or_next_page(num, @options[:next_label], "next")
52
+ end
53
+
54
+ def previous_or_next_page(page, text, classname)
55
+ link_options = @options[:link_options] || {}
56
+ if page
57
+ tag("li", link(text, page, link_options), class: classname)
58
+ else
59
+ tag("li", tag("span", text), class: "%s disabled" % classname)
60
+ end
61
+ end
62
+ end
63
+ 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,3 @@
1
+ module BootstrapPagination
2
+ VERSION = "0.2.5.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'will_paginate'
2
+
3
+ if defined?(ActionView)
4
+ require "bootstrap_pagination/action_view"
5
+ end
6
+
7
+ if defined?(Sinatra)
8
+ require "bootstrap_pagination/sinatra"
9
+ end
@@ -0,0 +1 @@
1
+ require "will_paginate/bootstrap"
data/pagination.png ADDED
Binary file
@@ -0,0 +1,100 @@
1
+ require 'minitest/global_expectations/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(:version) { nil }
28
+ let(:link_options) { nil}
29
+
30
+ let(:output) do
31
+ will_paginate(
32
+ collection.paginate(:page => page, :per_page => 1),
33
+ renderer: MockRenderer, bootstrap: version, link_options: link_options
34
+ )
35
+ end
36
+
37
+ let(:html) { Nokogiri::HTML.fragment(output) }
38
+
39
+ it "returns a string" do
40
+ output.must_be_kind_of String
41
+ end
42
+
43
+ it "returns a string containing HTML" do
44
+ html.must_be_kind_of Nokogiri::HTML::DocumentFragment
45
+ end
46
+
47
+ it "has an active list item" do
48
+ html.at_css('ul li.active').wont_be_nil
49
+ end
50
+
51
+ it "has a gap item with class disabled" do
52
+ html.at_css('ul li.disabled').wont_be_nil
53
+ end
54
+
55
+ it "has two items with rel prev value" do
56
+ html.css('[rel~=prev]').size.must_equal 2
57
+ end
58
+
59
+ it "has two items with rel next value" do
60
+ html.css('[rel~=next]').size.must_equal 2
61
+ end
62
+
63
+ it "has an anchor within each non-active list item" do
64
+ html.css('ul li:not(.active)').each { |li| li.at_css('a').wont_be_nil }
65
+ end
66
+
67
+ it "uses a span element for the active page" do
68
+ html.at_css('ul li.active span').wont_be_nil
69
+ end
70
+
71
+ describe "with markup for v2" do
72
+ it "has an outer pagination div" do
73
+ html.at_css('div.pagination').wont_be_nil
74
+ end
75
+
76
+ it "has an unordered list within the pagination div" do
77
+ html.at_css('div.pagination ul').wont_be_nil
78
+ end
79
+ end
80
+
81
+ describe "with markup for v3" do
82
+ let(:version) { 3 }
83
+
84
+ it "has no outer pagination div" do
85
+ html.at_css('div.pagination').must_be_nil
86
+ end
87
+
88
+ it "has an unordered list with the pagination class" do
89
+ html.at_css('ul.pagination').wont_be_nil
90
+ end
91
+ end
92
+
93
+ describe "with link attribute specified" do
94
+ let(:link_options) { {"data-remote" => true} }
95
+
96
+ it "includes the link attribute" do
97
+ html.at_css('li.prev a')["data-remote"].must_equal "true"
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,20 @@
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 = "spinels-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/spinels/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
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency "will_paginate", ">= 3.0.3"
20
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spinels-will_paginate-bootstrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.5.1
5
+ platform: ruby
6
+ authors:
7
+ - Nick Dainty
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: will_paginate
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.3
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
+ - ".github/workflows/ci.yml"
36
+ - ".gitignore"
37
+ - Gemfile
38
+ - MIT-LICENSE
39
+ - README.markdown
40
+ - Rakefile
41
+ - example/app.rb
42
+ - lib/bootstrap_pagination/action_view.rb
43
+ - lib/bootstrap_pagination/bootstrap_renderer.rb
44
+ - lib/bootstrap_pagination/sinatra.rb
45
+ - lib/bootstrap_pagination/version.rb
46
+ - lib/will_paginate-bootstrap.rb
47
+ - lib/will_paginate/bootstrap.rb
48
+ - pagination.png
49
+ - spec/pagination_spec.rb
50
+ - will_paginate-bootstrap.gemspec
51
+ homepage: https://github.com/spinels/will_paginate-bootstrap
52
+ licenses: []
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
+ rubygems_version: 3.4.7
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Integrates the Twitter Bootstrap pagination component with will_paginate
73
+ test_files:
74
+ - spec/pagination_spec.rb