kaminari 0.9.2 → 0.9.3

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.

data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ == 0.9.3
2
+
3
+ * improved template detection logic
4
+ When a template for a tag could not be found in the app/views/kaminari/
5
+ directory, it searches the tag's ancestor template files before falling back
6
+ to engine's default template. This may help keeping your custom templates DRY.
7
+
8
+ * simplified bundled template themes
9
+
1
10
  == 0.9.2
2
11
 
3
12
  * stop adding extra LF between templates when joining
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.9.3
data/kaminari.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kaminari}
8
- s.version = "0.9.2"
8
+ s.version = "0.9.3"
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-10}
12
+ s.date = %q{2011-02-11}
13
13
  s.description = %q{Kaminari is a Scope & Engine based clean and powerful and customizable and sophisticated paginator for Rails 3}
14
14
  s.email = %q{ronnie@dio.jp}
15
15
  s.extra_rdoc_files = [
@@ -49,10 +49,6 @@ Gem::Specification.new do |s|
49
49
  "app/views/kaminari/_truncated_span.html.haml",
50
50
  "app/views/kaminari/github/_current_page.html.erb",
51
51
  "app/views/kaminari/github/_current_page.html.haml",
52
- "app/views/kaminari/github/_first_page_link.html.erb",
53
- "app/views/kaminari/github/_first_page_link.html.haml",
54
- "app/views/kaminari/github/_last_page_link.html.erb",
55
- "app/views/kaminari/github/_last_page_link.html.haml",
56
52
  "app/views/kaminari/github/_next_link.html.erb",
57
53
  "app/views/kaminari/github/_next_link.html.haml",
58
54
  "app/views/kaminari/github/_next_span.html.erb",
@@ -69,10 +65,6 @@ Gem::Specification.new do |s|
69
65
  "app/views/kaminari/github/_truncated_span.html.haml",
70
66
  "app/views/kaminari/google/_current_page.html.erb",
71
67
  "app/views/kaminari/google/_current_page.html.haml",
72
- "app/views/kaminari/google/_first_page_link.html.erb",
73
- "app/views/kaminari/google/_first_page_link.html.haml",
74
- "app/views/kaminari/google/_last_page_link.html.erb",
75
- "app/views/kaminari/google/_last_page_link.html.haml",
76
68
  "app/views/kaminari/google/_next_link.html.erb",
77
69
  "app/views/kaminari/google/_next_link.html.haml",
78
70
  "app/views/kaminari/google/_next_span.html.erb",
@@ -94,6 +86,7 @@ Gem::Specification.new do |s|
94
86
  "lib/kaminari/engine.rb",
95
87
  "lib/kaminari/helpers.rb",
96
88
  "lib/kaminari/railtie.rb",
89
+ "lib/kaminari/tags.rb",
97
90
  "spec/acceptance/acceptance_helper.rb",
98
91
  "spec/acceptance/support/helpers.rb",
99
92
  "spec/acceptance/support/paths.rb",
@@ -5,7 +5,7 @@ module Kaminari
5
5
 
6
6
  class_option :template_engine, :type => :string, :aliases => '-e', :desc => 'Template engine for the views. Available options are "erb" and "haml".'
7
7
 
8
- def self.banner
8
+ def self.banner #:nodoc:
9
9
  <<-BANNER.chomp
10
10
  rails g kaminari:views THEME [options]
11
11
 
@@ -15,13 +15,13 @@ rails g kaminari:views THEME [options]
15
15
  default: The default one.
16
16
  This one is used internally while you don't override the partials.
17
17
  google: Looks googlish! (note that this is just an example...)
18
- Make sure to specify a very big number (like 65536) for the "window" value.
18
+ Try with this option :window => 10, :outer_window => -1
19
19
  github: A very simple one with only "Older" and "Newer" links.
20
20
  BANNER
21
21
  end
22
22
 
23
23
  desc ''
24
- def copy_views
24
+ def copy_views #:nodoc:
25
25
  Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
26
26
  copy_file File.join([template_name.presence, f].compact), "app/views/kaminari/#{f}"
27
27
  end
@@ -1,4 +1,4 @@
1
- module Kaminari
2
- class Engine < ::Rails::Engine
1
+ module Kaminari #:nodoc:
2
+ class Engine < ::Rails::Engine #:nodoc:
3
3
  end
4
4
  end
@@ -1,71 +1,16 @@
1
+ require File.join(File.dirname(__FILE__), 'tags')
2
+
1
3
  module Kaminari
2
4
  module Helpers
3
- class Tag
4
- def initialize(renderer, options = {})
5
- @renderer, @options = renderer, renderer.options.merge(options)
6
- end
7
-
8
- def to_s(locals = {})
9
- @renderer.render :partial => "kaminari/#{self.class.name.demodulize.underscore}", :locals => @options.merge(locals)
10
- end
11
-
12
- private
13
- def page_url_for(page)
14
- @renderer.url_for @renderer.params.merge(:page => (page <= 1 ? nil : page))
15
- end
16
- end
17
-
18
- class PrevSpan < Tag
19
- end
20
-
21
- class PrevLink < Tag
22
- def to_s
23
- super :prev_url => page_url_for(@options[:current_page] - 1)
24
- end
25
- end
26
-
27
- class NextSpan < Tag
28
- end
29
-
30
- class NextLink < Tag
31
- def to_s
32
- super :next_url => page_url_for(@options[:current_page] + 1)
33
- end
34
- end
35
-
36
- class PageLink < Tag
37
- def to_s
38
- super :page_url => page_url_for(@options[:page])
39
- end
40
- end
41
-
42
- class CurrentPage < Tag
43
- def to_s
44
- super :page_url => page_url_for(@options[:page])
45
- end
46
- end
47
-
48
- class FirstPageLink < PageLink
49
- end
50
-
51
- class LastPageLink < PageLink
52
- end
53
-
54
- class TruncatedSpan < Tag
55
- end
56
-
57
- class Paginator < Tag
58
- end
59
-
60
5
  class PaginationRenderer
61
6
  attr_reader :options
62
7
 
63
- def initialize(template, options)
8
+ def initialize(template, options) #:nodoc:
64
9
  @template, @options = template, options
65
10
  @left, @window, @right = (options[:left] || options[:outer_window] || 1), (options[:window] || options[:inner_window] || 4), (options[:right] || options[:outer_window] || 1)
66
11
  end
67
12
 
68
- def tagify_links
13
+ def tagify_links #:nodoc:
69
14
  num_pages, current_page, left, window, right = @options[:num_pages], @options[:current_page], @left, @window, @right
70
15
  return [] if num_pages <= 1
71
16
 
@@ -90,7 +35,15 @@ module Kaminari
90
35
  tags << (num_pages > current_page ? NextLink.new(self) : NextSpan.new(self))
91
36
  end
92
37
 
93
- def to_s
38
+ def context #:nodoc:
39
+ @template.instance_variable_get('@lookup_context')
40
+ end
41
+
42
+ def resolver #:nodoc:
43
+ context.instance_variable_get('@view_paths').first
44
+ end
45
+
46
+ def to_s #:nodoc:
94
47
  suppress_logging_render_partial do
95
48
  clear_content_for :kaminari_paginator_tags
96
49
  @template.content_for :kaminari_paginator_tags, tagify_links.join.html_safe
@@ -129,6 +82,19 @@ module Kaminari
129
82
  end
130
83
  end
131
84
 
85
+ # = Helpers
86
+ #
87
+ # A helper that renders the pagination links.
88
+ #
89
+ # <%= paginate @articles %>
90
+ #
91
+ # ==== Options
92
+ # * <tt>:window</tt> - The "inner window" size (2 by default).
93
+ # * <tt>:outer_window</tt> - The "outer window" size (1 by default).
94
+ # * <tt>:left</tt> - The "left outer window" size (1 by default).
95
+ # * <tt>:right</tt> - The "right outer window" size (1 by default).
96
+ # * <tt>:remote</tt> - Ajax? (false by default)
97
+ # * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
132
98
  def paginate(scope, options = {}, &block)
133
99
  PaginationRenderer.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :remote => false)
