kaminari 0.17.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +19 -0
  3. data/.github/workflows/main.yml +107 -0
  4. data/.gitignore +2 -1
  5. data/CHANGELOG.md +650 -0
  6. data/CONTRIBUTING.md +22 -0
  7. data/Gemfile +2 -0
  8. data/README.md +588 -0
  9. data/Rakefile +25 -25
  10. data/gemfiles/active_record_41.gemfile +17 -12
  11. data/gemfiles/active_record_42.gemfile +17 -12
  12. data/gemfiles/active_record_50.gemfile +26 -0
  13. data/gemfiles/active_record_51.gemfile +26 -0
  14. data/gemfiles/active_record_52.gemfile +26 -0
  15. data/gemfiles/active_record_60.gemfile +28 -0
  16. data/gemfiles/active_record_61.gemfile +28 -0
  17. data/gemfiles/active_record_70.gemfile +28 -0
  18. data/gemfiles/active_record_edge.gemfile +22 -17
  19. data/kaminari.gemspec +23 -27
  20. data/lib/kaminari/version.rb +3 -1
  21. data/lib/kaminari.rb +4 -38
  22. data/misc/bug_report_template.rb +57 -0
  23. metadata +54 -190
  24. data/.gemtest +0 -0
  25. data/.rspec +0 -2
  26. data/.travis.yml +0 -64
  27. data/CHANGELOG.rdoc +0 -480
  28. data/README.rdoc +0 -336
  29. data/app/views/kaminari/_first_page.html.erb +0 -11
  30. data/app/views/kaminari/_first_page.html.haml +0 -9
  31. data/app/views/kaminari/_first_page.html.slim +0 -10
  32. data/app/views/kaminari/_gap.html.erb +0 -8
  33. data/app/views/kaminari/_gap.html.haml +0 -8
  34. data/app/views/kaminari/_gap.html.slim +0 -9
  35. data/app/views/kaminari/_last_page.html.erb +0 -11
  36. data/app/views/kaminari/_last_page.html.haml +0 -9
  37. data/app/views/kaminari/_last_page.html.slim +0 -10
  38. data/app/views/kaminari/_next_page.html.erb +0 -11
  39. data/app/views/kaminari/_next_page.html.haml +0 -9
  40. data/app/views/kaminari/_next_page.html.slim +0 -10
  41. data/app/views/kaminari/_page.html.erb +0 -12
  42. data/app/views/kaminari/_page.html.haml +0 -10
  43. data/app/views/kaminari/_page.html.slim +0 -11
  44. data/app/views/kaminari/_paginator.html.erb +0 -23
  45. data/app/views/kaminari/_paginator.html.haml +0 -18
  46. data/app/views/kaminari/_paginator.html.slim +0 -19
  47. data/app/views/kaminari/_prev_page.html.erb +0 -11
  48. data/app/views/kaminari/_prev_page.html.haml +0 -9
  49. data/app/views/kaminari/_prev_page.html.slim +0 -10
  50. data/config/locales/kaminari.yml +0 -19
  51. data/gemfiles/active_record_30.gemfile +0 -28
  52. data/gemfiles/active_record_31.gemfile +0 -26
  53. data/gemfiles/active_record_32.gemfile +0 -25
  54. data/gemfiles/active_record_40.gemfile +0 -26
  55. data/gemfiles/data_mapper_12.gemfile +0 -32
  56. data/gemfiles/mongo_mapper.gemfile +0 -25
  57. data/gemfiles/mongoid_30.gemfile +0 -22
  58. data/gemfiles/mongoid_31.gemfile +0 -21
  59. data/gemfiles/mongoid_40.gemfile +0 -19
  60. data/gemfiles/mongoid_50.gemfile +0 -23
  61. data/gemfiles/sinatra_13.gemfile +0 -36
  62. data/gemfiles/sinatra_14.gemfile +0 -33
  63. data/lib/generators/kaminari/config_generator.rb +0 -16
  64. data/lib/generators/kaminari/templates/kaminari_config.rb +0 -10
  65. data/lib/generators/kaminari/views_generator.rb +0 -119
  66. data/lib/kaminari/config.rb +0 -51
  67. data/lib/kaminari/engine.rb +0 -4
  68. data/lib/kaminari/grape.rb +0 -4
  69. data/lib/kaminari/helpers/action_view_extension.rb +0 -132
  70. data/lib/kaminari/helpers/paginator.rb +0 -195
  71. data/lib/kaminari/helpers/sinatra_helpers.rb +0 -176
  72. data/lib/kaminari/helpers/tags.rb +0 -108
  73. data/lib/kaminari/hooks.rb +0 -53
  74. data/lib/kaminari/models/active_record_extension.rb +0 -22
  75. data/lib/kaminari/models/active_record_model_extension.rb +0 -22
  76. data/lib/kaminari/models/active_record_relation_methods.rb +0 -42
  77. data/lib/kaminari/models/array_extension.rb +0 -66
  78. data/lib/kaminari/models/configuration_methods.rb +0 -48
  79. data/lib/kaminari/models/data_mapper_collection_methods.rb +0 -19
  80. data/lib/kaminari/models/data_mapper_extension.rb +0 -51
  81. data/lib/kaminari/models/mongo_mapper_extension.rb +0 -18
  82. data/lib/kaminari/models/mongoid_criteria_methods.rb +0 -40
  83. data/lib/kaminari/models/mongoid_extension.rb +0 -26
  84. data/lib/kaminari/models/page_scope_methods.rb +0 -73
  85. data/lib/kaminari/models/plucky_criteria_methods.rb +0 -23
  86. data/lib/kaminari/railtie.rb +0 -7
  87. data/lib/kaminari/sinatra.rb +0 -7
  88. data/spec/config/config_spec.rb +0 -91
  89. data/spec/fake_app/active_record/config.rb +0 -3
  90. data/spec/fake_app/active_record/models.rb +0 -65
  91. data/spec/fake_app/data_mapper/config.rb +0 -1
  92. data/spec/fake_app/data_mapper/models.rb +0 -27
  93. data/spec/fake_app/mongo_mapper/config.rb +0 -2
  94. data/spec/fake_app/mongo_mapper/models.rb +0 -9
  95. data/spec/fake_app/mongoid/config.rb +0 -20
  96. data/spec/fake_app/mongoid/models.rb +0 -38
  97. data/spec/fake_app/rails_app.rb +0 -56
  98. data/spec/fake_app/sinatra_app.rb +0 -22
  99. data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +0 -1
  100. data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +0 -3
  101. data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +0 -1
  102. data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +0 -7
  103. data/spec/fake_gem.rb +0 -20
  104. data/spec/generators/views_generator_spec.rb +0 -18
  105. data/spec/helpers/action_view_extension_spec.rb +0 -318
  106. data/spec/helpers/helpers_spec.rb +0 -144
  107. data/spec/helpers/sinatra_helpers_spec.rb +0 -223
  108. data/spec/helpers/tags_spec.rb +0 -140
  109. data/spec/models/active_record/active_record_relation_methods_spec.rb +0 -77
  110. data/spec/models/active_record/inherited_spec.rb +0 -9
  111. data/spec/models/active_record/scopes_spec.rb +0 -265
  112. data/spec/models/array_spec.rb +0 -172
  113. data/spec/models/configuration_methods_spec.rb +0 -125
  114. data/spec/models/data_mapper/data_mapper_spec.rb +0 -205
  115. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +0 -84
  116. data/spec/models/mongoid/mongoid_spec.rb +0 -228
  117. data/spec/requests/users_spec.rb +0 -53
  118. data/spec/spec_helper.rb +0 -34
  119. data/spec/spec_helper_for_sinatra.rb +0 -34
  120. data/spec/support/database_cleaner.rb +0 -19
  121. data/spec/support/matchers.rb +0 -52
