will_paginate_infinite 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 444accbac3d55cc4911441991f917eb880910a8e
4
+ data.tar.gz: f03ff150b2cf27a6957f6aefce1dd9e5f57cf372
5
+ SHA512:
6
+ metadata.gz: 7ccd2018c75d9ac4f45f7b546b7a2713b364f6f8f4486245547904b17a070c8319a0651ffe539730bb08e0506ff0b3ecb96640780072c73baf017c6b819a8115
7
+ data.tar.gz: 606d9b6cc2f19561c1676870671e9e5b45dd9b675749207d3791c7b2b2795a9b47e14bd4a5779ca19089fbfd8d79ec023a14f0e4f01f62b24767b539af7cbc35
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Instalation
2
+
3
+ Include the gem in your Gemfile:
4
+ ```
5
+ gem 'will_paginate_infinite'
6
+ ```
7
+ And then execute:
8
+ ```
9
+ $ bundle install
10
+ ```
11
+
12
+
13
+ Adds to `app/assets/stylesheets/application.scss`:
14
+ ```
15
+ *= require will_paginate_infinite
16
+ ```
17
+
18
+ And javascript to `app/assets/javascripts/application.js`:
19
+ ```
20
+ //= require will_paginate_infinite
21
+ ```
22
+
23
+
24
+ # Configuration
25
+ In your index view pagination :
26
+ ```
27
+ # app/views/news/index.html.erb
28
+ <h1>News List</h1>
29
+
30
+ <div class="list-news">
31
+ <ul>
32
+ <% @news.each do |item| %>
33
+ <%= render item %>
34
+ <% end %>
35
+ </ul>
36
+
37
+ <%= will_paginate @news, renderer: WillPaginateInfinite::InfinitePagination %>
38
+ </div>
39
+ ```
40
+ Will paginate renderer: `WillPaginateInfinite::InfinitePagination`
41
+
42
+
43
+ In content partial view:
44
+ ```
45
+ # app/views/news/_news.html.erb
46
+ <li>
47
+ <%= item.title %>
48
+ </li>
49
+ ```
50
+
51
+ And in controller/action with items to be paginated:
52
+ ```
53
+ # app/controllers/news_controller.rb
54
+ class NewsController < ApplicationController
55
+ def index
56
+ @news = News.order(:created_at).paginate(:page => params[:page], :per_page => 30)
57
+ # ...
58
+
59
+ respond_to do |format|
60
+ format.html
61
+ format.js
62
+ end
63
+ end
64
+ end
65
+ ```
66
+
67
+ Creates a javascript version from your index view:
68
+ ```
69
+ # app/views/news/index.js.erb
70
+ <%= infinite_append ".list-news ul", @news %>
71
+ ```
72
+ or
73
+ ```
74
+ # app/views/news/index.js.erb
75
+ <%= infinite_append ".list-news ul", { partial: "news/news", collection: @news } %>
76
+ ```
@@ -0,0 +1,13 @@
1
+ jQuery(function() {
2
+ if ($('.infinite-pagination').size() > 0) {
3
+ $(window).on('scroll', function() {
4
+ var more_posts_url = $('.infinite-pagination a.next_page').attr('href');
5
+ var bottom_distance = 20;
6
+
7
+ if (more_posts_url && $(window).scrollTop() > $(document).height() - $(window).height() - bottom_distance) {
8
+ $('.infinite-pagination').html('Carregando...');
9
+ $.getScript(more_posts_url);
10
+ }
11
+ });
12
+ }
13
+ });
@@ -0,0 +1,17 @@
1
+ module InfiniteHelper
2
+ def infinite_append(containerSelector, render_options)
3
+ collection = render_options
4
+ collection = render_options[:collection] unless render_options.is_a?(ActiveRecord::Relation)
5
+
6
+ html = "$('" + containerSelector + "').append('"+ j(render render_options) + "');"
7
+
8
+ if collection.next_page
9
+ html += "$('.infinite-pagination').replaceWith('" + j(will_paginate(collection, renderer: WillPaginateInfinite::InfinitePagination)) + "');"
10
+ else
11
+ html += "$(window).off('scroll');"
12
+ html += "$('.infinite-pagination').remove();"
13
+ end
14
+
15
+ html.html_safe
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ # require 'will_paginate'
2
+ #
3
+ # module WillPaginateInfinite
4
+ # module Willpaginate
5
+ # class Engine < ::Rails::Engine
6
+ # end
7
+ # end
8
+ # end
9
+ require "will_paginate/view_helpers/action_view"
10
+ require "will_paginate_infinite/infinite_renderer"
11
+
12
+ module WillPaginateInfinite
13
+ class InfinitePagination < WillPaginate::ActionView::LinkRenderer
14
+ include WillPaginateInfinite::InfiniteRenderer
15
+ end
16
+
17
+ class Engine < ::Rails::Engine
18
+ end
19
+ end
@@ -0,0 +1,64 @@
1
+ # require "bootstrap_pagination/version"
2
+
3
+ module WillPaginateInfinite
4
+ # Contains functionality shared by all renderer classes.
5
+ module InfiniteRenderer
6
+
7
+ def to_html
8
+ list_items = pagination.map do |item|
9
+ case item
10
+ when Fixnum
11
+ page_number(item)
12
+ else
13
+ send(item)
14
+ end
15
+ end.join(@options[:link_separator])
16
+
17
+ tag("ul", list_items, class: ul_class)
18
+ end
19
+
20
+ def container_attributes
21
+ super.except(*[:link_options])
22
+ end
23
+
24
+ protected
25
+
26
+ # def page_number(page)
27
+ # link_options = @options[:link_options] || {}
28
+ #
29
+ # if page == current_page
30
+ # tag("li", tag("span", page), class: "active")
31
+ # else
32
+ # tag("li", link(page, page, link_options.merge(rel: rel_value(page))))
33
+ # end
34
+ # end
35
+
36
+ # def previous_or_next_page(page, text, classname)
37
+ # link_options = @options[:link_options] || {}
38
+ #
39
+ # if page
40
+ # tag("li", link(text, page, link_options), class: classname)
41
+ # else
42
+ # tag("li", tag("span", text), class: "%s disabled" % classname)
43
+ # end
44
+ # end
45
+
46
+ # def gap
47
+ # tag("li", tag("span", ELLIPSIS), class: "disabled")
48
+ # end
49
+
50
+ # def previous_page
51
+ # num = @collection.current_page > 1 && @collection.current_page - 1
52
+ # previous_or_next_page(num, @options[:previous_label], "prev")
53
+ # end
54
+ #
55
+ # def next_page
56
+ # num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
57
+ # previous_or_next_page(num, @options[:next_label], "next")
58
+ # end
59
+
60
+ def ul_class
61
+ ["infinite-pagination", @options[:class]].compact.join(" ")
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'version'
4
+ Gem::Specification.new do |s|
5
+ s.name = 'will_paginate_infinite'
6
+ s.version = '0.0.1'
7
+ s.date = '2016-07-15'
8
+ s.summary = "Will Paginate with infinite scroll"
9
+ s.description = "Will Paginate with infinite scroll"
10
+ s.authors = ["Adriano Godoy"]
11
+ s.email = 'godoy.ccp@gmail.com'
12
+
13
+ s.files = `git ls-files -z`.split("\x0")
14
+ s.require_paths = ["lib"]
15
+
16
+
17
+ s.homepage =
18
+ 'http://rubygems.org/gems/will_paginate_infinite'
19
+ s.license = 'MIT'
20
+
21
+ s.add_runtime_dependency "will_paginate"
22
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: will_paginate_infinite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adriano Godoy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-15 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: '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: Will Paginate with infinite scroll
28
+ email: godoy.ccp@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - README.md
35
+ - app/assets/javascripts/will_paginate_infinite.js
36
+ - app/assets/stylesheets/will_paginate_infinite.scss
37
+ - app/helpers/infinite_helper.rb
38
+ - lib/will_paginate_infinite.rb
39
+ - lib/will_paginate_infinite/infinite_renderer.rb
40
+ - will_paginate_infinite.gemspec
41
+ homepage: http://rubygems.org/gems/will_paginate_infinite
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.5.1
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Will Paginate with infinite scroll
65
+ test_files: []