134
100
  end
@@ -5,7 +5,7 @@ require File.join(File.dirname(__FILE__), 'active_record')
5
5
  require File.join(File.dirname(__FILE__), 'helpers')
6
6
 
7
7
  module Kaminari
8
- class Railtie < ::Rails::Railtie
8
+ class Railtie < ::Rails::Railtie #:nodoc:
9
9
  initializer 'paginatablize' do |app|
10
10
  ::ActiveRecord::Base.send :include, Kaminari::ActiveRecord
11
11
  ::ActionView::Base.send :include, Kaminari::Helpers
@@ -0,0 +1,115 @@
1
+ module Kaminari
2
+ module Helpers
3
+ # A tag stands for an HTML tag inside the paginator.
4
+ # Basically, a tag has its own partial template file, so every tag can be
5
+ # rendered into String using its partial template.
6
+ #
7
+ # The template file should be placed in your app/views/kaminari/ directory
8
+ # with underscored class name (besides the "Tag" class. Tag is an abstract
9
+ # class, so _tag parital is not needed).
10
+ # e.g.) PrevLink -> app/views/kaminari/_prev_link.html.erb
11
+ #
12
+ # If the template file does not exist, it falls back to ancestor classes.
13
+ # e.g.) FirstPageLink -> app/views/kaminari/_first_page_link.html.erb
14
+ # -> app/views/kaminari/_page_link.html.erb
15
+ #
16
+ # When no template were found in your app, finally the engine's pre insatalled
17
+ # template will be used.
18
+ # e.g.) Paginator -> $GEM_HOME/kaminari-x.x.x/app/views/kaminari/_paginator.html.erb
19
+ class Tag
20
+ def self.template_filename #:nodoc:
21
+ name.demodulize.underscore
22
+ end
23
+
24
+ def initialize(renderer, options = {}) #:nodoc:
25
+ @renderer, @options = renderer, renderer.options.merge(options)
26
+ end
27
+
28
+ def to_s(locals = {}) #:nodoc:
29
+ @renderer.render :partial => find_template, :locals => @options.merge(locals)
30
+ end
31
+
32
+ private
33
+ # OMG yet another super dirty hack
34
+ # this method finds
35
+ # 1. a template for the given class from app/views
36
+ # 2. a template for its parent class from app/views
37
+ # 3. the default one inside the engine
38
+ def find_template(klass = self.class)
39
+ if @renderer.resolver.find_all(*args_for_lookup(klass)).present?
40
+ "kaminari/#{klass.template_filename}"
41
+ elsif (parent = klass.ancestors[1]) == Tag
42
+ "kaminari/#{self.class.template_filename}"
43
+ else
44
+ find_template parent
45
+ end
46
+ end
47
+
48
+ def args_for_lookup(klass)
49
+ if (method = @renderer.context.method :args_for_lookup).arity == 3
50
+ # 3.0
51
+ method.call klass.template_filename, 'kaminari', true
52
+ else
53
+ # 3.1
54
+ method.call klass.template_filename, 'kaminari', true, []
55
+ end
56
+ end
57
+
58
+ def page_url_for(page)
59
+ @renderer.url_for @renderer.params.merge(:page => (page <= 1 ? nil : page))
60
+ end
61
+ end
62
+
63
+ # "Previous" without link
64
+ class PrevSpan < Tag
65
+ end
66
+
67
+ # "Previous" with link
68
+ class PrevLink < Tag
69
+ def to_s #:nodoc:
70
+ super :prev_url => page_url_for(@options[:current_page] - 1)
71
+ end
72
+ end
73
+
74
+ # "Next" without link
75
+ class NextSpan < Tag
76
+ end
77
+
78
+ # "Next" with link
79
+ class NextLink < Tag
80
+ def to_s #:nodoc:
81
+ super :next_url => page_url_for(@options[:current_page] + 1)
82
+ end
83
+ end
84
+
85
+ # A link showing page number
86
+ class PageLink < Tag
87
+ def to_s #:nodoc:
88
+ super :page_url => page_url_for(@options[:page])
89
+ end
90
+ end
91
+
92
+ # A non-link tag showing the current page number
93
+ class CurrentPage < Tag
94
+ def to_s #:nodoc:
95
+ super :page_url => page_url_for(@options[:page])
96
+ end
97
+ end
98
+
99
+ # A link with page number that appears at the leftmost
100
+ class FirstPageLink < PageLink
101
+ end
102
+
103
+ # A link with page number that appears at the rightmost
104
+ class LastPageLink < PageLink
105
+ end
106
+
107
+ # A non-link tag that stands for skipped pages...
108
+ class TruncatedSpan < Tag
109
+ end
110
+
111
+ # The container tag
112
+ class Paginator < Tag
113
+ end
114
+ end
115
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaminari
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 2
10
- version: 0.9.2
9
+ - 3
10
+ version: 0.9.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Akira Matsuda
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-10 00:00:00 +09:00
18
+ date: 2011-02-11 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -275,10 +275,6 @@ files:
275
275
  - app/views/kaminari/_truncated_span.html.haml
