heedley-heedley-merb-pagination 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-08-19
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -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.
@@ -0,0 +1,22 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/merb-pagination.rb
9
+ lib/merb-pagination/hash.rb
10
+ lib/merb-pagination/pagination_helper.rb
11
+ lib/merb-pagination/version.rb
12
+ script/console
13
+ script/destroy
14
+ script/generate
15
+ script/txt2html
16
+ setup.rb
17
+ tasks/deployment.rake
18
+ tasks/environment.rake
19
+ tasks/website.rake
20
+ test/test_helper.rb
21
+ test/test_merb-pagination.rb
22
+ merb-pagination.gemspec
@@ -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.
@@ -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,72 @@
1
+ require 'merb-pagination/version'
2
+
3
+ AUTHOR = 'Lori Holden'
4
+ EMAIL = "email+gem@loriholden.com"
5
+ DESCRIPTION = "A pagination helper for merb"
6
+ GEM_NAME = 'merb-pagination'
7
+ RUBYFORGE_PROJECT = 'merb-pagination'
8
+ HOMEPATH = "http://merb-pagination.rubyforge.org/"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ ['merb-core', '>= 0.9.4'],
12
+ ['builder', '>= 2.0.0']
13
+ ]
14
+
15
+ @config_file = "~/.rubyforge/user-config.yml"
16
+ @config = nil
17
+ RUBYFORGE_USERNAME = "lholden"
18
+ def rubyforge_username
19
+ unless @config
20
+ begin
21
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
22
+ rescue
23
+ puts <<-EOS
24
+ ERROR: No rubyforge config file found: #{@config_file}
25
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
26
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
27
+ EOS
28
+ exit
29
+ end
30
+ end
31
+ RUBYFORGE_USERNAME.replace @config["username"]
32
+ end
33
+
34
+
35
+ REV = nil
36
+ VERS = MerbPagination::VERSION::STRING + (REV ? ".#{REV}" : "")
37
+ RDOC_OPTS = ['--quiet', '--title', 'merb_pagination documentation',
38
+ "--opname", "index.html",
39
+ "--line-numbers",
40
+ "--main", "README",
41
+ "--inline-source"]
42
+
43
+ class Hoe
44
+ def extra_deps
45
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
46
+ @extra_deps
47
+ end
48
+ end
49
+
50
+ # Generate all the Rake tasks
51
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
52
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
53
+ p.developer(AUTHOR, EMAIL)
54
+ p.description = DESCRIPTION
55
+ p.summary = DESCRIPTION
56
+ p.url = HOMEPATH
57
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
58
+ p.test_globs = ["test/**/test_*.rb"]
59
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
60
+
61
+ # == Optional
62
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
63
+ p.extra_deps = EXTRA_DEPENDENCIES
64
+
65
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
66
+ end
67
+
68
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
70
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
71
+ $hoe.rsync_args = '-av --delete --ignore-errors'
72
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -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,206 @@
1
+ require 'builder'
2
+ module Merb
3
+ module PaginationHelper
4
+ # paginate + some route parameters to generate more complex routes that
5
+ # let me avoid loathsome querystrings ;)
6
+ def paginate_with_route(current_page, page_count, route_name, params_for_route = {}, options = {})
7
+ options.reverse_merge!({
8
+ :class => 'paginated',
9
+ :prev_label => '&laquo; Previous ',
10
+ :next_label => ' Next &raquo;',
11
+ :left_cut_label => '&larr;',
12
+ :right_cut_label => '&rarr;',
13
+ :outer_window => 2,
14
+ :inner_window => 10,
15
+ :default_css => true,
16
+ :page_param => 'page'
17
+ })
18
+
19
+ pages = {
20
+ :all => (1 .. page_count).to_a,
21
+ :left => [],
22
+ :center => [],
23
+ :right => []
24
+ }
25
+
26
+ # Only worry about using our 'windows' if the page count is less then
27
+ # our windows combined.
28
+ if options[:inner_window].nil? or ((options[:outer_window] *2) + options[:inner_window] + 2) >= page_count
29
+ pages[:center] = pages[:all]
30
+ else
31
+ pages[:left] = pages[:all][0, options[:outer_window]]
32
+ pages[:right] = pages[:all][page_count - options[:outer_window], options[:outer_window]]
33
+ pages[:center] = case current_page
34
+ # allow the inner 'window' to shift to right when close to the left edge
35
+ # Ex: 1 2 [3] 4 5 6 7 8 9 ... 20
36
+ when -infinity .. (options[:inner_window] / 2) +3
37
+ pages[:all][options[:outer_window], options[:inner_window]] +
38
+ [options[:right_cut_label]]
39
+ # allow the inner 'window' to shift left when close to the right edge
40
+ # Ex: 1 2 ... 12 13 14 15 16 [17] 18 19 20
41
+ when (page_count - (options[:inner_window] / 2.0).ceil) -1 .. infinity
42
+ [options[:left_cut_label]] +
43
+ pages[:all][page_count - options[:inner_window] - options[:outer_window], options[:inner_window]]
44
+ # Display the unshifed window
45
+ # ex: 1 2 ... 5 6 7 [8] 9 10 11 ... 19 20
46
+ else
47
+ [options[:left_cut_label]] +
48
+ pages[:all][current_page - (options[:inner_window] / 2) -1, options[:inner_window]] +
49
+ [options[:right_cut_label]]
50
+ end
51
+ end
52
+
53
+ Builder::XmlMarkup.new.div(:class => options[:class]) do |b|
54
+ b.style {|s| s << %Q{
55
+ div.#{options[:class]} ul, div.#{options[:class]} ul li {
56
+ display: inline;
57
+ padding: 2px;
58
+ }
59
+ } } if options[:default_css]
60
+ b << (current_page <= 1 ? options[:prev_label] : link_to(options[:prev_label],url(route_name, params_for_route.merge(:page => current_page - 1))) )
61
+
62
+ b.ul do
63
+ [pages[:left], pages[:center], pages[:right]].each do |p|
64
+ p.each do |page_number|
65
+ case page_number
66
+ when String
67
+ b.li(:class=>'more_marker') {|li| li << page_number}
68
+ when current_page
69
+ b.li(page_number, :class=>'current_page')
70
+ else
71
+ b.li { b.a(page_number, :href=> url(route_name, params_for_route.merge(:page => page_number)) ) }
72
+ end
73
+ end
74
+ end
75
+ end
76
+ b << (current_page >= page_count ? options[:next_label] : link_to(options[:next_label],url(route_name, params_for_route.merge(:page => current_page + 1))) )
77
+ end
78
+ end
79
+
80
+ # Given a page count and the current page, we generate a set of pagination
81
+ # links.
82
+ #
83
+ # * We use an inner and outer window into a list of links. For a set of
84
+ # 20 pages with the current page being 10:
85
+ # outer_window:
86
+ # 1 2 ..... 19 20
87
+ # inner_window
88
+ # 5 6 7 8 9 10 11 12 13 14
89
+ #
90
+ # This is totally adjustable, or can be turned off by giving the
91
+ # :inner_window setting a value of nil.
92
+ #
93
+ # * Options
94
+ # :class => <em>css_class</em::
95
+ # The CSS class to be given to the paginator div.
96
+ # Defaults to 'paginated'
97
+ # :prev_label => <em>text_for_previous_link</em>::
98
+ # Defaults to '&laquo; Previous '
99
+ # :next_labe => <em>text_for_next_link</em>::
100
+ # Defaults to ' Next &raquo;'
101
+ # :left_cut_label => <em>text_for_cut</em>::
102
+ # Used when the page numbers need to be cut off to prevent the set of
103
+ # pagination links from being too long.
104
+ # Defaults to '&larr;'
105
+ # :right_cut_label => <em>text_for_cut</em>::
106
+ # Same as :left_cut_label but for the right side of numbers.
107
+ # Defaults to '&rarr;'
108
+ # :outer_window => <em>number_of_pages</em>::
109
+ # Sets the number of pages to include in the outer 'window'
110
+ # Defaults to 2
111
+ # :inner_window => <em>number_of_pages</em>::
112
+ # Sets the number of pags to include in the inner 'window'
113
+ # Defaults to 10
114
+ # :default_css => <em>use_paginator_provided_css</em>
115
+ # Use the default CSS provided by the paginator. If you want to do
116
+ # your own custom styling of the paginator from scratch, set this to
117
+ # false.
118
+ # Defaults to true
119
+ # :page_param => <em>name_of_page_paramiter</em>
120
+ # Sets the name of the paramiter the paginator uses to return what
121
+ # page is being requested.
122
+ # Defaults to 'page'
123
+ # :url => <em>url_for_links</em>
124
+ # Provides the base url to use in the page navigation links.
125
+ # Defaults to ''
126
+ def paginate(current_page, page_count, options = {})
127
+ options.reverse_merge!({
128
+ :class => 'paginated',
129
+ :prev_label => '&laquo; Previous ',
130
+ :next_label => ' Next &raquo;',
131
+ :left_cut_label => '&larr;',
132
+ :right_cut_label => '&rarr;',
133
+ :outer_window => 2,
134
+ :inner_window => 10,
135
+ :default_css => true,
136
+ :page_param => 'page',
137
+ :url => ''
138
+ })
139
+ url = options.delete :url
140
+ url << (url.include?('?') ? '&' : '?') << options[:page_param]
141
+
142
+ pages = {
143
+ :all => (1 .. page_count).to_a,
144
+ :left => [],
145
+ :center => [],
146
+ :right => []
147
+ }
148
+
149
+ # Only worry about using our 'windows' if the page count is less then
150
+ # our windows combined.
151
+ if options[:inner_window].nil? or ((options[:outer_window] *2) + options[:inner_window] + 2) >= page_count
152
+ pages[:center] = pages[:all]
153
+ else
154
+ pages[:left] = pages[:all][0, options[:outer_window]]
155
+ pages[:right] = pages[:all][page_count - options[:outer_window], options[:outer_window]]
156
+ pages[:center] = case current_page
157
+ # allow the inner 'window' to shift to right when close to the left edge
158
+ # Ex: 1 2 [3] 4 5 6 7 8 9 ... 20
159
+ when -infinity .. (options[:inner_window] / 2) +3
160
+ pages[:all][options[:outer_window], options[:inner_window]] +
161
+ [options[:right_cut_label]]
162
+ # allow the inner 'window' to shift left when close to the right edge
163
+ # Ex: 1 2 ... 12 13 14 15 16 [17] 18 19 20
164
+ when (page_count - (options[:inner_window] / 2.0).ceil) -1 .. infinity
165
+ [options[:left_cut_label]] +
166
+ pages[:all][page_count - options[:inner_window] - options[:outer_window], options[:inner_window]]
167
+ # Display the unshifed window
168
+ # ex: 1 2 ... 5 6 7 [8] 9 10 11 ... 19 20
169
+ else
170
+ [options[:left_cut_label]] +
171
+ pages[:all][current_page - (options[:inner_window] / 2) -1, options[:inner_window]] +
172
+ [options[:right_cut_label]]
173
+ end
174
+ end
175
+
176
+ Builder::XmlMarkup.new.div(:class => options[:class]) do |b|
177
+ b.style {|s| s << %Q{
178
+ div.#{options[:class]} ul, div.#{options[:class]} ul li {
179
+ display: inline;
180
+ padding: 2px;
181
+ }
182
+ } } if options[:default_css]
183
+ b << (current_page <= 1 ? options[:prev_label] : %Q{<a href="#{url}=#{current_page -1}">#{options[:prev_label]}</a>})
184
+
185
+ b.ul do
186
+ [pages[:left], pages[:center], pages[:right]].each do |p|
187
+ p.each do |page_number|
188
+ case page_number
189
+ when String
190
+ b.li(:class=>'more_marker') {|li| li << page_number}
191
+ when current_page
192
+ b.li(page_number, :class=>'current_page')
193
+ else
194
+ b.li { b.a(page_number, :href=>"#{url}=#{page_number}") }
195
+ end
196
+ end
197
+ end
198
+ end
199
+
200
+ b << (current_page >= page_count ? options[:next_label] : %Q{<a href="#{url}=#{current_page +1}">#{options[:next_label]}</a>})
201
+ end
202
+ end
203
+ private
204
+ def infinity; 1.0/0; end
205
+ end
206
+ end
@@ -0,0 +1,9 @@
1
+ module MerbPagination
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,72 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{heedley-merb-pagination}
3
+ s.version = "0.0.1"
4
+ s.date = %q{2008-12-10}
5
+ s.summary = %q{A pagination helper for merb. Useful with dm-is-paginated}
6
+ s.email = "hedley.robertson@gmail.com"
7
+ s.homepage = %q{http://github.com/heedley/merb-pagination/tree/master}
8
+ s.require_paths = ["lib"]
9
+ s.description = %q{fork of lholden's merb-pagination}
10
+ s.has_rdoc = true
11
+ s.authors = ["Lori Holden", "Hedley Robertson"]
12
+
13
+
14
+ s.files = ["History.txt",
15
+ "License.txt",
16
+ "Manifest.txt",
17
+ "README.txt",
18
+ "Rakefile",
19
+ "config/hoe.rb",
20
+ "config/requirements.rb",
21
+ "lib/merb-pagination.rb",
22
+ "lib/merb-pagination/hash.rb",
23
+ "lib/merb-pagination/pagination_helper.rb",
24
+ "lib/merb-pagination/version.rb",
25
+ "script/console",
26
+ "script/destroy",
27
+ "script/generate",
28
+ "script/txt2html",
29
+ "setup.rb",
30
+ "tasks/deployment.rake",
31
+ "tasks/environment.rake",
32
+ "tasks/website.rake",
33
+ "test/test_helper.rb",
34
+ "test/test_merb-pagination.rb",
35
+ "merb-pagination.gemspec"]
36
+
37
+ s.test_files = ["test/test_merb-pagination.rb"]
38
+ s.rdoc_options = ["--main", "README.txt"]
39
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
40
+ s.add_dependency(%q<merb-core>, [">= 0.9"])
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 2
44
+ end
45
+ end
46
+
47
+ #
48
+ #Gem::Specification.new do |s|
49
+ # s.name = %q{heedley-merb-pagination}
50
+ # s.version = "0.0.1"
51
+ #
52
+ # s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
53
+ # s.authors = ["Lori Holden", "Hedley Robertson"]
54
+ # s.autorequire = %q{merb-pagination}
55
+ # s.date = %q{2008-12-10}
56
+ # s.description = %q{fork of lholden's merb-pagination}
57
+ # s.email = %q{nathan@myobie.com}
58
+ #
59
+ # s.extra_rdoc_files = ["README.txt", "License.txt"]
60
+ # s.files = ["lib/merb-pagination/pagination_helper.rb","lib/merb-pagination/hash.rb","lib/merb-pagination/version.rb","lib/merb-pagination.rb", "History.txt", "PostInstall.txt", "License.txt", "Manifest.txt", "Rakefile", "setup.rb", "merb-pagination.gemspec", "lib", "tasks", "test","tasks/deployment.rake","tasks/website.rake","tasks/environment.rake","test/test_merb-pagination.rb","test/test_helper.rb"]
61
+ # s.has_rdoc = true
62
+ # s.homepage = %q{http://github.com/heedley/merb-pagination/tree/master}
63
+ # s.require_paths = ["lib"]
64
+ # s.rubygems_version = %q{0.0.1}
65
+ # s.summary = %q{A pagination helper for merb. Useful with dm-is-paginated}
66
+ #
67
+ # if s.respond_to? :specification_version then
68
+ # current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
69
+ # s.specification_version = 2
70
+ # s.add_runtime_dependency(%q<merb-core>, [">= 0.9"])
71
+ # end
72
+ #end