bootstrap_pager 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/.idea/encodings.xml +5 -0
  4. data/.idea/misc.xml +5 -0
  5. data/.idea/modules.xml +9 -0
  6. data/.idea/pager.iml +50 -0
  7. data/.idea/scopes/scope_settings.xml +5 -0
  8. data/.idea/vcs.xml +7 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE +20 -0
  11. data/MIT-LICENSE +20 -0
  12. data/README.rdoc +307 -0
  13. data/Rakefile +42 -0
  14. data/app/assets/javascripts/infinitescroll.js +8 -0
  15. data/app/helpers/pager_helper.rb +5 -0
  16. data/app/views/pager/_first_page.html.erb +11 -0
  17. data/app/views/pager/_first_page.html.haml +9 -0
  18. data/app/views/pager/_first_page.html.slim +10 -0
  19. data/app/views/pager/_gap.html.erb +8 -0
  20. data/app/views/pager/_gap.html.haml +8 -0
  21. data/app/views/pager/_gap.html.slim +10 -0
  22. data/app/views/pager/_last_page.html.erb +11 -0
  23. data/app/views/pager/_last_page.html.haml +9 -0
  24. data/app/views/pager/_last_page.html.slim +10 -0
  25. data/app/views/pager/_next_page.html.erb +11 -0
  26. data/app/views/pager/_next_page.html.haml +9 -0
  27. data/app/views/pager/_next_page.html.slim +10 -0
  28. data/app/views/pager/_page.html.erb +14 -0
  29. data/app/views/pager/_page.html.haml +11 -0
  30. data/app/views/pager/_page.html.slim +13 -0
  31. data/app/views/pager/_paginator.html.erb +25 -0
  32. data/app/views/pager/_paginator.html.haml +19 -0
  33. data/app/views/pager/_paginator.html.slim +20 -0
  34. data/app/views/pager/_prev_page.html.erb +11 -0
  35. data/app/views/pager/_prev_page.html.haml +9 -0
  36. data/app/views/pager/_prev_page.html.slim +10 -0
  37. data/bootstrap_pager.gemspec +36 -0
  38. data/config/locales/pager.yml +19 -0
  39. data/gemfiles/active_record_30.gemfile +9 -0
  40. data/gemfiles/active_record_31.gemfile +7 -0
  41. data/gemfiles/active_record_32.gemfile +10 -0
  42. data/gemfiles/active_record_40.gemfile +8 -0
  43. data/gemfiles/active_record_edge.gemfile +11 -0
  44. data/gemfiles/data_mapper_12.gemfile +15 -0
  45. data/gemfiles/mongo_mapper.gemfile +10 -0
  46. data/gemfiles/mongoid_24.gemfile +7 -0
  47. data/gemfiles/mongoid_30.gemfile +12 -0
  48. data/gemfiles/sinatra_13.gemfile +13 -0
  49. data/gemfiles/sinatra_14.gemfile +13 -0
  50. data/lib/bootstrap_pager/config.rb +51 -0
  51. data/lib/bootstrap_pager/grape.rb +4 -0
  52. data/lib/bootstrap_pager/helpers/action_view_extension.rb +152 -0
  53. data/lib/bootstrap_pager/helpers/paginator.rb +186 -0
  54. data/lib/bootstrap_pager/helpers/sinatra_helpers.rb +144 -0
  55. data/lib/bootstrap_pager/helpers/tags.rb +96 -0
  56. data/lib/bootstrap_pager/hooks.rb +41 -0
  57. data/lib/bootstrap_pager/models/active_record_extension.rb +22 -0
  58. data/lib/bootstrap_pager/models/active_record_model_extension.rb +20 -0
  59. data/lib/bootstrap_pager/models/active_record_relation_methods.rb +29 -0
  60. data/lib/bootstrap_pager/models/array_extension.rb +58 -0
  61. data/lib/bootstrap_pager/models/configuration_methods.rb +48 -0
  62. data/lib/bootstrap_pager/models/data_mapper_collection_methods.rb +15 -0
  63. data/lib/bootstrap_pager/models/data_mapper_extension.rb +48 -0
  64. data/lib/bootstrap_pager/models/mongo_mapper_extension.rb +18 -0
  65. data/lib/bootstrap_pager/models/mongoid_criteria_methods.rb +23 -0
  66. data/lib/bootstrap_pager/models/mongoid_extension.rb +33 -0
  67. data/lib/bootstrap_pager/models/page_scope_methods.rb +70 -0
  68. data/lib/bootstrap_pager/models/plucky_criteria_methods.rb +18 -0
  69. data/lib/bootstrap_pager/railtie.rb +7 -0
  70. data/lib/bootstrap_pager/sinatra.rb +5 -0
  71. data/lib/bootstrap_pager/version.rb +3 -0
  72. data/lib/bootstrap_pager.rb +38 -0
  73. data/lib/generators/pager/config_generator.rb +16 -0
  74. data/lib/generators/pager/templates/pager_config.rb +10 -0
  75. data/lib/generators/pager/views_generator.rb +118 -0
  76. data/spec/config/config_spec.rb +91 -0
  77. data/spec/fake_app/active_record/config.rb +3 -0
  78. data/spec/fake_app/active_record/models.rb +57 -0
  79. data/spec/fake_app/data_mapper/config.rb +7 -0
  80. data/spec/fake_app/data_mapper/models.rb +27 -0
  81. data/spec/fake_app/log/development.log +832 -0
  82. data/spec/fake_app/mongo_mapper/config.rb +2 -0
  83. data/spec/fake_app/mongo_mapper/models.rb +9 -0
  84. data/spec/fake_app/mongoid/config.rb +16 -0
  85. data/spec/fake_app/mongoid/models.rb +22 -0
  86. data/spec/fake_app/rails_app.rb +67 -0
  87. data/spec/fake_app/sinatra_app.rb +22 -0
  88. data/spec/fake_gem.rb +4 -0
  89. data/spec/helpers/action_view_extension_spec.rb +292 -0
  90. data/spec/helpers/helpers_spec.rb +135 -0
  91. data/spec/helpers/sinatra_helpers_spec.rb +170 -0
  92. data/spec/helpers/tags_spec.rb +140 -0
  93. data/spec/models/active_record/active_record_relation_methods_spec.rb +47 -0
  94. data/spec/models/active_record/default_per_page_spec.rb +32 -0
  95. data/spec/models/active_record/max_pages_spec.rb +23 -0
  96. data/spec/models/active_record/max_per_page_spec.rb +32 -0
  97. data/spec/models/active_record/scopes_spec.rb +242 -0
  98. data/spec/models/array_spec.rb +150 -0
  99. data/spec/models/data_mapper/data_mapper_spec.rb +207 -0
  100. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +84 -0
  101. data/spec/models/mongoid/mongoid_spec.rb +126 -0
  102. data/spec/requests/users_spec.rb +53 -0
  103. data/spec/spec_helper.rb +33 -0
  104. data/spec/spec_helper_for_sinatra.rb +34 -0
  105. data/spec/support/database_cleaner.rb +16 -0
  106. data/spec/support/matchers.rb +52 -0
  107. data/vendor/assets/javascripts/jquery.infinitescroll.js +814 -0
  108. data/vendor/assets/javascripts/jquery.infinitescroll.min.js +1 -0
  109. metadata +311 -0