276
276
  - app/views/kaminari/github/_current_page.html.erb
277
277
  - app/views/kaminari/github/_current_page.html.haml
278
- - app/views/kaminari/github/_first_page_link.html.erb
279
- - app/views/kaminari/github/_first_page_link.html.haml
280
- - app/views/kaminari/github/_last_page_link.html.erb
281
- - app/views/kaminari/github/_last_page_link.html.haml
282
278
  - app/views/kaminari/github/_next_link.html.erb
283
279
  - app/views/kaminari/github/_next_link.html.haml
284
280
  - app/views/kaminari/github/_next_span.html.erb
@@ -295,10 +291,6 @@ files:
295
291
  - app/views/kaminari/github/_truncated_span.html.haml
296
292
  - app/views/kaminari/google/_current_page.html.erb
297
293
  - app/views/kaminari/google/_current_page.html.haml
298
- - app/views/kaminari/google/_first_page_link.html.erb
299
- - app/views/kaminari/google/_first_page_link.html.haml
300
- - app/views/kaminari/google/_last_page_link.html.erb
301
- - app/views/kaminari/google/_last_page_link.html.haml
302
294
  - app/views/kaminari/google/_next_link.html.erb
303
295
  - app/views/kaminari/google/_next_link.html.haml
304
296
  - app/views/kaminari/google/_next_span.html.erb
