kaminari 0.10.4 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of kaminari might be problematic. Click here for more details.

Files changed (55) hide show
  1. data/CHANGELOG +31 -0
  2. data/Gemfile +1 -30
  3. data/Gemfile.lock +66 -82
  4. data/README.rdoc +16 -0
  5. data/Rakefile +12 -2
  6. data/VERSION +1 -1
  7. data/app/views/kaminari/_first_page.html.erb +11 -0
  8. data/app/views/kaminari/_first_page.html.haml +9 -0
  9. data/app/views/kaminari/{_truncated_span.html.erb → _gap.html.erb} +2 -2
  10. data/app/views/kaminari/{_truncated_span.html.haml → _gap.html.haml} +2 -2
  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/{_next_link.html.erb → _next_page.html.erb} +3 -3
  14. data/app/views/kaminari/{_next_link.html.haml → _next_page.html.haml} +3 -3
  15. data/app/views/kaminari/_page.html.erb +12 -0
  16. data/app/views/kaminari/_page.html.haml +10 -0
  17. data/app/views/kaminari/_paginator.html.erb +8 -14
  18. data/app/views/kaminari/_paginator.html.haml +8 -13
  19. data/app/views/kaminari/{_prev_link.html.erb → _prev_page.html.erb} +3 -3
  20. data/app/views/kaminari/_prev_page.html.haml +9 -0
  21. data/config/locales/kaminari.yml +4 -2
  22. data/kaminari.gemspec +88 -59
  23. data/lib/generators/kaminari/views_generator.rb +13 -9
  24. data/lib/kaminari.rb +1 -0
  25. data/lib/kaminari/helpers/action_view_extension.rb +5 -5
  26. data/lib/kaminari/helpers/paginator.rb +153 -0
  27. data/lib/kaminari/helpers/tags.rb +32 -200
  28. data/lib/kaminari/models/active_record_extension.rb +1 -8
  29. data/lib/kaminari/models/active_record_relation_methods.rb +8 -1
  30. data/lib/kaminari/models/mongoid_extension.rb +1 -0
  31. data/lib/kaminari/railtie.rb +1 -1
  32. data/lib/kaminari/version.rb +3 -0
  33. data/spec/acceptance/users_spec.rb +13 -4
  34. data/spec/fake_app.rb +34 -2
  35. data/spec/helpers/helpers_spec.rb +13 -4
  36. data/spec/helpers/tags_spec.rb +32 -50
  37. data/spec/models/active_record_relation_methods_spec.rb +18 -0
  38. data/spec/models/scopes_spec.rb +12 -1
  39. data/spec/spec_helper.rb +1 -0
  40. data/spec/support/database_cleaner.rb +13 -0
  41. metadata +248 -127
  42. data/app/views/kaminari/_current_page.html.erb +0 -9
  43. data/app/views/kaminari/_current_page.html.haml +0 -9
  44. data/app/views/kaminari/_first_page_link.html.erb +0 -12
  45. data/app/views/kaminari/_first_page_link.html.haml +0 -10
  46. data/app/views/kaminari/_last_page_link.html.erb +0 -12
  47. data/app/views/kaminari/_last_page_link.html.haml +0 -10
  48. data/app/views/kaminari/_next_span.html.erb +0 -8
  49. data/app/views/kaminari/_next_span.html.haml +0 -7
  50. data/app/views/kaminari/_page_link.html.erb +0 -12
  51. data/app/views/kaminari/_page_link.html.haml +0 -10
  52. data/app/views/kaminari/_prev_link.html.haml +0 -9
  53. data/app/views/kaminari/_prev_span.html.erb +0 -8
  54. data/app/views/kaminari/_prev_span.html.haml +0 -7
  55. data/lib/kaminari/helpers/helpers.rb +0 -75
@@ -1,6 +1,6 @@
1
1
  <%# The container tag
2
2
  - available local variables
3
- current_page: the page number of currently displayed page
3
+ current_page: a page object for the currently displayed page
4
4
  num_pages: total number of pages
5
5
  per_page: number of items to fetch per page
6
6
  remote: data-remote
@@ -8,22 +8,16 @@
8
8
  -%>
9
9
  <%= paginator.render do -%>