@@ -0,0 +1,9 @@
1
+ -# Link to the "Next" page
2
+ -# available local variables
3
+ -# url: url to the next page
4
+ -# current_page: a page object for the currently displayed page
5
+ -# total_pages: total number of pages
6
+ -# per_page: number of items to fetch per page
7
+ -# remote: data-remote
8
+ %li.next
9
+ = link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, :rel => 'next', :remote => remote
@@ -0,0 +1,10 @@
1
+ / Link to the "Next" page
2
+ - available local variables
3
+ url : url to the next page
4
+ current_page : a page object for the currently displayed page
5
+ total_pages : total number of pages
6
+ per_page : number of items to fetch per page
7
+ remote : data-remote
8
+ li.next
9
+ == link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, :rel => 'next', :remote => remote
10
+ '
@@ -0,0 +1,14 @@
1
+ <%# Link showing page number
2
+ - available local variables
3
+ page: a page object for "this" page
4
+ url: url to this page
5
+ current_page: a page object for the currently displayed page
6
+ total_pages: total number of pages
7
+ per_page: number of items to fetch per page
8
+ remote: data-remote
9
+ -%>
10
+ <li class="page<%= ' active' if page.current? %>">
11
+ <%= link_to_unless page.current?, page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} do |name| %>
12
+ <span><%= name %></span>
13
+ <% end %>
14
+ </li>
@@ -0,0 +1,11 @@
1
+ -# Link showing page number
2
+ -# available local variables
3
+ -# page: a page object for "this" page
4
+ -# url: url to this page
5
+ -# current_page: a page object for the currently displayed page
6
+ -# total_pages: total number of pages
7
+ -# per_page: number of items to fetch per page
8
+ -# remote: data-remote
9
+ %li{:class => "page#{' active' if page.current?}"}
10
+ = link_to_unless page.current?, page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} do |name|
11
+ %span= name
@@ -0,0 +1,13 @@
1
+ / Link showing page number
2
+ - available local variables
3
+ page : a page object for "this" page
4
+ url : url to this page
5
+ current_page : a page object for the currently displayed page
6
+ total_pages : total number of pages
7
+ per_page : number of items to fetch per page
8
+ remote : data-remote
9
+ li class="page#{' active' if page.current?}"
10
+ == link_to_unless page.current?, page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} do |name|
11
+ span
12
+ == name
13
+ '
@@ -0,0 +1,25 @@
1
+ <%# The container tag
2
+ - available local variables
3
+ current_page: a page object for the currently displayed page
4
+ total_pages: total number of pages
5
+ per_page: number of items to fetch per page
6
+ remote: data-remote
7
+ paginator: the paginator that renders the pagination tags inside
8
+ -%>
9
+ <%= paginator.render do -%>
10
+ <nav class="pagination">
11
+ <ul>
12
+ <%= first_page_tag unless current_page.first? %>
13
+ <%= prev_page_tag unless current_page.first? %>
14
+ <% each_page do |page| -%>
15
+ <% if page.left_outer? || page.right_outer? || page.inside_window? -%>
16
+ <%= page_tag page %>
17
+ <% elsif !page.was_truncated? -%>
18
+ <%= gap_tag %>
19
+ <% end -%>
20
+ <% end -%>
21
+ <%= next_page_tag unless current_page.last? %>
22
+ <%= last_page_tag unless current_page.last? %>
23
+ </ul>
24
+ </nav>
25
+ <% end -%>
@@ -0,0 +1,19 @@
1
+ -# The container tag
2
+ -# available local variables
3
+ -# current_page: a page object for the currently displayed page
4
+ -# total_pages: total number of pages
5
+ -# per_page: number of items to fetch per page
6
+ -# remote: data-remote
7
+ -# paginator: the paginator that renders the pagination tags inside
8
+ = paginator.render do
9
+ %nav.pagination
10
+ %ul
11
+ = first_page_tag unless current_page.first?
12
+ = prev_page_tag unless current_page.first?
13
+ - each_page do |page|
14
+ - if page.left_outer? || page.right_outer? || page.inside_window?
15
+ = page_tag page
16
+ - elsif !page.was_truncated?
17
+ = gap_tag
18
+ = next_page_tag unless current_page.last?
19
+ = last_page_tag unless current_page.last?
@@ -0,0 +1,20 @@
1
+ / The container tag
2
+ - available local variables
3
+ current_page : a page object for the currently displayed page
4
+ total_pages : total number of pages
5
+ per_page : number of items to fetch per page
6
+ remote : data-remote
7
+ paginator : the paginator that renders the pagination tags inside
8
+
9
+ == paginator.render do
10
+ nav.pagination
11
+ ul
12
+ == first_page_tag unless current_page.first?
13
+ == prev_page_tag unless current_page.first?
14
+ - each_page do |page|
15
+ - if page.left_outer? || page.right_outer? || page.inside_window?
16
+ == page_tag page
17
+ - elsif !page.was_truncated?
18
+ == gap_tag
19
+ == next_page_tag unless current_page.last?
20
+ == last_page_tag unless current_page.last?
@@ -0,0 +1,11 @@
1
+ <%# Link to the "Previous" page
2
+ - available local variables
3
+ url: url to the previous page
4
+ current_page: a page object for the currently displayed page
5
+ total_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <li class="prev">
10
+ <%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, :rel => 'prev', :remote => remote %>
11
+ </li>
@@ -0,0 +1,9 @@
1
+ -# Link to the "Previous" page
2
+ -# available local variables
3
+ -# url: url to the previous page
4
+ -# current_page: a page object for the currently displayed page
5
+ -# total_pages: total number of pages
6
+ -# per_page: number of items to fetch per page
7
+ -# remote: data-remote
8
+ %li.prev
9
+ = link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, :rel => 'prev', :remote => remote
@@ -0,0 +1,10 @@
1
+ / Link to the "Previous" page
2
+ - available local variables
3
+ url : url to the previous page
4
+ current_page : a page object for the currently displayed page
5
+ total_pages : total number of pages
6
+ per_page : number of items to fetch per page
7
+ remote : data-remote
8
+ li.prev
9
+ == link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, :rel => 'prev', :remote => remote
10
+ '
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bootstrap_pager/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'bootstrap_pager'
7
+ s.version = BootstrapPager::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Karen Lundgren']
10
+ s.email = ['webmaster@sourcherryweb.com']
11
+ s.homepage = 'https://github.com/nerakdon/bootstrap_pager'
12
+ s.summary = 'A pagination engine plugin for Rails 3+ or other modern frameworks. Now with more shiny, including infinite paging, bootstrap integration, and the ability to use it within an engine.'
13
+ s.description = 'Like its ancestor Kaminari, BootstrapPager is a Scope & Engine based, clean, powerful, agnostic, customizable and sophisticated paginator for Rails 3+. Now with more shiny, including infinite paging, bootstrap integration, and the ability to use it within an engine. '
14
+
15
+ s.rubyforge_project = 'bootstrap_pager'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.extra_rdoc_files = ['README.rdoc']
20
+ s.require_paths = ['lib']
21
+
22
+ s.licenses = ['MIT']
23
+
24
+ s.add_dependency 'activesupport', ['>= 3.0.0']
25
+ s.add_dependency 'actionpack', ['>= 3.0.0']
26
+
27
+ s.add_development_dependency 'bundler', ['>= 1.0.0']
28
+ s.add_development_dependency 'rake', ['>= 0']
29
+ s.add_development_dependency 'sqlite3', ['>= 0']
30
+ s.add_development_dependency 'tzinfo', ['>= 0']
31
+ s.add_development_dependency 'rspec', ['>= 0']
32
+ s.add_development_dependency 'rr', ['>= 0']
33
+ s.add_development_dependency 'capybara', ['>= 1.0']
34
+ s.add_development_dependency 'database_cleaner', ['>= 0']
35
+ s.add_development_dependency 'rdoc', ['>= 0']
36
+ end
@@ -0,0 +1,19 @@
1
+ # Sample localization file for BootstrapPager. You can override these values in your app's locales file if you want.
2
+
3
+ en:
4
+ views:
5
+ pagination:
6
+ first: "&laquo; First"
7
+ last: "Last &raquo;"
8
+ previous: "&lsaquo; Prev"
9
+ next: "Next &rsaquo;"
10
+ truncate: "&hellip;"
11
+ helpers:
12
+ page_entries_info:
13
+ one_page:
14
+ display_entries:
15
+ zero: "No %{entry_name} found"
16
+ one: "Displaying <b>1</b> %{entry_name}"
17
+ other: "Displaying <b>all %{count}</b> %{entry_name}"
18
+ more_pages:
19
+ display_entries: "Displaying %{entry_name} <b>%{first}&nbsp;-&nbsp;%{last}</b> of <b>%{total}</b> in total"
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '~> 3.0.20'
4
+ gem 'activerecord', '~> 3.0.20', :require => 'active_record'
5
+ gem 'rspec-rails', '>= 2.0'
6
+ gem 'nokogiri', '< 1.6'
7
+ gem 'capybara', '< 2.1'
8
+
9
+ gemspec :path => '../'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '~> 3.1.12'
4
+ gem 'activerecord', '~> 3.1.12', :require => 'active_record'
5
+ gem 'rspec-rails', '>= 2.0'
6
+
7
+ gemspec :path => '../'
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '~> 3.2.3'
4
+ gem 'activerecord', '~> 3.2.3', :require => 'active_record'
5
+ gem 'rspec-rails', '>= 2.0'
6
+ gem 'nokogiri'
7
+ gem 'xpath'
8
+ gem 'mime-types'
9
+
10
+ gemspec :path => '../'
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '>= 4.0.0'
4
+ gem 'activerecord', '>= 4.0.0', :require => 'active_record'
5
+ gem 'rspec-rails', '>= 2.0'
6
+ gem 'database_cleaner', '>= 1.0.1'
7
+
8
+ gemspec :path => '../'
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git 'https://github.com/rails/rails.git' do
4
+ gem 'railties'
5
+ gem 'activerecord', :require => 'active_record'
6
+ end
7
+
8
+ gem 'rspec-rails', '>= 2.0'
9
+ gem 'database_cleaner', '>= 1.0.1'
10
+
11
+ gemspec :path => '../'
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '>= 3.2.3'
4
+ gem 'dm-core', '~> 1.2.0'
5
+ gem 'dm-migrations', '~> 1.2.0'
6
+ gem 'dm-aggregates', '~> 1.2.0'
7
+ gem 'dm-transactions', '~> 1.2.0'
8
+ gem 'dm-active_model', '~> 1.2.1'
9
+ gem 'dm-sqlite-adapter', '~> 1.2.0'
10
+ gem 'rspec-rails', '>= 2.0'
11
+ gem 'nokogiri'
12
+ gem 'xpath'
13
+ gem 'mime-types'
14
+
15
+ gemspec :path => '../'
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '>= 3.2.3'
4
+ gem 'mongo_mapper', '>= 0.11.0'
5
+ gem 'rspec-rails', '>= 2.0'
6
+ gem 'nokogiri'
7
+ gem 'xpath'
8
+ gem 'mime-types'
9
+
10
+ gemspec :path => '../'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '>= 3.2.3'
4
+ gem 'mongoid', '~> 2.4.0'
5
+ gem 'rspec-rails', '>= 2.0'
6
+
7
+ gemspec :path => '../'
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '>= 3.2.3'
4
+ gem 'mongoid', '>= 3.0'
5
+ gem 'rspec-rails', '>= 2.0'
6
+ gem 'origin'
7
+ gem 'moped'
8
+ gem 'nokogiri'
9
+ gem 'xpath'
10
+ gem 'mime-types'
11
+
12
+ gemspec :path => '../'
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 3.2.3', :require => 'active_record'
4
+ gem 'sinatra', '~> 1.3.0'
5
+ gem 'tilt', '~> 1.3.0'
6
+ gem 'padrino-helpers', '~> 0.10.6'
7
+ gem 'rack-test', '>= 0'
8
+ gem 'sinatra-contrib', '~> 1.3.0'
9
+ gem 'nokogiri'
10
+ gem 'xpath'
11
+ gem 'mime-types'
12
+
13
+ gemspec :path => '../'
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 3.2.0', :require => 'active_record'
4
+ gem 'sinatra', '~> 1.4.0'
5
+ gem 'tilt', '~> 1.3.0'
6
+ gem 'padrino-helpers', '~> 0.11.3'
7
+ gem 'rack-test', '>= 0'
8
+ gem 'sinatra-contrib', '~> 1.4.0'
9
+ gem 'nokogiri'
10
+ gem 'xpath'
11
+ gem 'mime-types'
12
+
13
+ gemspec :path => '../'
@@ -0,0 +1,51 @@
1
+ require 'active_support/configurable'
2
+
3
+ module BootstrapPager
4
+ # Configures global settings for BootstrapPager
5
+ # BootstrapPager.configure do |config|
6
+ # config.default_per_page = 10
7
+ # end
8
+ def self.configure(&block)
9
+ yield @config ||= BootstrapPager::Configuration.new
10
+ end
11
+
12
+ # Global settings for BootstrapPager
13
+ def self.config
14
+ @config
15
+ end
16
+
17
+ # need a Class for 3.0
18
+ class Configuration #:nodoc:
19
+ include ActiveSupport::Configurable
20
+ config_accessor :default_per_page
21
+ config_accessor :max_per_page
22
+ config_accessor :window
23
+ config_accessor :outer_window
24
+ config_accessor :left
25
+ config_accessor :right
26
+ config_accessor :page_method_name
27
+ config_accessor :max_pages
28
+
29
+ def param_name
30
+ config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
31
+ end
32
+
33
+ # define param_name writer (copied from AS::Configurable)
34
+ writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
35
+ singleton_class.class_eval writer, __FILE__, line
36
+ class_eval writer, __FILE__, line
37
+ end
38
+
39
+ # this is ugly. why can't we pass the default value to config_accessor...?
40
+ configure do |config|
41
+ config.default_per_page = 25
42
+ config.max_per_page = nil
43
+ config.window = 4
44
+ config.outer_window = 0
45
+ config.left = 0
46
+ config.right = 0
47
+ config.page_method_name = :page
48
+ config.param_name = :page
49
+ config.max_pages = nil
50
+ end
51
+ end
@@ -0,0 +1,4 @@
1
+ require 'grape'
2
+ require 'bootstrap_pager'
3
+
4
+ BootstrapPager::Hooks.init
@@ -0,0 +1,152 @@
1
+ module BootstrapPager
2
+ # = Helpers
3
+ module ActionViewExtension
4
+ # A helper that renders the pagination links.
5
+ #
6
+ # <%= paginate @articles %>
7
+ #
8
+ # ==== Options
9
+ # * <tt>:window</tt> - The "inner window" size (4 by default).
10
+ # * <tt>:outer_window</tt> - The "outer window" size (0 by default).
11
+ # * <tt>:left</tt> - The "left outer window" size (0 by default).
12
+ # * <tt>:right</tt> - The "right outer window" size (0 by default).
13
+ # * <tt>:params</tt> - url_for parameters for the links (:controller, :action, etc.)
14
+ # * <tt>:param_name</tt> - parameter name for page number in the links (:page by default)
15
+ # * <tt>:remote</tt> - Ajax? (false by default)
16
+ # * <tt>:engine_namespace</tt> - namespace of router (current engine's namespace by default)
17
+ # * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
18
+ def paginate(scope, options = {}, &block)
19
+ paginator = BootstrapPager::Helpers::Paginator.new self, options.reverse_merge(:current_page => scope.current_page, :total_pages => scope.total_pages, :per_page => scope.limit_value, :param_name => BootstrapPager.config.param_name, :remote => false)
20
+ paginator.to_s
21
+ end
22
+
23
+ # A simple "Twitter like" pagination link that creates a link to the previous page.
24
+ #
25
+ # ==== Examples
26
+ # Basic usage:
27
+ #
28
+ # <%= link_to_previous_page @items, 'Previous Page' %>
29
+ #
30
+ # Ajax:
31
+ #
32
+ # <%= link_to_previous_page @items, 'Previous Page', :remote => true %>
33
+ #
34
+ # By default, it renders nothing if there are no more results on the previous page.
35
+ # You can customize this output by passing a block.
36
+ #
37
+ # <%= link_to_previous_page @users, 'Previous Page' do %>
38
+ # <span>At the Beginning</span>
39
+ # <% end %>
40
+ def link_to_previous_page(scope, name, options = {}, &block)
41
+ params = options.delete(:params) || {}
42
+ param_name = options.delete(:param_name) || BootstrapPager.config.param_name
43
+ engine_namespace = options.delete(:engine_namespace)
44
+ url = (engine_namespace || self).url_for params.merge(param_name => (scope.current_page - 1))
45
+ link_to_unless scope.first_page?, name, url, options.reverse_merge(:rel => 'previous') do
46
+ block.call if block
47
+ end
48
+ end
49
+
50
+ # A simple "Twitter like" pagination link that creates a link to the next page.
51
+ #
52
+ # ==== Examples
53
+ # Basic usage:
54
+ #
55
+ # <%= link_to_next_page @items, 'Next Page' %>
56
+ #
57
+ # Ajax:
58
+ #
59
+ # <%= link_to_next_page @items, 'Next Page', :remote => true %>
60
+ #
61
+ # By default, it renders nothing if there are no more results on the next page.
62
+ # You can customize this output by passing a block.
63
+ #
64
+ # <%= link_to_next_page @users, 'Next Page' do %>
65
+ # <span>No More Pages</span>
66
+ # <% end %>
67
+ def link_to_next_page(scope, name, options = {}, &block)
68
+ params = options.delete(:params) || {}
69
+ param_name = options.delete(:param_name) || BootstrapPager.config.param_name
70
+ engine_namespace = options.delete(:engine_namespace)
71
+ url = (engine_namespace || self).url_for params.merge(param_name => (scope.current_page + 1))
72
+ link_to_unless scope.last_page?, name, url, options.reverse_merge(:rel => 'next') do
73
+ block.call if block
74
+ end
75
+ end
76
+
77
+ # Renders a helpful message with numbers of displayed vs. total entries.
78
+ # Ported from mislav/will_paginate
79
+ #
80
+ # ==== Examples
81
+ # Basic usage:
82
+ #
83
+ # <%= page_entries_info @posts %>
84
+ # #-> Displaying posts 6 - 10 of 26 in total
85
+ #
86
+ # By default, the message will use the humanized class name of objects
87
+ # in collection: for instance, "project types" for ProjectType models.
88
+ # The namespace will be cutted out and only the last name will be used.
89
+ # Override this with the <tt>:entry_name</tt> parameter:
90
+ #
91
+ # <%= page_entries_info @posts, :entry_name => 'item' %>
92
+ # #-> Displaying items 6 - 10 of 26 in total
93
+ def page_entries_info(collection, options = {})
94
+ entry_name = if options[:entry_name]
95
+ options[:entry_name]
96
+ elsif collection.is_a?(::BootstrapPager::PaginatableArray)
97
+ 'entry'
98
+ else
99
+ if collection.respond_to? :model # DataMapper
100
+ collection.model.model_name.human.downcase
101
+ else # AR
102
+ collection.model_name.human.downcase
103
+ end
104
+ end
105
+ entry_name = entry_name.pluralize unless collection.total_count == 1
106
+
107
+ if collection.total_pages < 2
108
+ t('helpers.page_entries_info.one_page.display_entries', :entry_name => entry_name, :count => collection.total_count)
109
+ else
110
+ first = collection.offset_value + 1
111
+ last = collection.last_page? ? collection.total_count : collection.offset_value + collection.limit_value
112
+ t('helpers.page_entries_info.more_pages.display_entries', :entry_name => entry_name, :first => first, :last => last, :total => collection.total_count)
113
+ end.html_safe
114
+ end
115
+
116
+ # Renders rel="next" and rel="prev" links to be used in the head.
117
+ #
118
+ # ==== Examples
119
+ # Basic usage:
120
+ #
121
+ # In head:
122
+ # <head>
123
+ # <title>My Website</title>
124
+ # <%= yield :head %>
125
+ # </head>
126
+ #
127
+ # Somewhere in body:
128
+ # <% content_for :head do %>
129
+ # <%= rel_next_prev_link_tags @items %>
130
+ # <% end %>
131
+ #
132
+ # #-> <link rel="next" href="/items/page/3" /><link rel="prev" href="/items/page/1" />
133
+ #
134
+ def rel_next_prev_link_tags(scope, options = {})
135
+ params = options.delete(:params) || {}
136
+ param_name = options.delete(:param_name) || BootstrapPager.config.param_name
137
+ engine_namespace = options.delete(:engine_namespace)
138
+
139
+ output = ""
140
+
141
+ unless scope.last_page?
142
+ output << '<link rel="next" href="' + (engine_namespace || self).url_for(params.merge(param_name => (scope.current_page + 1))) + '"/>'
143
+ end
144
+ unless scope.first_page?
145
+ output << '<link rel="prev" href="' + (engine_namespace || self).url_for(params.merge(param_name => (scope.current_page - 1))) + '"/>'
146
+ end
147
+
148
+ output.html_safe
149
+ end
150
+
151
+ end
152
+ end