@@ -320,6 +312,7 @@ files:
320
312
  - lib/kaminari/engine.rb
321
313
  - lib/kaminari/helpers.rb
322
314
  - lib/kaminari/railtie.rb
315
+ - lib/kaminari/tags.rb
323
316
  - spec/acceptance/acceptance_helper.rb
324
317
  - spec/acceptance/support/helpers.rb
325
318
  - spec/acceptance/support/paths.rb
@@ -1,9 +0,0 @@
1
- <%# available local variables:
2
- page: the page number of this page
3
- page_url: url to this page
4
- current_page: the page number of 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
- <%# EMPTY! %>
@@ -1,8 +0,0 @@
1
- -# available local variables:
2
- page: the page number of this page
3
- page_url: url to this page
4
- current_page: the page number of 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
- -# EMPTY!
@@ -1,9 +0,0 @@
1
- <%# available local variables:
2
- page: the page number of this page
3
- page_url: url to this page
4
- current_page: the page number of 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
- <%# EMPTY! %>
@@ -1,8 +0,0 @@
1
- -# available local variables:
2
- page: the page number of this page
3
- page_url: url to this page
4
- current_page: the page number of 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
- -# EMPTY!
@@ -1,10 +0,0 @@
1
- <%# available local variables:
2
- page: the page number of this page
3
- page_url: url to this page
4
- current_page: the page number of 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
- <%# this kind of works even though looks a bit hackish... -%>
10
- <%= render :partial => 'kaminari/page_link', :locals => @_partial_renderer.instance_variable_get('@locals') %>
@@ -1,9 +0,0 @@
1
- -# available local variables:
2
- page: the page number of this page
3
- page_url: url to this page
4
- current_page: the page number of 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
- -# this kind of works even though looks a bit hackish...
9
- = render :partial => 'kaminari/page_link', :locals => @_partial_renderer.instance_variable_get('@locals')
@@ -1,10 +0,0 @@
1
- <%# available local variables:
2
- page: the page number of this page
3
- page_url: url to this page
4
- current_page: the page number of 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
- <%# this kind of works even though looks a bit hackish... -%>
10
- <%= render :partial => 'kaminari/page_link', :locals => @_partial_renderer.instance_variable_get('@locals') %>
@@ -1,9 +0,0 @@
1
- -# available local variables:
2
- page: the page number of this page
3
- page_url: url to this page
4
- current_page: the page number of 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
- -# this kind of works even though looks a bit hackish...
9
- = render :partial => 'kaminari/page_link', :locals => @_partial_renderer.instance_variable_get('@locals')