@@ -1,26 +0,0 @@
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.14.1'
6
-
7
- gem 'mime-types', '2.99' if RUBY_VERSION < '2.0.0'
8
-
9
- platforms :ruby do
10
- if RUBY_VERSION > "2.1.0"
11
- gem 'sqlite3'
12
- else
13
- gem 'sqlite3', '1.3.8'
14
- end
15
- end
16
- platforms :jruby do
17
- gem 'activerecord-jdbcsqlite3-adapter', '>= 1.3.0'
18
- end
19
- platforms :rbx do
20
- gem 'rubysl', '~> 2.0'
21
- gem 'racc'
22
- gem 'rubysl-test-unit'
23
- gem 'rubinius-developer_tools'
24
- end
25
-
26
- gemspec :path => '../'
@@ -1,25 +0,0 @@
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.14.1'
6
- gem 'mime-types', '2.99' if RUBY_VERSION < '2.0.0'
7
-
8
- platforms :ruby do
9
- if RUBY_VERSION > "2.1.0"
10
- gem 'sqlite3'
11
- else
12
- gem 'sqlite3', '1.3.8'
13
- end
14
- end
15
- platforms :jruby do
16
- gem 'activerecord-jdbcsqlite3-adapter', '>= 1.3.0'
17
- end
18
- platforms :rbx do
19
- gem 'rubysl', '~> 2.0'
20
- gem 'racc'
21
- gem 'rubysl-test-unit'
22
- gem 'rubinius-developer_tools'
23
- end
24
-
25
- gemspec :path => '../'
@@ -1,26 +0,0 @@
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.14.1'
6
- gem 'mime-types', '2.99' if RUBY_VERSION == '1.9.3'
7
-
8
- platforms :ruby do
9
- if RUBY_VERSION > "2.1.0"
10
- gem 'sqlite3'
11
- gem 'test-unit'
12
- else
13
- gem 'sqlite3', '1.3.8'
14
- end
15
- end
16
- platforms :jruby do
17
- gem 'activerecord-jdbcsqlite3-adapter', '>= 1.3.0'
18
- end
19
- platforms :rbx do
20
- gem 'rubysl', '~> 2.0'
21
- gem 'racc'
22
- gem 'rubysl-test-unit'
23
- gem 'rubinius-developer_tools'
24
- end
25
-
26
- gemspec :path => '../'
@@ -1,32 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'railties', '~> 3.2.21'
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.14.1'
11
-
12
- gem 'mime-types', '2.99' if RUBY_VERSION < '2.0.0'
13
-
14
- platforms :ruby do
15
- if RUBY_VERSION > "2.1.0"
16
- gem 'sqlite3'
17
- gem 'test-unit'
18
- else
19
- gem 'sqlite3', '1.3.8'
20
- end
21
- end
22
- platforms :jruby do
23
- gem 'activerecord-jdbcsqlite3-adapter', '~> 1.2.0'
24
- end
25
- platforms :rbx do
26
- gem 'rubysl', '~> 2.0'
27
- gem 'racc'
28
- gem 'rubysl-test-unit'
29
- gem 'rubinius-developer_tools'
30
- end
31
-
32
- gemspec :path => '../'
@@ -1,25 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'railties', '>= 3.2.3'
4
- gem 'bson', '~> 1.9.2'
5
- gem 'mongo_mapper', '>= 0.11.0'
6
- gem 'rspec-rails', '~> 2.14.1'
7
-
8
- gem 'capybara'
9
- gem 'nokogiri'
10
- gem 'rubyzip'
11
-
12
- if RUBY_VERSION == '1.9.3'
13
- gem 'mime-types', '2.99'
14
- else
15
- gem 'mime-types'
16
- end
17
-
18
- platforms :rbx do
19
- gem 'rubysl', '~> 2.0'
20
- gem 'racc'
21
- gem 'minitest'
22
- gem 'rubinius-developer_tools'
23
- end
24
-
25
- gemspec :path => '../'
@@ -1,22 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'railties', '>= 3.2.3'
4
- gem 'mongoid', '~> 3.0.0'
5
- gem 'rspec-rails', '~> 2.14.1'
6
- gem 'origin'
7
- gem 'moped'
8
- gem 'activesupport', '~> 3.2.18'
9
- gem 'mime-types', '2.99' if RUBY_VERSION == '1.9.3'
10
-
11
- platforms :mri do
12
- gem 'test-unit' if RUBY_VERSION > "2.1.0"
13
- end
14
-
15
- platforms :rbx do
16
- gem 'rubysl', '~> 2.0'
17
- gem 'racc'
18
- gem 'rubysl-test-unit'
19
- gem 'rubinius-developer_tools'
20
- end
21
-
22
- gemspec :path => '../'
@@ -1,21 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'railties', '~> 3.2'
4
- gem 'mongoid', '~> 3.1.0'
5
- gem 'rspec-rails', '~> 2.14.1'
6
- gem 'origin'
7
- gem 'moped'
8
- gem 'mime-types', '2.99' if RUBY_VERSION == '1.9.3'
9
-
10
- platforms :mri do
11
- gem 'test-unit' if RUBY_VERSION > "2.1.0"
12
- end
13
-
14
- platforms :rbx do
15
- gem 'rubysl', '~> 2.0'
16
- gem 'racc'
17
- gem 'rubysl-test-unit'
18
- gem 'rubinius-developer_tools'
19
- end
20
-
21
- gemspec :path => '../'
@@ -1,19 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'railties', '~> 4.0'
4
- gem "mongoid", "~> 4.0.0.beta2"
5
- gem 'rspec-rails', '~> 2.14.1'
6
- gem 'mime-types', '2.99' if RUBY_VERSION == '1.9.3'
7
-
8
- platforms :mri do
9
- gem 'test-unit' if RUBY_VERSION > "2.1.0"
10
- end
11
-
12
- platforms :rbx do
13
- gem 'rubysl', '~> 2.0'
14
- gem 'racc'
15
- gem 'minitest'
16
- gem 'rubinius-developer_tools'
17
- end
18
-
19
- gemspec :path => '../'
@@ -1,23 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'railties', '~> 4.0'
4
- gem 'mongoid', '~> 5.0.0'
5
- gem 'rspec-rails', '~> 2.14.1'
6
- gem 'mime-types', '2.99' if RUBY_VERSION == '1.9.3'
7
-
8
- group :development, :test do
9
- gem 'database_cleaner', '~> 1.5.1'
10
- end
11
-
12
- platforms :mri do
13
- gem 'test-unit' if RUBY_VERSION > '2.1.0'
14
- end
15
-
16
- platforms :rbx do
17
- gem 'rubysl', '~> 2.0'
18
- gem 'racc'
19
- gem 'minitest'
20
- gem 'rubinius-developer_tools'
21
- end
22
-
23
- gemspec :path => '../'
@@ -1,36 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'sinatra', '~> 1.3.0'
4
- gem 'tilt'
5
-
6
- if RUBY_VERSION >= "2.2.0"
7
- gem 'activerecord', '>= 4.0.0', :require => 'active_record'
8
- gem 'padrino-helpers'
9
- else
10
- gem 'activerecord', '~> 3.2.3', :require => 'active_record'
11
- gem 'padrino-helpers', '~> 0.10.6'
12
- end
13
-
14
- gem 'rack-test'
15
- gem 'sinatra-contrib'
16
- gem 'rspec', '~> 2.14.1'
17
- gem 'mime-types', '2.99' if RUBY_VERSION == '1.9.3'
18
-
19
- platforms :ruby do
20
- if RUBY_VERSION > "2.1.0"
21
- gem 'sqlite3'
22
- else
23
- gem 'sqlite3', '1.3.8'
24
- end
25
- end
26
- platforms :jruby do
27
- gem 'activerecord-jdbcsqlite3-adapter', '>= 1.3.0'
28
- end
29
- platforms :rbx do
30
- gem 'rubysl', '~> 2.0'
31
- gem 'racc'
32
- gem 'rubysl-test-unit'
33
- gem 'rubinius-developer_tools'
34
- end
35
-
36
- gemspec :path => '../'
@@ -1,33 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'sinatra', '~> 1.4.0'
4
- gem 'rspec', '~> 2.14.1'
5
-
6
- gem 'activerecord', '>= 4.0.0', :require => 'active_record'
7
- gem 'padrino-helpers', '~> 0.12.0'
8
-
9
- gem 'rack-test', '>= 0'
10
- gem 'sinatra-contrib', '~> 1.4.0'
11
-
12
- if RUBY_VERSION == '1.9.3'
13
- gem 'mime-types', '2.99'
14
- end
15
-
16
- platforms :ruby do
17
- if RUBY_VERSION > "2.1.0"
18
- gem 'sqlite3'
19
- else
20
- gem 'sqlite3', '1.3.8'
21
- end
22
- end
23
- platforms :jruby do
24
- gem 'activerecord-jdbcsqlite3-adapter', '>= 1.3.0'
25
- end
26
- platforms :rbx do
27
- gem 'rubysl', '~> 2.0'
28
- gem 'racc'
29
- gem 'rubysl-test-unit'
30
- gem 'rubinius-developer_tools'
31
- end
32
-
33
- gemspec :path => '../'
@@ -1,16 +0,0 @@
1
- module Kaminari
2
- module Generators
3
- class ConfigGenerator < Rails::Generators::Base
4
- source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
-
6
- desc <<DESC
7
- Description:
8
- Copies Kaminari configuration file to your application's initializer directory.
9
- DESC
10
-
11
- def copy_config_file
12
- template 'kaminari_config.rb', 'config/initializers/kaminari_config.rb'
13
- end
14
- end
15
- end
16
- end
@@ -1,10 +0,0 @@
1
- Kaminari.configure do |config|
2
- # config.default_per_page = 25
3
- # config.max_per_page = nil
4
- # config.window = 4
5
- # config.outer_window = 0
6
- # config.left = 0
7
- # config.right = 0
8
- # config.page_method_name = :page
9
- # config.param_name = :page
10
- end
@@ -1,119 +0,0 @@
1
- module Kaminari
2
- module Generators
3
-
4
- class ViewsGenerator < Rails::Generators::NamedBase
5
- source_root File.expand_path('../../../../app/views/kaminari', __FILE__)
6
-
7
- class_option :template_engine, :type => :string, :aliases => '-e', :desc => 'Template engine for the views. Available options are "erb", "haml", and "slim".'
8
-
9
- def self.banner #:nodoc:
10
- <<-BANNER.chomp
11
- rails g kaminari:views THEME [options]
12
-
13
- Copies all paginator partial templates to your application.
14
- You can choose a template THEME by specifying one from the list below:
15
-
16
- - default
17
- The default one.
18
- This one is used internally while you don't override the partials.
19
- #{themes.map {|t| " - #{t.name}\n#{t.description}"}.join("\n")}
20
- BANNER
21
- end
22
-
23
- desc ''
24
- def copy_or_fetch #:nodoc:
25
- return copy_default_views if file_name == 'default'
26
-
27
- if theme = self.class.themes.detect {|t| t.name == file_name}
28
- if download_templates(theme).empty?
29
- say %Q[template_engine: #{template_engine} is not available for theme: #{file_name}]
30
- end
31
- else
32
- say %Q[no such theme: #{file_name}\n avaliable themes: #{self.class.themes.map(&:name).join ", "}]
33
- end
34
- end
35
-
36
- private
37
- def self.themes
38
- begin
39
- @themes ||= GitHubApiHelper.get_files_in_master.group_by {|fn, _| fn[0...(fn.index('/') || 0)]}.delete_if {|fn, _| fn.blank?}.map do |name, files|
40
- Theme.new name, files
41
- end
42
- rescue SocketError
43
- []
44
- end
45
- end
46
-
47
- def download_templates(theme)
48
- theme.templates_for(template_engine).each do |template|
49
- say " downloading #{template.name} from kaminari_themes..."
50
- create_file template.name, GitHubApiHelper.get_content_for("#{theme.name}/#{template.name}")
51
- end
52
- end
53
-
54
- def copy_default_views
55
- filename_pattern = File.join self.class.source_root, "*.html.#{template_engine}"
56
- Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
57
- copy_file f, "app/views/kaminari/#{f}"
58
- end
59
- end
60
-
61
- def template_engine
62
- options[:template_engine].try(:to_s).try(:downcase) || 'erb'
63
- end
64
- end
65
-
66
- Template = Struct.new(:name, :sha) do
67
- def description?
68
- name == 'DESCRIPTION'
69
- end
70
-
71
- def view?
72
- name =~ /^app\/views\//
73
- end
74
-
75
- def engine #:nodoc:
76
- File.extname(name).sub /^\./, ''
77
- end
78
- end
79
-
80
- class Theme
81
- attr_accessor :name
82
- def initialize(name, templates) #:nodoc:
83
- @name, @templates = name, templates.map {|fn, sha| Template.new fn.sub(/^#{name}\//, ''), sha}
84
- end
85
-
86
- def description #:nodoc:
87
- file = @templates.detect(&:description?)
88
- return "#{' ' * 12}#{name}" unless file
89
- GitHubApiHelper.get_content_for("#{@name}/#{file.name}").chomp.gsub(/^/, ' ' * 12)
90
- end
91
-
92
- def templates_for(template_engine) #:nodoc:
93
- @templates.select {|t| t.engine == template_engine }
94
- end
95
- end
96
-
97
- module GitHubApiHelper
98
- def get_files_in_master
99
- master_tree_sha = open('https://api.github.com/repos/amatsuda/kaminari_themes/git/refs/heads/master') do |json|
100
- ActiveSupport::JSON.decode(json.read)['object']['sha']
101
- end
102
- open('https://api.github.com/repos/amatsuda/kaminari_themes/git/trees/' + master_tree_sha + '?recursive=1') do |json|
103
- blobs = ActiveSupport::JSON.decode(json.read)['tree'].find_all {|i| i['type'] == 'blob' }
104
- blobs.map do |blob|
105
- [blob['path'], blob['sha']]
106
- end
107
- end
108
- end
109
- module_function :get_files_in_master
110
-
111
- def get_content_for(path)
112
- open('https://api.github.com/repos/amatsuda/kaminari_themes/contents/' + path) do |json|
113
- Base64.decode64(ActiveSupport::JSON.decode(json.read)['content'])
114
- end
115
- end
116
- module_function :get_content_for
117
- end
118
- end
119
- end
@@ -1,51 +0,0 @@
1
- require 'active_support/configurable'
2
-
3
- module Kaminari
4
- # Configures global settings for Kaminari
5
- # Kaminari.configure do |config|
6
- # config.default_per_page = 10
7
- # end
8
- def self.configure(&block)
9
- yield @config ||= Kaminari::Configuration.new
10
- end
11
-
12
- # Global settings for Kaminari
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
@@ -1,4 +0,0 @@
1
- module Kaminari #:nodoc:
2
- class Engine < ::Rails::Engine #:nodoc:
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- require 'grape'
2
- require 'kaminari'
3
-
4
- Kaminari::Hooks.init
@@ -1,132 +0,0 @@
1
- module Kaminari
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>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
17
- def paginate(scope, options = {}, &block)
18
- options[:total_pages] ||= options[:num_pages] || scope.total_pages
19
-
20
- paginator = Kaminari::Helpers::Paginator.new(self, options.reverse_merge(:current_page => scope.current_page, :per_page => scope.limit_value, :remote => false))
21
- paginator.to_s
22
- end
23
-
24
- # A simple "Twitter like" pagination link that creates a link to the previous page.
25
- #
26
- # ==== Examples
27
- # Basic usage:
28
- #
29
- # <%= link_to_previous_page @items, 'Previous Page' %>
30
- #
31
- # Ajax:
32
- #
33
- # <%= link_to_previous_page @items, 'Previous Page', :remote => true %>
34
- #
35
- # By default, it renders nothing if there are no more results on the previous page.
36
- # You can customize this output by passing a block.
37
- #
38
- # <%= link_to_previous_page @users, 'Previous Page' do %>
39
- # <span>At the Beginning</span>
40
- # <% end %>
41
- def link_to_previous_page(scope, name, options = {}, &block)
42
- params = options.delete(:params) || {}
43
- param_name = options.delete(:param_name) || Kaminari.config.param_name
44
- link_to_unless scope.first_page?, name, params.merge(param_name => scope.prev_page), options.reverse_merge(:rel => 'previous') do
45
- block.call if block
46
- end
47
- end
48
-
49
- # A simple "Twitter like" pagination link that creates a link to the next page.
50
- #
51
- # ==== Examples
52
- # Basic usage:
53
- #
54
- # <%= link_to_next_page @items, 'Next Page' %>
55
- #
56
- # Ajax:
57
- #
58
- # <%= link_to_next_page @items, 'Next Page', :remote => true %>
59
- #
60
- # By default, it renders nothing if there are no more results on the next page.
61
- # You can customize this output by passing a block.
62
- #
63
- # <%= link_to_next_page @users, 'Next Page' do %>
64
- # <span>No More Pages</span>
65
- # <% end %>
66
- def link_to_next_page(scope, name, options = {}, &block)
67
- params = options.delete(:params) || {}
68
- param_name = options.delete(:param_name) || Kaminari.config.param_name
69
- link_to_unless scope.last_page?, name, params.merge(param_name => scope.next_page), options.reverse_merge(:rel => 'next') do
70
- block.call if block
71
- end
72
- end
73
-
74
- # Renders a helpful message with numbers of displayed vs. total entries.
75
- # Ported from mislav/will_paginate
76
- #
77
- # ==== Examples
78
- # Basic usage:
79
- #
80
- # <%= page_entries_info @posts %>
81
- # #-> Displaying posts 6 - 10 of 26 in total
82
- #
83
- # By default, the message will use the humanized class name of objects
84
- # in collection: for instance, "project types" for ProjectType models.
85
- # The namespace will be cutted out and only the last name will be used.
86
- # Override this with the <tt>:entry_name</tt> parameter:
87
- #
88
- # <%= page_entries_info @posts, :entry_name => 'item' %>
89
- # #-> Displaying items 6 - 10 of 26 in total
90
- def page_entries_info(collection, options = {})
91
- entry_name = options[:entry_name] || collection.entry_name
92
- entry_name = entry_name.pluralize unless collection.total_count == 1
93
-
94
- if collection.total_pages < 2
95
- t('helpers.page_entries_info.one_page.display_entries', :entry_name => entry_name, :count => collection.total_count)
96
- else
97
- first = collection.offset_value + 1
98
- last = (sum = collection.offset_value + collection.limit_value) > collection.total_count ? collection.total_count : sum
99
- t('helpers.page_entries_info.more_pages.display_entries', :entry_name => entry_name, :first => first, :last => last, :total => collection.total_count)
100
- end.html_safe
101
- end
102
-
103
- # Renders rel="next" and rel="prev" links to be used in the head.
104
- #
105
- # ==== Examples
106
- # Basic usage:
107
- #
108
- # In head:
109
- # <head>
110
- # <title>My Website</title>
111
- # <%= yield :head %>
112
- # </head>
113
- #
114
- # Somewhere in body:
115
- # <% content_for :head do %>
116
- # <%= rel_next_prev_link_tags @items %>
117
- # <% end %>
118
- #
119
- # #-> <link rel="next" href="/items/page/3" /><link rel="prev" href="/items/page/1" />
120
- #
121
- def rel_next_prev_link_tags(scope, options = {})
122
- params = options.delete(:params) || {}
123
- param_name = options.delete(:param_name) || Kaminari.config.param_name
124
-
125
- output = ""
126
- output << '<link rel="next" href="' + url_for(params.merge(param_name => scope.next_page, :only_path => true)) + '"/>' if scope.next_page
127
- output << '<link rel="prev" href="' + url_for(params.merge(param_name => scope.prev_page, :only_path => true)) + '"/>' if scope.prev_page
128
-
129
- output.html_safe
130
- end
131
- end
132
- end