10
10
  <nav class="pagination">
11
- <%= current_page > 1 ? prev_link_tag : prev_span_tag %>
11
+ <%= first_page_tag unless current_page.first? %>
12
+ <%= prev_page_tag unless current_page.first? %>
12
13
  <% each_page do |page| -%>
13
- <% if page.current? -%>
14
- <%= current_page_tag %>
15
- <% elsif page.left_outer? || page.right_outer? || page.inside_window? -%>
16
- <% if page.first? -%>
17
- <%= first_page_link_tag %>
18
- <% elsif page.last? -%>
19
- <%= last_page_link_tag %>
20
- <% else -%>
21
- <%= page_link_tag %>
22
- <% end -%>
14
+ <% if page.left_outer? || page.right_outer? || page.inside_window? -%>
15
+ <%= page_tag page %>
23
16
  <% elsif !page.was_truncated? -%>
24
- <%= truncated_span_tag %>
17
+ <%= gap_tag %>
25
18
  <% end -%>
26
19
  <% end -%>
27
- <%= num_pages > current_page ? next_link_tag : next_span_tag %>
20
+ <%= next_page_tag unless current_page.last? %>
21
+ <%= last_page_tag unless current_page.last? %>
28
22
  </nav>
29
23
  <% end -%>
@@ -1,23 +1,18 @@
1
1
  -# The container tag
2
2
  - available local variables
3
- current_page: the page number of currently displayed page
3
+ current_page: a page object for the currently displayed page
4
4
  num_pages: total number of pages
5
5
  per_page: number of items to fetch per page
6
6
  remote: data-remote
7
7
  paginator: the paginator that renders the pagination tags inside
8
8
  = paginator.render do
9
9
  %nav.pagination
10
- = current_page > 1 ? prev_link_tag : prev_span_tag
10
+ = first_page_tag unless current_page.first?
11
+ = prev_page_tag unless current_page.first?
11
12
  - each_page do |page|
12
- - if page.current?
13
- = current_page_tag
14
- - elsif page.left_outer? || page.right_outer? || page.inside_window?
15
- - if page.first?
16
- = first_page_link_tag
17
- - elsif page.last?
18
- = last_page_link_tag
19
- - else
20
- = page_link_tag
13
+ - if page.left_outer? || page.right_outer? || page.inside_window?
14
+ = page_tag page
21
15
  - elsif !page.was_truncated?
22
- = truncated_span_tag
23
- = num_pages > current_page ? next_link_tag : next_span_tag
16
+ = gap_tag
17
+ = next_page_tag unless current_page.last?
18
+ = last_page_tag unless current_page.last?
@@ -1,11 +1,11 @@
1
- <%# "Previous" with link
1
+ <%# Link to the "Previous" page
2
2
  - available local variables
3
3
  url: url to the previous page
4
- current_page: the page number of currently displayed page
4
+ current_page: a page object for the currently displayed page
5
5
  num_pages: total number of pages
6
6
  per_page: number of items to fetch per page
7
7
  remote: data-remote
8
8
  -%>
9
9
  <span class="prev">
10
- <%= link_to raw(t 'views.pagination.previous'), url, :class => 'prev', :rel => 'prev', :remote => remote %>
10
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote %>
11
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
@@ -3,6 +3,8 @@
3
3
  en:
4
4
  views:
5
5
  pagination:
6
- previous: "&laquo; Prev"
7
- next: "Next &raquo;"
6
+ first: "&laquo; First"
7
+ last: "Last &raquo;"
8
+ previous: "&lsaquo; Prev"
9
+ next: "Next &rsaquo;"
8
10
  truncate: "..."
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kaminari}
8
- s.version = "0.10.4"
8
+ s.version = "0.11.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Akira Matsuda"]
12
- s.date = %q{2011-02-24}
12
+ s.date = %q{2011-04-19}
13
13
  s.description = %q{Kaminari is a Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Rails 3}
14
14
  s.email = %q{ronnie@dio.jp}
