kaminari-jets-core 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.md +31 -0
  5. data/app/views/kaminari/_first_page.html.erb +11 -0
  6. data/app/views/kaminari/_first_page.html.haml +9 -0
  7. data/app/views/kaminari/_first_page.html.slim +10 -0
  8. data/app/views/kaminari/_gap.html.erb +8 -0
  9. data/app/views/kaminari/_gap.html.haml +8 -0
  10. data/app/views/kaminari/_gap.html.slim +9 -0
  11. data/app/views/kaminari/_last_page.html.erb +11 -0
  12. data/app/views/kaminari/_last_page.html.haml +9 -0
  13. data/app/views/kaminari/_last_page.html.slim +10 -0
  14. data/app/views/kaminari/_next_page.html.erb +11 -0
  15. data/app/views/kaminari/_next_page.html.haml +9 -0
  16. data/app/views/kaminari/_next_page.html.slim +10 -0
  17. data/app/views/kaminari/_page.html.erb +12 -0
  18. data/app/views/kaminari/_page.html.haml +10 -0
  19. data/app/views/kaminari/_page.html.slim +11 -0
  20. data/app/views/kaminari/_paginator.html.erb +25 -0
  21. data/app/views/kaminari/_paginator.html.haml +18 -0
  22. data/app/views/kaminari/_paginator.html.slim +19 -0
  23. data/app/views/kaminari/_prev_page.html.erb +11 -0
  24. data/app/views/kaminari/_prev_page.html.haml +9 -0
  25. data/app/views/kaminari/_prev_page.html.slim +10 -0
  26. data/config/locales/kaminari.yml +23 -0
  27. data/kaminari-core.gemspec +26 -0
  28. data/lib/generators/kaminari/config_generator.rb +19 -0
  29. data/lib/generators/kaminari/templates/kaminari_config.rb +14 -0
  30. data/lib/generators/kaminari/views_generator.rb +137 -0
  31. data/lib/kaminari/config.rb +40 -0
  32. data/lib/kaminari/core/version.rb +8 -0
  33. data/lib/kaminari/core.rb +29 -0
  34. data/lib/kaminari/engine.rb +6 -0
  35. data/lib/kaminari/exceptions.rb +5 -0
  36. data/lib/kaminari/helpers/helper_methods.rb +247 -0
  37. data/lib/kaminari/helpers/paginator.rb +191 -0
  38. data/lib/kaminari/helpers/tags.rb +164 -0
  39. data/lib/kaminari/jets/engine.rb +6 -0
  40. data/lib/kaminari/jets/turbine.rb +9 -0
  41. data/lib/kaminari/models/array_extension.rb +73 -0
  42. data/lib/kaminari/models/configuration_methods.rb +60 -0
  43. data/lib/kaminari/models/page_scope_methods.rb +91 -0
  44. data/lib/kaminari/railtie.rb +9 -0
  45. metadata +115 -0
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+
5
+ module Kaminari
6
+ module ConfigurationMethods #:nodoc:
7
+ extend ActiveSupport::Concern
8
+ module ClassMethods #:nodoc:
9
+ # Overrides the default +per_page+ value per model
10
+ # class Article < ActiveRecord::Base
11
+ # paginates_per 10
12
+ # end
13
+ def paginates_per(val)
14
+ @_default_per_page = val
15
+ end
16
+
17
+ # This model's default +per_page+ value
18
+ # returns +default_per_page+ value unless explicitly overridden via <tt>paginates_per</tt>
19
+ def default_per_page
20
+ (defined?(@_default_per_page) && @_default_per_page) || Kaminari.config.default_per_page
21
+ end
22
+
23
+ # Overrides the max +per_page+ value per model
24
+ # class Article < ActiveRecord::Base
25
+ # max_paginates_per 100
26
+ # end
27
+ def max_paginates_per(val)
28
+ @_max_per_page = val
29
+ end
30
+
31
+ # This model's max +per_page+ value
32
+ # returns +max_per_page+ value unless explicitly overridden via <tt>max_paginates_per</tt>
33
+ def max_per_page
34
+ (defined?(@_max_per_page) && @_max_per_page) || Kaminari.config.max_per_page
35
+ end
36
+
37
+ # Overrides the max_pages value per model when a value is given
38
+ # class Article < ActiveRecord::Base
39
+ # max_pages 100
40
+ # end
41
+ #
42
+ # Also returns this model's max_pages value (globally configured
43
+ # +max_pages+ value unless explicitly overridden) when no value is given
44
+ def max_pages(val = :none)
45
+ if val == :none
46
+ # getter
47
+ (defined?(@_max_pages) && @_max_pages) || Kaminari.config.max_pages
48
+ else
49
+ # setter
50
+ @_max_pages = val
51
+ end
52
+ end
53
+
54
+ def max_pages_per(val)
55
+ ActiveSupport::Deprecation.warn 'max_pages_per is deprecated. Use max_pages instead.'
56
+ max_pages val
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kaminari
4
+ module PageScopeMethods
5
+ # Specify the <tt>per_page</tt> value for the preceding <tt>page</tt> scope
6
+ # Model.page(3).per(10)
7
+ def per(num, max_per_page: nil)
8
+ max_per_page ||= ((defined?(@_max_per_page) && @_max_per_page) || self.max_per_page)
9
+ @_per = (num || default_per_page).to_i
10
+ if (n = num.to_i) < 0 || !(/^\d/ =~ num.to_s)
11
+ self
12
+ elsif n.zero?
13
+ limit(n)
14
+ elsif max_per_page && (max_per_page < n)
15
+ limit(max_per_page).offset(offset_value / limit_value * max_per_page)
16
+ else
17
+ limit(n).offset(offset_value / limit_value * n)
18
+ end
19
+ end
20
+
21
+ def max_paginates_per(new_max_per_page)
22
+ @_max_per_page = new_max_per_page
23
+
24
+ per (defined?(@_per) && @_per) || default_per_page, max_per_page: new_max_per_page
25
+ end
26
+
27
+ def padding(num)
28
+ num = num.to_i
29
+ raise ArgumentError, "padding must not be negative" if num < 0
30
+ @_padding = num
31
+ offset(offset_value + @_padding)
32
+ end
33
+
34
+ # Total number of pages
35
+ def total_pages
36
+ count_without_padding = total_count
37
+ count_without_padding -= @_padding if defined?(@_padding) && @_padding
38
+ count_without_padding = 0 if count_without_padding < 0
39
+
40
+ total_pages_count = (count_without_padding.to_f / limit_value).ceil
41
+ max_pages && (max_pages < total_pages_count) ? max_pages : total_pages_count
42
+ rescue FloatDomainError
43
+ raise ZeroPerPageOperation, "The number of total pages was incalculable. Perhaps you called .per(0)?"
44
+ end
45
+
46
+ # Current page number
47
+ def current_page
48
+ offset_without_padding = offset_value
49
+ offset_without_padding -= @_padding if defined?(@_padding) && @_padding
50
+ offset_without_padding = 0 if offset_without_padding < 0
51
+
52
+ (offset_without_padding / limit_value) + 1
53
+ rescue ZeroDivisionError
54
+ raise ZeroPerPageOperation, "Current page was incalculable. Perhaps you called .per(0)?"
55
+ end
56
+
57
+ # Current per-page number
58
+ def current_per_page
59
+ ActiveSupport::Deprecation.warn '#current_per_page is deprecated and will be removed in the next major ' \
60
+ 'version. Please use #limit_value instead.'
61
+
62
+ limit_value
63
+ # (defined?(@_per) && @_per) || default_per_page
64
+ end
65
+
66
+ # Next page number in the collection
67
+ def next_page
68
+ current_page + 1 unless last_page? || out_of_range?
69
+ end
70
+
71
+ # Previous page number in the collection
72
+ def prev_page
73
+ current_page - 1 unless first_page? || out_of_range?
74
+ end
75
+
76
+ # First page of the collection?
77
+ def first_page?
78
+ current_page == 1
79
+ end
80
+
81
+ # Last page of the collection?
82
+ def last_page?
83
+ current_page == total_pages
84
+ end
85
+
86
+ # Out of range of the collection?
87
+ def out_of_range?
88
+ current_page > total_pages
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kaminari
4
+ class Railtie < ::Rails::Railtie #:nodoc:
5
+ # Doesn't actually do anything. Just keeping this hook point, mainly for compatibility
6
+ initializer 'kaminari' do
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kaminari-jets-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Tung Nguyen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: kaminari-core includes pagination logic independent from ORMs and view
42
+ libraries
43
+ email:
44
+ - tongueroo@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - CHANGELOG.md
50
+ - MIT-LICENSE
51
+ - README.md
52
+ - app/views/kaminari/_first_page.html.erb
53
+ - app/views/kaminari/_first_page.html.haml
54
+ - app/views/kaminari/_first_page.html.slim
55
+ - app/views/kaminari/_gap.html.erb
56
+ - app/views/kaminari/_gap.html.haml
57
+ - app/views/kaminari/_gap.html.slim
58
+ - app/views/kaminari/_last_page.html.erb
59
+ - app/views/kaminari/_last_page.html.haml
60
+ - app/views/kaminari/_last_page.html.slim
61
+ - app/views/kaminari/_next_page.html.erb
62
+ - app/views/kaminari/_next_page.html.haml
63
+ - app/views/kaminari/_next_page.html.slim
64
+ - app/views/kaminari/_page.html.erb
65
+ - app/views/kaminari/_page.html.haml
66
+ - app/views/kaminari/_page.html.slim
67
+ - app/views/kaminari/_paginator.html.erb
68
+ - app/views/kaminari/_paginator.html.haml
69
+ - app/views/kaminari/_paginator.html.slim
70
+ - app/views/kaminari/_prev_page.html.erb
71
+ - app/views/kaminari/_prev_page.html.haml
72
+ - app/views/kaminari/_prev_page.html.slim
73
+ - config/locales/kaminari.yml
74
+ - kaminari-core.gemspec
75
+ - lib/generators/kaminari/config_generator.rb
76
+ - lib/generators/kaminari/templates/kaminari_config.rb
77
+ - lib/generators/kaminari/views_generator.rb
78
+ - lib/kaminari/config.rb
79
+ - lib/kaminari/core.rb
80
+ - lib/kaminari/core/version.rb
81
+ - lib/kaminari/engine.rb
82
+ - lib/kaminari/exceptions.rb
83
+ - lib/kaminari/helpers/helper_methods.rb
84
+ - lib/kaminari/helpers/paginator.rb
85
+ - lib/kaminari/helpers/tags.rb
86
+ - lib/kaminari/jets/engine.rb
87
+ - lib/kaminari/jets/turbine.rb
88
+ - lib/kaminari/models/array_extension.rb
89
+ - lib/kaminari/models/configuration_methods.rb
90
+ - lib/kaminari/models/page_scope_methods.rb
91
+ - lib/kaminari/railtie.rb
92
+ homepage: https://github.com/kaminari/kaminari
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 2.0.0
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.4.20
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Kaminari's core pagination library
115
+ test_files: []