rs_paginator 0.0.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
+ SHA1:
3
+ metadata.gz: 1b34b9cb6e1afe9900b9c2fd7883a28aa4c32b9a
4
+ data.tar.gz: a9f885f767f4723a8ceb6e37ce9b746b239008a7
5
+ SHA512:
6
+ metadata.gz: 0f8036b077a6f4734133789f9a4331e23161f18929d6cbc98bacc7fec85b19e49d3f3f911f1ff68681385e19f16e0d15b67078f3db5ba6b89ac06963859ab4cd
7
+ data.tar.gz: 5169f67e267b1dff36ac771094e89981c2bca20c98533b1a51d895d5f0e5f17ef294170e231d7116487d9212b85f1caabdaf715302308ccbcfcadaa6a04129a7
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2014 RadarServices Smart IT-Security <gems@radarservices.com>
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # RS-Paginator
2
+
3
+ ``rs_pagination`` implements Bootstrap pagination for generic collections.
4
+
5
+
6
+ ## Installation
7
+
8
+ ```
9
+ $ gem install rs_paginator
10
+ ```
11
+
12
+ ```ruby
13
+ require 'rs_paginator'
14
+ ```
15
+
16
+ or use ``gem 'rs_paginator'`` in your Gemfile when using bundler.
17
+
18
+
19
+ ### Usage
20
+
21
+ Create a collection in your controller.
22
+ ```ruby
23
+ collection = RsPaginator::Collection(objects, 1, 10, 27)
24
+ ```
25
+
26
+ And use it inside your view.
27
+ ```ruby
28
+ paginate(collection)
29
+ ```
@@ -0,0 +1,7 @@
1
+ en:
2
+ rs_paginator:
3
+ page_info:
4
+ empty: No entries found
5
+ one: Displaying one entry
6
+ one_page: Displaying %{total} entries
7
+ other: Displaying entries %{from} - %{to} of %{total}
@@ -0,0 +1,20 @@
1
+ module RsPaginator
2
+ class Collection < SimpleDelegator
3
+
4
+ include Enumerable
5
+ attr_reader :page, :per_page, :total
6
+
7
+ def initialize(objects, page, per_page, total)
8
+ @objects = objects
9
+ @page = page.to_i
10
+ @per_page = per_page.to_i
11
+ @total = total.to_i
12
+ super(objects)
13
+ end
14
+
15
+ def total_pages
16
+ (@total.to_f / @per_page).ceil
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ module RsPaginator
2
+ class PageInfo
3
+
4
+ include ActionView::Context
5
+ include ActionView::Helpers::TagHelper
6
+ include ActionView::Helpers::OutputSafetyHelper
7
+
8
+ def initialize(objects, context)
9
+ @objects = objects
10
+ @context = context
11
+ end
12
+
13
+ def render
14
+ content_tag(:div, class: 'page_info') do
15
+ if @objects.empty?
16
+ @context.t('rs_paginator.page_info.empty')
17
+ elsif @objects.total_pages == 1 && @objects.count == 1
18
+ @context.t('rs_paginator.page_info.one')
19
+ elsif @objects.total_pages == 1
20
+ @context.t('rs_paginator.page_info.one_page', total: @objects.total)
21
+ else
22
+ from = @objects.per_page * (@objects.page - 1) + 1
23
+ to = from + @objects.count - 1
24
+ @context.t('rs_paginator.page_info.other', from: from, to: to, total: @objects.total)
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,68 @@
1
+ module RsPaginator
2
+ class Paginator
3
+
4
+ include ActionView::Context
5
+ include ActionView::Helpers::TagHelper
6
+ include ActionView::Helpers::OutputSafetyHelper
7
+
8
+ def initialize(objects, context)
9
+ @objects = objects
10
+ @context = context
11
+ @total_pages = objects.total_pages
12
+ @current_page = objects.page
13
+ end
14
+
15
+ def render
16
+ content_tag(:ul, class: %w[pagination pagination-sm]) do
17
+ prev_link + page_links + next_link
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def prev_link
24
+ first = @current_page == 1
25
+ content_tag(:li, class: first ? 'disabled' : nil) do
26
+ url = first ? '#' : @context.params.merge(page: @current_page - 1)
27
+ @context.link_to(raw('&laquo;'), url)
28
+ end
29
+ end
30
+
31
+ def next_link
32
+ last = @current_page == @total_pages
33
+ content_tag(:li, class: last ? 'disabled' : nil) do
34
+ url = last ? '#' : @context.params.merge(page: @current_page + 1)
35
+ @context.link_to(raw('&raquo;'), url)
36
+ end
37
+ end
38
+
39
+ def page_links
40
+ raw visible_pages.map { |i| i ? page_link(i) : gap }.join
41
+ end
42
+
43
+ def page_link(i)
44
+ current = i == @current_page
45
+ content_tag(:li, class: current ? 'active' : nil) do
46
+ url = current ? '#' : @context.params.merge(page: i)
47
+ @context.link_to(i, url)
48
+ end
49
+ end
50
+
51
+ def gap
52
+ content_tag(:li, @context.link_to(raw('&#x22ef;'), '#'), class: 'disabled')
53
+ end
54
+
55
+ def visible_pages
56
+ if @total_pages <= 11
57
+ 1..@total_pages
58
+ elsif @current_page <= 6
59
+ (1..8).to_a + [nil, @total_pages-1, @total_pages]
60
+ elsif @current_page > @total_pages - 6
61
+ [1, 2, nil] + ((@total_pages - 8)..@total_pages).to_a
62
+ else
63
+ [1, 2, nil] + ((@current_page - 2)..(@current_page + 2)).to_a + [nil, @total_pages-1, @total_pages]
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,11 @@
1
+ require 'rs_paginator/view_helpers'
2
+
3
+ module RsPaginator
4
+ class Railtie < Rails::Railtie
5
+
6
+ initializer "rs_paginator" do
7
+ ActionView::Base.send :include, RsPaginator::ViewHelpers
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module RsPaginator
2
+
3
+ VERSION = '0.0.1'
4
+
5
+ end
@@ -0,0 +1,13 @@
1
+ module RsPaginator
2
+ module ViewHelpers
3
+
4
+ def paginate(objects)
5
+ RsPaginator::Paginator.new(objects, self).render
6
+ end
7
+
8
+ def page_info(objects)
9
+ RsPaginator::PageInfo.new(objects, self).render
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ require 'i18n'
2
+ I18n.load_path += Dir[File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'locales', '*.yml'))]
3
+
4
+ require 'rs_paginator/collection'
5
+ require 'rs_paginator/page_info'
6
+ require 'rs_paginator/paginator'
7
+ require 'rs_paginator/railtie' if defined?(Rails)
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), 'lib', 'rs_paginator', 'version')
4
+
5
+ require 'date'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "rs_paginator"
9
+ s.version = RsPaginator::VERSION
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = [
13
+ "Sebastian Weiss <sebastian.weiss@radarservices.com",
14
+ "Martin Natano <martin.natano@radarservices.com",
15
+ ]
16
+ s.date = Date.today.strftime
17
+ s.description = "RadarServices (Bootstrap) Paginator"
18
+ s.email = "gems [a] radarservices [d] com"
19
+ s.files = `git ls-files`.split("\n").reject { |file| file == '.gitignore' }
20
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
21
+ s.extra_rdoc_files = %w[LICENSE README.md]
22
+
23
+ s.homepage = "http://github.com/rs-dev/rs_paginator"
24
+ s.require_paths = ["lib"]
25
+ s.summary = "RadarServices (Bootstrap) Paginator"
26
+ s.license = "ISC"
27
+
28
+ s.add_runtime_dependency(%q<i18n>)
29
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rs_paginator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Weiss <sebastian.weiss@radarservices.com
8
+ - Martin Natano <martin.natano@radarservices.com
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: i18n
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: RadarServices (Bootstrap) Paginator
29
+ email: gems [a] radarservices [d] com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - LICENSE
34
+ - README.md
35
+ files:
36
+ - LICENSE
37
+ - README.md
38
+ - config/locales/en.yml
39
+ - lib/rs_paginator.rb
40
+ - lib/rs_paginator/collection.rb
41
+ - lib/rs_paginator/page_info.rb
42
+ - lib/rs_paginator/paginator.rb
43
+ - lib/rs_paginator/railtie.rb
44
+ - lib/rs_paginator/version.rb
45
+ - lib/rs_paginator/view_helpers.rb
46
+ - rs_paginator.gemspec
47
+ homepage: http://github.com/rs-dev/rs_paginator
48
+ licenses:
49
+ - ISC
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.2.1
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: RadarServices (Bootstrap) Paginator
71
+ test_files: []