15
15
  s.extra_rdoc_files = [
@@ -27,33 +27,27 @@ Gem::Specification.new do |s|
27
27
  "README.rdoc",
28
28
  "Rakefile",
29
29
  "VERSION",
30
- "app/views/kaminari/_current_page.html.erb",
31
- "app/views/kaminari/_current_page.html.haml",
32
- "app/views/kaminari/_first_page_link.html.erb",
33
- "app/views/kaminari/_first_page_link.html.haml",
34
- "app/views/kaminari/_last_page_link.html.erb",
35
- "app/views/kaminari/_last_page_link.html.haml",
36
- "app/views/kaminari/_next_link.html.erb",
37
- "app/views/kaminari/_next_link.html.haml",
38
- "app/views/kaminari/_next_span.html.erb",
39
- "app/views/kaminari/_next_span.html.haml",
40
- "app/views/kaminari/_page_link.html.erb",
41
- "app/views/kaminari/_page_link.html.haml",
30
+ "app/views/kaminari/_first_page.html.erb",
31
+ "app/views/kaminari/_first_page.html.haml",
32
+ "app/views/kaminari/_gap.html.erb",
33
+ "app/views/kaminari/_gap.html.haml",
34
+ "app/views/kaminari/_last_page.html.erb",
35
+ "app/views/kaminari/_last_page.html.haml",
36
+ "app/views/kaminari/_next_page.html.erb",
37
+ "app/views/kaminari/_next_page.html.haml",
38
+ "app/views/kaminari/_page.html.erb",
39
+ "app/views/kaminari/_page.html.haml",
42
40
  "app/views/kaminari/_paginator.html.erb",
43
41
  "app/views/kaminari/_paginator.html.haml",
44
- "app/views/kaminari/_prev_link.html.erb",
45
- "app/views/kaminari/_prev_link.html.haml",
46
- "app/views/kaminari/_prev_span.html.erb",
47
- "app/views/kaminari/_prev_span.html.haml",
48
- "app/views/kaminari/_truncated_span.html.erb",
49
- "app/views/kaminari/_truncated_span.html.haml",
42
+ "app/views/kaminari/_prev_page.html.erb",
43
+ "app/views/kaminari/_prev_page.html.haml",
50
44
  "config/locales/kaminari.yml",
51
45
  "kaminari.gemspec",
52
46
  "lib/generators/kaminari/views_generator.rb",
53
47
  "lib/kaminari.rb",
54
48
  "lib/kaminari/engine.rb",
55
49
  "lib/kaminari/helpers/action_view_extension.rb",
56
- "lib/kaminari/helpers/helpers.rb",
50
+ "lib/kaminari/helpers/paginator.rb",
57
51
  "lib/kaminari/helpers/tags.rb",
58
52
  "lib/kaminari/models/active_record_extension.rb",
59
53
  "lib/kaminari/models/active_record_relation_methods.rb",
@@ -62,6 +56,7 @@ Gem::Specification.new do |s|
62
56
  "lib/kaminari/models/mongoid_extension.rb",
63
57
  "lib/kaminari/models/page_scope_methods.rb",
64
58
  "lib/kaminari/railtie.rb",
59
+ "lib/kaminari/version.rb",
65
60
  "spec/acceptance/acceptance_helper.rb",
66
61
  "spec/acceptance/support/helpers.rb",
67
62
  "spec/acceptance/support/paths.rb",
@@ -69,16 +64,18 @@ Gem::Specification.new do |s|
69
64
  "spec/fake_app.rb",
70
65
  "spec/helpers/helpers_spec.rb",
71
66
  "spec/helpers/tags_spec.rb",
67
+ "spec/models/active_record_relation_methods_spec.rb",
72
68
  "spec/models/default_per_page_spec.rb",
73
69
  "spec/models/mongoid_spec.rb",
74
70
  "spec/models/scopes_spec.rb",
75
71
  "spec/spec_helper.rb",
72
+ "spec/support/database_cleaner.rb",
76
73
  "spec/support/matchers.rb"
77
74
  ]
