dimkiriyenko-kaminari 0.12.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.document +5 -0
  2. data/.gemtest +0 -0
  3. data/.gitignore +7 -0
  4. data/.rspec +2 -0
  5. data/CHANGELOG +245 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.rdoc +226 -0
  9. data/Rakefile +22 -0
  10. data/app/views/kaminari/_first_page.html.erb +11 -0
  11. data/app/views/kaminari/_first_page.html.haml +9 -0
  12. data/app/views/kaminari/_first_page.html.slim +10 -0
  13. data/app/views/kaminari/_gap.html.erb +8 -0
  14. data/app/views/kaminari/_gap.html.haml +8 -0
  15. data/app/views/kaminari/_gap.html.slim +9 -0
  16. data/app/views/kaminari/_last_page.html.erb +11 -0
  17. data/app/views/kaminari/_last_page.html.haml +9 -0
  18. data/app/views/kaminari/_last_page.html.slim +10 -0
  19. data/app/views/kaminari/_next_page.html.erb +11 -0
  20. data/app/views/kaminari/_next_page.html.haml +9 -0
  21. data/app/views/kaminari/_next_page.html.slim +10 -0
  22. data/app/views/kaminari/_page.html.erb +12 -0
  23. data/app/views/kaminari/_page.html.haml +10 -0
  24. data/app/views/kaminari/_page.html.slim +11 -0
  25. data/app/views/kaminari/_paginator.html.erb +23 -0
  26. data/app/views/kaminari/_paginator.html.haml +18 -0
  27. data/app/views/kaminari/_paginator.html.slim +19 -0
  28. data/app/views/kaminari/_prev_page.html.erb +11 -0
  29. data/app/views/kaminari/_prev_page.html.haml +9 -0
  30. data/app/views/kaminari/_prev_page.html.slim +10 -0
  31. data/config/locales/kaminari.yml +10 -0
  32. data/kaminari.gemspec +35 -0
  33. data/lib/generators/kaminari/config_generator.rb +16 -0
  34. data/lib/generators/kaminari/templates/kaminari_config.rb +8 -0
  35. data/lib/generators/kaminari/views_generator.rb +103 -0
  36. data/lib/kaminari.rb +2 -0
  37. data/lib/kaminari/config.rb +41 -0
  38. data/lib/kaminari/engine.rb +4 -0
  39. data/lib/kaminari/helpers/action_view_extension.rb +50 -0
  40. data/lib/kaminari/helpers/paginator.rb +154 -0
  41. data/lib/kaminari/helpers/tags.rb +95 -0
  42. data/lib/kaminari/models/active_record_extension.rb +25 -0
  43. data/lib/kaminari/models/active_record_relation_methods.rb +31 -0
  44. data/lib/kaminari/models/array_extension.rb +42 -0
  45. data/lib/kaminari/models/configuration_methods.rb +20 -0
  46. data/lib/kaminari/models/mongo_mapper_extension.rb +18 -0
  47. data/lib/kaminari/models/mongoid_criteria_methods.rb +18 -0
  48. data/lib/kaminari/models/mongoid_extension.rb +31 -0
  49. data/lib/kaminari/models/page_scope_methods.rb +36 -0
  50. data/lib/kaminari/models/plucky_criteria_methods.rb +18 -0
  51. data/lib/kaminari/railtie.rb +36 -0
  52. data/lib/kaminari/version.rb +3 -0
  53. data/spec/acceptance/acceptance_helper.rb +5 -0
  54. data/spec/acceptance/support/helpers.rb +5 -0
  55. data/spec/acceptance/support/paths.rb +9 -0
  56. data/spec/acceptance/users_spec.rb +53 -0
  57. data/spec/config/config_spec.rb +61 -0
  58. data/spec/fake_app.rb +80 -0
  59. data/spec/helpers/action_view_extension_spec.rb +37 -0
  60. data/spec/helpers/helpers_spec.rb +135 -0
  61. data/spec/helpers/tags_spec.rb +140 -0
  62. data/spec/models/active_record_relation_methods_spec.rb +40 -0
  63. data/spec/models/array_spec.rb +105 -0
  64. data/spec/models/default_per_page_spec.rb +29 -0
  65. data/spec/models/mongo_mapper_spec.rb +79 -0
  66. data/spec/models/mongoid_spec.rb +72 -0
  67. data/spec/models/scopes_spec.rb +149 -0
  68. data/spec/spec_helper.rb +28 -0
  69. data/spec/support/database_cleaner.rb +13 -0
  70. data/spec/support/matchers.rb +46 -0
  71. metadata +314 -0
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.pattern = FileList['spec/**/*_spec.rb']
10
+ end
11
+
12
+ task :default => :spec
13
+
14
+ require 'rake/rdoctask'
15
+ Rake::RDocTask.new do |rdoc|
16
+ require 'kaminari/version'
17
+
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = "kaminari #{Kaminari::VERSION}"
20
+ rdoc.rdoc_files.include('README*')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,11 @@
1
+ <%# Link to the "First" page
2
+ - available local variables
3
+ url: url to the first page
4
+ current_page: a page object for the currently displayed page
5
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <span class="first">
10
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote %>
11
+ </span>
@@ -0,0 +1,9 @@
1
+ -# Link to the "First" page
2
+ -# available local variables
3
+ -# url: url to the first page
4
+ -# current_page: a page object for the currently displayed page
5
+ -# num_pages: total number of pages
6
+ -# per_page: number of items to fetch per page
7
+ -# remote: data-remote
8
+ %span.first
9
+ = link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote
@@ -0,0 +1,10 @@
1
+ / Link to the "First" page
2
+ - available local variables
3
+ url : url to the first page
4
+ current_page : a page object for the currently displayed page
5
+ num_pages : total number of pages
6
+ per_page : number of items to fetch per page
7
+ remote : data-remote
8
+ span.first
9
+ == link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote
10
+ '
@@ -0,0 +1,8 @@
1
+ <%# Non-link tag that stands for skipped pages...
2
+ - available local variables
3
+ current_page: a page object for the currently displayed page
4
+ num_pages: total number of pages
5
+ per_page: number of items to fetch per page
6
+ remote: data-remote
7
+ -%>
8
+ <span class="page gap"><%= raw(t 'views.pagination.truncate') %></span>
@@ -0,0 +1,8 @@
1
+ -# Non-link tag that stands for skipped pages...
2
+ -# available local variables
3
+ -# current_page: a page object for the currently displayed page
4
+ -# num_pages: total number of pages
5
+ -# per_page: number of items to fetch per page
6
+ -# remote: data-remote
7
+ %span.page.gap
8
+ = raw(t 'views.pagination.truncate')
@@ -0,0 +1,9 @@
1
+ / Non-link tag that stands for skipped pages...
2
+ - available local variables
3
+ current_page : a page object for the currently displayed page
4
+ num_pages : total number of pages
5
+ per_page : number of items to fetch per page
6
+ remote : data-remote
7
+ span.page.gap
8
+ == raw(t 'views.pagination.truncate')
9
+ '
@@ -0,0 +1,11 @@
1
+ <%# Link to the "Last" page
2
+ - available local variables
3
+ url: url to the last page
4
+ current_page: a page object for the currently displayed page
5
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <span class="last">
10
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote} %>
11
+ </span>
@@ -0,0 +1,9 @@
1
+ -# Link to the "Last" page
2
+ -# available local variables
3
+ -# url: url to the last page
4
+ -# current_page: a page object for the currently displayed page
5
+ -# num_pages: total number of pages
6
+ -# per_page: number of items to fetch per page
7
+ -# remote: data-remote
8
+ %span.last
9
+ = link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote}
@@ -0,0 +1,10 @@
1
+ / Link to the "Last" page
2
+ - available local variables
3
+ url : url to the last page
4
+ current_page : a page object for the currently displayed page
5
+ num_pages : total number of pages
6
+ per_page : number of items to fetch per page
7
+ remote : data-remote
8
+ span.last
9
+ == link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote}
10
+ '
@@ -0,0 +1,11 @@
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
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <span class="next">
10
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote %>
11
+ </span>
@@ -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
+ -# num_pages: total number of pages
6
+ -# per_page: number of items to fetch per page
7
+ -# remote: data-remote
8
+ %span.next
9
+ = link_to_unless current_page.last?, raw(t 'views.pagination.next'), 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
+ num_pages : total number of pages
6
+ per_page : number of items to fetch per page
7
+ remote : data-remote
8
+ span.next
9
+ == link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote
10
+ '
@@ -0,0 +1,12 @@
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
+ num_pages: total number of pages
7
+ per_page: number of items to fetch per page
8
+ remote: data-remote
9
+ -%>
10
+ <span class="page<%= ' current' if page.current? %>">
11
+ <%= link_to_unless page.current?, page, url, opts = {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
12
+ </span>
@@ -0,0 +1,10 @@
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
+ -# num_pages: total number of pages
7
+ -# per_page: number of items to fetch per page
8
+ -# remote: data-remote
9
+ %span{:class => "page#{' current' if page.current?}"}
10
+ = link_to_unless page.current?, page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil}
@@ -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
+ num_pages : total number of pages
7
+ per_page : number of items to fetch per page
8
+ remote : data-remote
9
+ span class="page#{' current' if page.current?}"
10
+ == link_to_unless page.current?, page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil}
11
+ '
@@ -0,0 +1,23 @@
1
+ <%# The container tag
2
+ - available local variables
3
+ current_page: a page object for the currently displayed page
4
+ num_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
+ <%= 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
+ <% end -%>
19
+ <% end -%>
20
+ <%= next_page_tag unless current_page.last? %>
21
+ <%= last_page_tag unless current_page.last? %>
22
+ </nav>
23
+ <% end -%>
@@ -0,0 +1,18 @@
1
+ -# The container tag
2
+ -# available local variables
3
+ -# current_page: a page object for the currently displayed page
4
+ -# num_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
+ = first_page_tag unless current_page.first?
11
+ = prev_page_tag unless current_page.first?
12
+ - each_page do |page|
13
+ - if page.left_outer? || page.right_outer? || page.inside_window?
14
+ = page_tag page
15
+ - elsif !page.was_truncated?
16
+ = gap_tag
17
+ = next_page_tag unless current_page.last?
18
+ = last_page_tag unless current_page.last?
@@ -0,0 +1,19 @@
1
+ / The container tag
2
+ - available local variables
3
+ current_page : a page object for the currently displayed page
4
+ num_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
+ == 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,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
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <span class="prev">
10
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote %>
11
+ </span>
@@ -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
+ -# num_pages: total number of pages
6
+ -# per_page: number of items to fetch per page
7
+ -# remote: data-remote
8
+ %span.prev
9
+ = link_to_unless current_page.first?, raw(t 'views.pagination.previous'), 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
+ num_pages : total number of pages
6
+ per_page : number of items to fetch per page
7
+ remote : data-remote
8
+ span.prev
9
+ == link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote
10
+ '
@@ -0,0 +1,10 @@
1
+ # Sample localization file for Kaminari. 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: "..."
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "kaminari/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'dimkiriyenko-kaminari'
7
+ s.version = Kaminari::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Akira Matsuda','Dmitriy Kiriyenko']
10
+ s.email = ['ronnie@dio.jp', 'dmitriy.kiriyenko@gmail.com']
11
+ s.homepage = 'https://github.com/dmitriy-kiriyenko/kaminari'
12
+ s.summary = 'A pagination engine plugin for Rails 3'
13
+ s.description = 'Kaminari is a Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Rails 3'
14
+
15
+ s.rubyforge_project = 'kaminari'
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 'rails', ['>= 3.0.0']
25
+ s.add_development_dependency 'bundler', ['>= 1.0.0']
26
+ s.add_development_dependency 'sqlite3', ['>= 0']
27
+ s.add_development_dependency 'mongoid', ['>= 2']
28
+ s.add_development_dependency 'mongo_mapper', ['>= 0.9']
29
+ s.add_development_dependency 'rspec', ['>= 0']
30
+ s.add_development_dependency 'rspec-rails', ['>= 0']
31
+ s.add_development_dependency 'rr', ['>= 0']
32
+ s.add_development_dependency 'steak', ['>= 0']
33
+ s.add_development_dependency 'capybara', ['>= 0']
34
+ s.add_development_dependency 'database_cleaner', ['>= 0']
35
+ end
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,8 @@
1
+ Kaminari.configure do |config|
2
+ # config.default_per_page = 25
3
+ # config.window = 4
4
+ # config.outer_window = 0
5
+ # config.left = 0
6
+ # config.right = 0
7
+ # config.param_name = :page
8
+ end
@@ -0,0 +1,103 @@
1
+ module Kaminari
2
+ module Generators
3
+ SHOW_API = 'http://github.com/api/v2/json/blob/show/amatsuda/kaminari_themes'
4
+ ALL_API = 'http://github.com/api/v2/json/blob/all/amatsuda/kaminari_themes/master'
5
+
6
+ class ViewsGenerator < Rails::Generators::NamedBase
7
+ source_root File.expand_path('../../../../app/views/kaminari', __FILE__)
8
+
9
+ class_option :template_engine, :type => :string, :aliases => '-e', :desc => 'Template engine for the views. Available options are "erb" and "haml".'
10
+
11
+ def self.banner #:nodoc:
12
+ <<-BANNER.chomp
13
+ rails g kaminari:views THEME [options]
14
+
15
+ Copies all paginator partial templates to your application.
16
+ You can choose a template THEME by specifying one from the list below:
17
+
18
+ - default
19
+ The default one.
20
+ This one is used internally while you don't override the partials.
21
+ #{themes.map {|t| " - #{t.name}\n#{t.description}"}.join("\n")}
22
+ BANNER
23
+ end
24
+
25
+ desc ''
26
+ def copy_or_fetch #:nodoc:
27
+ return copy_default_views if file_name == 'default'
28
+
29
+ themes = self.class.themes
30
+ if theme = themes.detect {|t| t.name == file_name}
31
+ download_templates theme
32
+ else
33
+ say %Q[no such theme: #{file_name}\n avaliable themes: #{themes.map(&:name).join ", "}]
34
+ end
35
+ end
36
+
37
+ private
38
+ def self.themes
39
+ begin
40
+ @themes ||= open ALL_API do |json|
41
+ # @themes ||= open(File.join(File.dirname(__FILE__), '../../../spec/generators/sample.json')) do |json|
42
+ files = ActiveSupport::JSON.decode(json)['blobs']
43
+ hash = files.group_by {|fn, _| fn[0...(fn.index('/') || 0)]}.delete_if {|fn, _| fn.blank?}
44
+ hash.map do |name, files|
45
+ Theme.new name, files
46
+ end
47
+ end
48
+ rescue SocketError
49
+ []
50
+ end
51
+ end
52
+
53
+ def download_templates(theme)
54
+ theme.templates_for(template_engine).each do |template|
55
+ say " downloading #{template.name} from kaminari_themes..."
56
+ get "#{SHOW_API}/#{template.sha}", template.name
57
+ end
58
+ end
59
+
60
+ def copy_default_views
61
+ filename_pattern = File.join self.class.source_root, "*.html.#{template_engine}"
62
+ Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
63
+ copy_file f, "app/views/kaminari/#{f}"
64
+ end
65
+ end
66
+
67
+ def template_engine
68
+ options[:template_engine].try(:to_s).try(:downcase) || 'erb'
69
+ end
70
+ end
71
+
72
+ Template = Struct.new(:name, :sha) do
73
+ def description?
74
+ name == 'DESCRIPTION'
75
+ end
76
+
77
+ def view?
78
+ name =~ /^app\/views\//
79
+ end
80
+
81
+ def engine #:nodoc:
82
+ File.extname(name).sub /^\./, ''
83
+ end
84
+ end
85
+
86
+ class Theme
87
+ attr_accessor :name
88
+ def initialize(name, templates) #:nodoc:
89
+ @name, @templates = name, templates.map {|fn, sha| Template.new fn.sub(/^#{name}\//, ''), sha}
90
+ end
91
+
92
+ def description #:nodoc:
93
+ file = @templates.detect(&:description?)
94
+ return "#{' ' * 12}#{name}" unless file
95
+ open("#{SHOW_API}/#{file.sha}").read.chomp.gsub /^/, ' ' * 12
96
+ end
97
+
98
+ def templates_for(template_engine) #:nodoc:
99
+ @templates.select {|t| !t.description?}.select {|t| !t.view? || (t.engine == template_engine)}
100
+ end
101
+ end
102
+ end
103
+ end