psq-merb-pagination 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-08-19
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2008 Lori Holden
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/PostInstall.txt ADDED
@@ -0,0 +1,5 @@
1
+
2
+ For more information on merb_pagination, see:
3
+ http://projects.loriholden.com/wiki/merb_pagination
4
+
5
+
data/README.txt ADDED
@@ -0,0 +1,34 @@
1
+ = merb_pagination
2
+
3
+ * http://merb-pagination.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ A pagination helper for merb. Useful with dm-is-paginated
8
+
9
+ See the website for more details.
10
+
11
+ == LICENSE:
12
+
13
+ (The MIT License)
14
+
15
+ Copyright (c) 2008 Lori Holden
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining
18
+ a copy of this software and associated documentation files (the
19
+ 'Software'), to deal in the Software without restriction, including
20
+ without limitation the rights to use, copy, modify, merge, publish,
21
+ distribute, sublicense, and/or sell copies of the Software, and to
22
+ permit persons to whom the Software is furnished to do so, subject to
23
+ the following conditions:
24
+
25
+ The above copyright notice and this permission notice shall be
26
+ included in all copies or substantial portions of the Software.
27
+
28
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
29
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
31
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
32
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
33
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
34
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,14 @@
1
+ # Needed to import merb and other gems
2
+ require 'rubygems'
3
+ require 'pathname'
4
+
5
+ # Add all external dependencies for the plugin here
6
+ gem 'merb-core', '>=0.9.4'
7
+ require 'merb-core'
8
+
9
+ # Require plugin-files
10
+ dir = Pathname(__FILE__).dirname.expand_path / 'merb-pagination'
11
+ require dir / "hash"
12
+ require dir / 'pagination_helper'
13
+
14
+ Merb::Controller.send(:include, Merb::PaginationHelper)
@@ -0,0 +1,8 @@
1
+ class Hash
2
+ def reverse_merge(other_hash)
3
+ other_hash.merge(self)
4
+ end
5
+ def reverse_merge!(other_hash)
6
+ replace(reverse_merge(other_hash))
7
+ end
8
+ end
@@ -0,0 +1,136 @@
1
+ require 'builder'
2
+ module Merb
3
+ module PaginationHelper
4
+ # Given a page count and the current page, we generate a set of pagination
5
+ # links.
6
+ #
7
+ # * We use an inner and outer window into a list of links. For a set of
8
+ # 20 pages with the current page being 10:
9
+ # outer_window:
10
+ # 1 2 ..... 19 20
11
+ # inner_window
12
+ # 5 6 7 8 9 10 11 12 13 14
13
+ #
14
+ # This is totally adjustable, or can be turned off by giving the
15
+ # :inner_window setting a value of nil.
16
+ #
17
+ # * Options
18
+ # :class => <em>css_class</em::
19
+ # The CSS class to be given to the paginator div.
20
+ # Defaults to 'paginated'
21
+ # :prev_label => <em>text_for_previous_link</em>::
22
+ # Defaults to '&laquo; Previous '
23
+ # :next_labe => <em>text_for_next_link</em>::
24
+ # Defaults to ' Next &raquo;'
25
+ # :left_cut_label => <em>text_for_cut</em>::
26
+ # Used when the page numbers need to be cut off to prevent the set of
27
+ # pagination links from being too long.
28
+ # Defaults to '&larr;'
29
+ # :right_cut_label => <em>text_for_cut</em>::
30
+ # Same as :left_cut_label but for the right side of numbers.
31
+ # Defaults to '&rarr;'
32
+ # :outer_window => <em>number_of_pages</em>::
33
+ # Sets the number of pages to include in the outer 'window'
34
+ # Defaults to 2
35
+ # :inner_window => <em>number_of_pages</em>::
36
+ # Sets the number of pags to include in the inner 'window'
37
+ # Defaults to 10
38
+ # :default_css => <em>use_paginator_provided_css</em>
39
+ # Use the default CSS provided by the paginator. If you want to do
40
+ # your own custom styling of the paginator from scratch, set this to
41
+ # false.
42
+ # Defaults to true
43
+ # :page_param => <em>name_of_page_paramiter</em>
44
+ # Sets the name of the paramiter the paginator uses to return what
45
+ # page is being requested.
46
+ # Defaults to 'page'
47
+ # :url => <em>url_for_links</em>
48
+ # Provides the base url to use in the page navigation links.
49
+ # Defaults to ''
50
+ def paginate(current_page, page_count, options = {})
51
+ options.reverse_merge!({
52
+ :class => 'paginated',
53
+ :prev_label => '&laquo; Previous',
54
+ :next_label => 'Next &raquo;',
55
+ :left_cut_label => '&larr;',
56
+ :right_cut_label => '&rarr;',
57
+ :outer_window => 2,
58
+ :inner_window => 10,
59
+ :default_css => true,
60
+ :page_param => 'page',
61
+ :url => ''
62
+ })
63
+ url = options.delete :url
64
+ url << (url.include?('?') ? '&' : '?') << options[:page_param]
65
+
66
+ pages = {
67
+ :all => (1 .. page_count).to_a,
68
+ :left => [],
69
+ :center => [],
70
+ :right => []
71
+ }
72
+
73
+ # Only worry about using our 'windows' if the page count is less then
74
+ # our windows combined.
75
+ if options[:inner_window].nil? or ((options[:outer_window] *2) + options[:inner_window] + 2) >= page_count
76
+ pages[:center] = pages[:all]
77
+ else
78
+ pages[:left] = pages[:all][0, options[:outer_window]]
79
+ pages[:right] = pages[:all][page_count - options[:outer_window], options[:outer_window]]
80
+ pages[:center] = case current_page
81
+ # allow the inner 'window' to shift to right when close to the left edge
82
+ # Ex: 1 2 [3] 4 5 6 7 8 9 ... 20
83
+ when -infinity .. (options[:inner_window] / 2) +3
84
+ pages[:all][options[:outer_window], options[:inner_window]] +
85
+ [options[:right_cut_label]]
86
+ # allow the inner 'window' to shift left when close to the right edge
87
+ # Ex: 1 2 ... 12 13 14 15 16 [17] 18 19 20
88
+ when (page_count - (options[:inner_window] / 2.0).ceil) -1 .. infinity
89
+ [options[:left_cut_label]] +
90
+ pages[:all][page_count - options[:inner_window] - options[:outer_window], options[:inner_window]]
91
+ # Display the unshifed window
92
+ # ex: 1 2 ... 5 6 7 [8] 9 10 11 ... 19 20
93
+ else
94
+ [options[:left_cut_label]] +
95
+ pages[:all][current_page - (options[:inner_window] / 2) -1, options[:inner_window]] +
96
+ [options[:right_cut_label]]
97
+ end
98
+ end
99
+
100
+ Builder::XmlMarkup.new.div(:class => options[:class]) do |b|
101
+ b.style {|s| s << %Q{
102
+ div.#{options[:class]} ul, div.#{options[:class]} ul li {
103
+ display: inline;
104
+ padding: 2px;
105
+ }
106
+ } } if options[:default_css]
107
+ # b << (current_page <= 1 ? options[:prev_label] : %Q{<a href="#{url}=#{current_page -1}">#{options[:prev_label]}</a>})
108
+
109
+ b.ul do
110
+ b.li(:class => current_page <= 1 ? 'previous-off' : 'previous') {
111
+ b << (current_page <= 1 ? options[:prev_label] : %Q{<a href="#{url}=#{current_page -1}">#{options[:prev_label]}</a>})
112
+ }
113
+ [pages[:left], pages[:center], pages[:right]].each do |p|
114
+ p.each do |page_number|
115
+ case page_number
116
+ when String
117
+ b.li(:class=>'more_marker') {|li| li << page_number}
118
+ when current_page
119
+ b.li(page_number, :class=>'current_page')
120
+ else
121
+ b.li { b.a(page_number, :href=>"#{url}=#{page_number}") }
122
+ end
123
+ end
124
+ end
125
+ b.li(:class => current_page >= page_count ? 'next-off' : 'next') {
126
+ b << (current_page >= page_count ? options[:next_label] : %Q{<a href="#{url}=#{current_page +1}">#{options[:next_label]}</a>})
127
+ }
128
+ end
129
+
130
+ # b << (current_page >= page_count ? options[:next_label] : %Q{<a href="#{url}=#{current_page +1}">#{options[:next_label]}</a>})
131
+ end
132
+ end
133
+ private
134
+ def infinity; 1.0/0; end
135
+ end
136
+ end
@@ -0,0 +1,9 @@
1
+ module MerbPagination
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: psq-merb-pagination
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Lori Holden, Pascal Belloncle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-06 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.7
23
+ version:
24
+ description: Merb plugin that provides access to the Ruby Xapian search engine library
25
+ email: email+gem@loriholden.com, psq@nanorails.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README.txt
32
+ - License.txt
33
+ - PostInstall.txt
34
+ - History.txt
35
+ files:
36
+ - README.txt
37
+ - License.txt
38
+ - PostInstall.txt
39
+ - History.txt
40
+ - Rakefile
41
+ - lib/merb-pagination.rb
42
+ - lib/merb-pagination/hash.rb
43
+ - lib/merb-pagination/pagination_helper.rb
44
+ - lib/merb-pagination/version.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/psq/merb-pagination
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: merb-pagination
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Merb plugin that provides indexing of datamapper models using the Ruby Xapian search engine library
71
+ test_files: []
72
+