78
75
  s.homepage = %q{http://github.com/amatsuda/kaminari}
79
76
  s.licenses = ["MIT"]
80
77
  s.require_paths = ["lib"]
81
- s.rubygems_version = %q{1.5.2}
78
+ s.rubygems_version = %q{1.7.2}
82
79
  s.summary = %q{A pagination engine plugin for Rails 3}
83
80
  s.test_files = [
84
81
  "spec/acceptance/acceptance_helper.rb",
@@ -88,10 +85,12 @@ Gem::Specification.new do |s|
88
85
  "spec/fake_app.rb",
89
86
  "spec/helpers/helpers_spec.rb",
90
87
  "spec/helpers/tags_spec.rb",
88
+ "spec/models/active_record_relation_methods_spec.rb",
91
89
  "spec/models/default_per_page_spec.rb",
92
90
  "spec/models/mongoid_spec.rb",
93
91
  "spec/models/scopes_spec.rb",
94
92
  "spec/spec_helper.rb",
93
+ "spec/support/database_cleaner.rb",
95
94
  "spec/support/matchers.rb"
96
95
  ]
97
96
 
@@ -99,54 +98,84 @@ Gem::Specification.new do |s|
99
98
  s.specification_version = 3
100
99
 
101
100
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
102
- s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
103
- s.add_development_dependency(%q<rr>, [">= 1.0.2"])
104
- s.add_development_dependency(%q<steak>, [">= 1.1.0"])
105
- s.add_development_dependency(%q<capybara>, [">= 0.4.1.1"])
101
+ s.add_runtime_dependency(%q<kaminari>, [">= 0"])
102
+ s.add_development_dependency(%q<rails>, [">= 3.0.0"])
106
103
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
107
- s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
104
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
105
+ s.add_development_dependency(%q<mongoid>, [">= 2"])
106
+ s.add_development_dependency(%q<rspec>, [">= 0"])
107
+ s.add_development_dependency(%q<rspec-rails>, [">= 0"])
108
+ s.add_development_dependency(%q<rr>, [">= 0"])
109
+ s.add_development_dependency(%q<steak>, [">= 0"])
110
+ s.add_development_dependency(%q<capybara>, [">= 0"])
111
+ s.add_development_dependency(%q<database_cleaner>, [">= 0"])
108
112
  s.add_development_dependency(%q<rcov>, [">= 0"])
109
- s.add_development_dependency(%q<rails>, [">= 0"])
110
- s.add_development_dependency(%q<rack>, [">= 0"])
111
- s.add_development_dependency(%q<arel>, [">= 0"])
112
- s.add_development_dependency(%q<rspec-rails>, [">= 2.5.0"])
113
- s.add_development_dependency(%q<sqlite3>, [">= 1.3.3"])
114
- s.add_development_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
115
- s.add_development_dependency(%q<bson_ext>, ["~> 1.2"])
116
- s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
113
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
114
+ s.add_development_dependency(%q<rails>, [">= 3.0.0"])
115
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
116
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
117
+ s.add_development_dependency(%q<mongoid>, [">= 2"])
118
+ s.add_development_dependency(%q<rspec>, [">= 0"])
119
+ s.add_development_dependency(%q<rspec-rails>, [">= 0"])
120
+ s.add_development_dependency(%q<rr>, [">= 0"])
121
+ s.add_development_dependency(%q<steak>, [">= 0"])
122
+ s.add_development_dependency(%q<capybara>, [">= 0"])
123
+ s.add_development_dependency(%q<database_cleaner>, [">= 0"])
124
+ s.add_development_dependency(%q<rcov>, [">= 0"])
125
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
117
126
  else
118
- s.add_dependency(%q<rspec>, [">= 2.5.0"])
119
- s.add_dependency(%q<rr>, [">= 1.0.2"])
120
- s.add_dependency(%q<steak>, [">= 1.1.0"])
121
- s.add_dependency(%q<capybara>, [">= 0.4.1.1"])
127
+ s.add_dependency(%q<kaminari>, [">= 0"])
128
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
122
129
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
123
- s.add_dependency(%q<jeweler>, [">= 1.5.2"])
130
+ s.add_dependency(%q<sqlite3>, [">= 0"])
131
+ s.add_dependency(%q<mongoid>, [">= 2"])
132
+ s.add_dependency(%q<rspec>, [">= 0"])
133
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
134
+ s.add_dependency(%q<rr>, [">= 0"])
135
+ s.add_dependency(%q<steak>, [">= 0"])
136
+ s.add_dependency(%q<capybara>, [">= 0"])
137
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
124
138
  s.add_dependency(%q<rcov>, [">= 0"])
125
- s.add_dependency(%q<rails>, [">= 0"])
126
- s.add_dependency(%q<rack>, [">= 0"])
127
- s.add_dependency(%q<arel>, [">= 0"])
128
- s.add_dependency(%q<rspec-rails>, [">= 2.5.0"])
129
- s.add_dependency(%q<sqlite3>, [">= 1.3.3"])
130
- s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
131
- s.add_dependency(%q<bson_ext>, ["~> 1.2"])
139
+ s.add_dependency(%q<jeweler>, [">= 0"])
132
140
  s.add_dependency(%q<rails>, [">= 3.0.0"])
141
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
142
+ s.add_dependency(%q<sqlite3>, [">= 0"])
143
+ s.add_dependency(%q<mongoid>, [">= 2"])
144
+ s.add_dependency(%q<rspec>, [">= 0"])
145
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
146
+ s.add_dependency(%q<rr>, [">= 0"])
147
+ s.add_dependency(%q<steak>, [">= 0"])
148
+ s.add_dependency(%q<capybara>, [">= 0"])
149
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
150
+ s.add_dependency(%q<rcov>, [">= 0"])
151
+ s.add_dependency(%q<jeweler>, [">= 0"])
133
152
  end
134
153
  else
135
- s.add_dependency(%q<rspec>, [">= 2.5.0"])
136
- s.add_dependency(%q<rr>, [">= 1.0.2"])
137
- s.add_dependency(%q<steak>, [">= 1.1.0"])
138
- s.add_dependency(%q<capybara>, [">= 0.4.1.1"])
154
+ s.add_dependency(%q<kaminari>, [">= 0"])
155
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
139
156
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
140
- s.add_dependency(%q<jeweler>, [">= 1.5.2"])
157
+ s.add_dependency(%q<sqlite3>, [">= 0"])
158
+ s.add_dependency(%q<mongoid>, [">= 2"])
159
+ s.add_dependency(%q<rspec>, [">= 0"])
160
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
161
+ s.add_dependency(%q<rr>, [">= 0"])
162
+ s.add_dependency(%q<steak>, [">= 0"])
163
+ s.add_dependency(%q<capybara>, [">= 0"])
164
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
141
165
  s.add_dependency(%q<rcov>, [">= 0"])
142
- s.add_dependency(%q<rails>, [">= 0"])
143
- s.add_dependency(%q<rack>, [">= 0"])
144
- s.add_dependency(%q<arel>, [">= 0"])
145
- s.add_dependency(%q<rspec-rails>, [">= 2.5.0"])
146
- s.add_dependency(%q<sqlite3>, [">= 1.3.3"])
147
- s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
148
- s.add_dependency(%q<bson_ext>, ["~> 1.2"])
166
+ s.add_dependency(%q<jeweler>, [">= 0"])
149
167
  s.add_dependency(%q<rails>, [">= 3.0.0"])
168
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
169
+ s.add_dependency(%q<sqlite3>, [">= 0"])
170
+ s.add_dependency(%q<mongoid>, [">= 2"])
171
+ s.add_dependency(%q<rspec>, [">= 0"])
172
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
173
+ s.add_dependency(%q<rr>, [">= 0"])
174
+ s.add_dependency(%q<steak>, [">= 0"])
175
+ s.add_dependency(%q<capybara>, [">= 0"])
176
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
177
+ s.add_dependency(%q<rcov>, [">= 0"])
178
+ s.add_dependency(%q<jeweler>, [">= 0"])
150
179
  end
151
180
  end
152
181
 
@@ -38,7 +38,7 @@ BANNER
38
38
  def self.themes
39
39
  begin
40
40
  @themes ||= open ALL_API do |json|
41
- # open File.join File.dirname(__FILE__), '../../../spec/generators/sample.json' do |json|
41
+ # @themes ||= open(File.join(File.dirname(__FILE__), '../../../spec/generators/sample.json')) do |json|
42
42
  files = ActiveSupport::JSON.decode(json)['blobs']
43
43
  hash = files.group_by {|fn, _| fn[0...(fn.index('/') || 0)]}.delete_if {|fn, _| fn.blank?}
44
44
  hash.map do |name, files|
@@ -53,7 +53,7 @@ BANNER
53
53
  def download_templates(theme)
54
54
  theme.templates_for(template_engine).each do |template|
55
55
  say " downloading #{template.name} from kaminari_themes..."
56
- get "#{SHOW_API}/#{template.sha}", "app/views/kaminari/#{template.basename}"
56
+ get "#{SHOW_API}/#{template.sha}", template.name
57
57
  end
58
58
  end
59
59
 
@@ -70,29 +70,33 @@ BANNER
70
70
  end
71
71
 
72
72
  Template = Struct.new(:name, :sha) do
73
- def engine #:nodoc:
74
- File.extname(name).sub /^\./, ''
73
+ def description?
74
+ name == 'DESCRIPTION'
75
+ end
76
+
77
+ def view?
78
+ name =~ /^app\/views\//
75
79
  end
76
80
 
77
- def basename #:nodoc:
78
- File.basename name
81
+ def engine #:nodoc:
82
+ File.extname(name).sub /^\./, ''
79
83
  end
80
84
  end
81
85
 
82
86
  class Theme
83
87
  attr_accessor :name
84
88
  def initialize(name, templates) #:nodoc:
85
- @name, @templates = name, templates.map {|f| Template.new *f}
89
+ @name, @templates = name, templates.map {|fn, sha| Template.new fn.sub(/^#{name}\//, ''), sha}
86
90
  end
87
91
 
88
92
  def description #:nodoc:
89
- file = @templates.detect {|t| t.name == "#{name}/DESCRIPTION"}
93
+ file = @templates.detect(&:description?)
90
94
  return "#{' ' * 12}#{name}" unless file
91
95
  open("#{SHOW_API}/#{file.sha}").read.chomp.gsub /^/, ' ' * 12
92
96
  end
93
97
 
94
98
  def templates_for(template_engine) #:nodoc:
95
- @templates.select {|t| t.engine == template_engine}
99
+ @templates.select {|t| !t.description?}.select {|t| !t.view? || (t.engine == template_engine)}
96
100
  end
97
101
  end
98
102
  end
@@ -1,2 +1,3 @@
1
+ require File.join(File.dirname(__FILE__), 'kaminari/version')
1
2
  require File.join(File.dirname(__FILE__), 'kaminari/railtie')
2
3
  require File.join(File.dirname(__FILE__), 'kaminari/engine')
@@ -9,16 +9,16 @@ module Kaminari
9
9
  # <%= paginate @articles %>
10
10
  #
11
11
  # ==== Options
12
- # * <tt>:window</tt> - The "inner window" size (2 by default).
13
- # * <tt>:outer_window</tt> - The "outer window" size (1 by default).
14
- # * <tt>:left</tt> - The "left outer window" size (1 by default).
15
- # * <tt>:right</tt> - The "right outer window" size (1 by default).
12
+ # * <tt>:window</tt> - The "inner window" size (4 by default).
13
+ # * <tt>:outer_window</tt> - The "outer window" size (0 by default).
14
+ # * <tt>:left</tt> - The "left outer window" size (0 by default).
15
+ # * <tt>:right</tt> - The "right outer window" size (0 by default).
16
16
  # * <tt>:params</tt> - url_for parameters for the links (:controller, :action, etc.)
17
17
  # * <tt>:param_name</tt> - parameter name for page number in the links (:page by default)
18
18
  # * <tt>:remote</tt> - Ajax? (false by default)
19
19
  # * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
20
20
  def paginate(scope, options = {}, &block)
21
- Kaminari::Helpers::PaginationRenderer.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :param_name => :page, :remote => false)
21
+ Kaminari::Helpers::Paginator.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :param_name => :page, :remote => false)
22
22
  end
23
23
  end
24
24
  end
@@ -0,0 +1,153 @@
1
+ require File.join(File.dirname(__FILE__), 'tags')
2
+
3
+ module Kaminari
4
+ module Helpers
5
+ # The main container tag
6
+ class Paginator < Tag
7
+ def initialize(template, options) #:nodoc:
8
+ @window_options = {}.tap do |h|
9
+ h[:window] = options.delete(:window) || options.delete(:inner_window) || 4
10
+ outer_window = options.delete(:outer_window)
11
+ h[:left] = options.delete(:left) || outer_window || 0
12
+ h[:right] = options.delete(:right) || outer_window || 0
13
+ end
14
+ @template, @options = template, options
15
+ @options[:current_page] = PageProxy.new @window_options.merge(@options), @options[:current_page], nil
16
+ # so that this instance can actually "render". Black magic?
17
+ @output_buffer = ActionView::OutputBuffer.new
18
+ end
19
+
20
+ # render given block as a view template
21
+ def render(&block)
22
+ instance_eval &block if @options[:num_pages] > 1
23
+ @output_buffer
24
+ end
25
+
26
+ # enumerate each page providing PageProxy object as the block parameter
27
+ def each_page
28
+ return to_enum(:each_page) unless block_given?
29
+
30
+ 1.upto(@options[:num_pages]) do |i|
31
+ yield PageProxy.new(@window_options.merge(@options), i, @last)
32
+ end
33
+ end
34
+
35
+ def page_tag(page)
36
+ @last = Page.new @template, @options.merge(:page => page)
37
+ end
38
+
39
+ %w[first_page prev_page next_page last_page gap].each do |tag|
40
+ eval <<-DEF
41
+ def #{tag}_tag
42
+ @last = #{tag.classify}.new @template, @options
43
+ end
44
+ DEF
45
+ end
46
+
47
+ def to_s #:nodoc:
48
+ suppress_logging_render_partial do
49
+ super @window_options.merge(@options).merge :paginator => self
50
+ end
51
+ end
52
+
53
+ private
54
+ # dirty hack
55
+ def suppress_logging_render_partial(&blk)
56
+ if subscriber = ActionView::LogSubscriber.log_subscribers.detect {|ls| ls.is_a? ActionView::LogSubscriber}
57
+ class << subscriber
58
+ alias_method :render_partial_with_logging, :render_partial
59
+ # do nothing
60
+ def render_partial(event); end
61
+ end
62
+ ret = blk.call
63
+ class << subscriber
64
+ alias_method :render_partial, :render_partial_with_logging
65
+ undef :render_partial_with_logging
66
+ end
67
+ ret
68
+ else
69
+ blk.call
70
+ end
71
+ end
72
+
73
+ # Wraps a "page number" and provides some utility methods
74
+ class PageProxy
75
+ include Comparable
76
+
77
+ def initialize(options, page, last) #:nodoc:
78
+ @options, @page, @last = options, page, last
79
+ end
80
+
81
+ # the page number
82
+ def number
83
+ @page
84
+ end
85
+
86
+ # current page or not
87
+ def current?
88
+ @page == @options[:current_page]
89
+ end
90
+
91
+ # the first page or not
92
+ def first?
93
+ @page == 1
94
+ end
95
+
96
+ # the last page or not
97
+ def last?
98
+ @page == @options[:num_pages]
99
+ end
100
+
101
+ # the previous page or not
102
+ def prev?
103
+ @page == @options[:current_page] - 1
104
+ end
105
+
106
+ # the next page or not
107
+ def next?
108
+ @page == @options[:current_page] + 1
109
+ end
110
+
111
+ # within the left outer window or not
112
+ def left_outer?
113
+ @page <= @options[:left]
114
+ end
115
+
116
+ # within the right outer window or not
117
+ def right_outer?
118
+ @options[:num_pages] - @page < @options[:right]
119
+ end
120
+
121
+ # inside the inner window or not
122
+ def inside_window?
123
+ (@options[:current_page] - @page).abs <= @options[:window]
124
+ end
125
+
126
+ # The last rendered tag was "truncated" or not
127
+ def was_truncated?
128
+ @last.is_a? Gap
129
+ end
130
+
131
+ def to_i
132
+ number
133
+ end
134
+
135
+ def to_s
136
+ number.to_s
137
+ end
138
+
139
+ def +(other)
140
+ to_i + other.to_i
141
+ end
142
+
143
+ def -(other)
144
+ to_i - other.to_i
145
+ end
146
+
147
+ def <=>(other)
148
+ to_i <=> other.to_i
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end