pagify 0.7.1 → 0.8.0

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.
@@ -0,0 +1,2 @@
1
+ pkg
2
+ *.rbc
@@ -0,0 +1,3 @@
1
+ [submodule "task"]
2
+ path = task
3
+ url = git://github.com/godfat/gemgem.git
@@ -0,0 +1,78 @@
1
+ # CHANGES
2
+
3
+ ## pagify 0.8.0 / 2011-11-16
4
+
5
+ Adopt changes from @agios
6
+
7
+ * Setting `setting[:first_text]` to `nil` would make pagify
8
+ use page number as the first_text. The same goes to
9
+ `setting[:last_text]`
10
+
11
+ * Added a `<span class="pagination_active">` wrapper for active
12
+ page. You can change the class by changing `setting[:active_class]`
13
+
14
+ * Now links would by default contain `class="pagination_inactive"`.
15
+ You can also change the class name by changing `setting[:inactive_class]`
16
+ Set it to `nil` would disable this.
17
+
18
+ * Fixed a deprecation warning on activerecord 3.1.1
19
+
20
+ ## pagify 0.7.1 / 2010-04-26
21
+
22
+ * fix the problem that RUBY_VERSION is forzen,
23
+ just use lexical string comparsion then.
24
+
25
+ ## pagify 0.7.0 / 2009-11-16
26
+
27
+ * added innate helper.
28
+ * some internal refactoring
29
+
30
+ ## pagify 0.6.2 / 2009-08-08
31
+
32
+ * no joke now, use pagify_links instead of would_paginate.
33
+ * now you can define your own pagify_links and call super
34
+ in ApplicationHelper.
35
+ * added a links_type option for rails helper,
36
+ telling which html helper method you would like.
37
+ default to HTML#links_full
38
+
39
+ ## pagify 0.6.1 / 2009-07-30
40
+
41
+ * first rubyforge gem release!
42
+ * rearranged require call.
43
+ * use normal form for dir and module name
44
+ * removed pagify pager cache, it's not useful
45
+ * added rails helper (i.e. would_pagiante)
46
+ * fixed that NullPage from pagers other than NullPager,
47
+ it should always acts as an empty array.
48
+
49
+ ### Policy changed
50
+
51
+ null page was no longer a singleton. see reason below:
52
+
53
+ i encountered a strange problem, where:
54
+
55
+ pager[10].pager.per_page != pager[1].pager.per_page
56
+
57
+ because BasicPage#pager would refer to original pager,
58
+ while NullPage#pager would always refer to NullPager's singleton.
59
+
60
+ i think i should have not made NullPage be a singleton,
61
+ because we got have some way to keep page.pager.per_page
62
+ consist to the value we original setup. then we could write
63
+ something like this:
64
+
65
+ (0...page.pager.per_page).each{ ... }
66
+
67
+ that is, we don't have to keep pager around, and if you have
68
+ page, then you have pager. so now that NullPage was no longer
69
+ a singleton, and null_page.pager would return the original pager.
70
+
71
+ keep NullPager being a singleton though, and it should always
72
+ return the same page which refer the singleton null pager.
73
+
74
+ ## pagify 0.5 / 2008-10-11
75
+
76
+ * 1 major enhancement
77
+ * Birthday!
78
+ * extracted from Ludy::Paginator!
@@ -0,0 +1,2 @@
1
+ Lin Jen-Shin (godfat)
2
+ agios (agios)
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+
2
+ source 'http://rubygems.org'
3
+
4
+ gemspec
5
+
6
+ # datamapper
7
+ gem 'dm-core'
8
+ gem 'dm-aggregates'
9
+ gem 'dm-migrations'
10
+ gem 'dm-sqlite-adapter'
11
+
12
+ # rails
13
+ gem 'activerecord'
14
+ gem 'sqlite3'
@@ -0,0 +1,157 @@
1
+ # pagify
2
+
3
+ by Lin Jen-Shin ([godfat](http://godfat.org))
4
+
5
+ ## LINKS:
6
+
7
+ * [github](https://github.com/godfat/pagify)
8
+ * [rubygems](https://rubygems.org/gems/pagify)
9
+ * [rdoc](http://rdoc.info/github/godfat/pagify)
10
+
11
+ ## DESCRIPTION:
12
+
13
+ Pagination tools for Array(or custom class), DataMapper and ActiveRecord.
14
+ Helpers for Innate/Ramaze and Rails included.
15
+
16
+ ## REQUIREMENTS:
17
+
18
+ * Ruby 1.8+ or 1.9.1+
19
+ * For Basic/ArrayPager: only Ruby is needed
20
+ * For DataMapperPager: dm-core and dm-aggregates 1.2+
21
+ * for ActiveRecordPager: activerecord 2.3.14+ or activerecord 3.1+
22
+ * for Innate helper: innate 2011.10+
23
+
24
+ ## INSTALLATION:
25
+
26
+ gem install pagify
27
+
28
+ ## FEATURES:
29
+
30
+ * Aims to be as flexible as possible
31
+ * Separate intrusive "pagify" method and Array/DataMapper/ActiveRecord Pager.
32
+ * Separate view helpers. There's only html helper right now.
33
+ * Web framework specific helper included. Currently for Innate/Ramaze and Rails.
34
+
35
+ ## SYNOPSIS:
36
+
37
+ For fast Rails will_paginate replacement:
38
+
39
+ require 'pagify/active_record'
40
+ require 'pagify/helper/rails'
41
+
42
+ in controller:
43
+
44
+ @photos = Photo.pagify(:page => params[:page])
45
+
46
+ in view:
47
+
48
+ pagify_links(@photos)
49
+
50
+ For Innate/Ramaze:
51
+
52
+ require 'pagify'
53
+ require 'pagify/helper/innate'
54
+
55
+ in controller, say you want pagify helper:
56
+
57
+ class Controller < Ramaze::Controller
58
+ helper :pagify
59
+ end
60
+
61
+ for the data part, see `DataMapperPager` or `ActiveRecordPager` in view,
62
+ same as in Rails.
63
+
64
+ Basic DataMapper usage:
65
+
66
+ require 'pagify/data_mapper'
67
+
68
+ class User
69
+ include DataMapper::Resource
70
+ property :id, Serial
71
+ property :name, String
72
+ has n, :pets
73
+ end
74
+
75
+ class Pet
76
+ include DataMapper::Resource
77
+ property :id, Serial
78
+ property :name, String
79
+ belongs_to :user
80
+ end
81
+
82
+ User.pagify :page => 1, :per_page => 10 # => create a page contains users
83
+ User.all(:name => 'godfat').pagify # => create a page contains users named godfat
84
+
85
+ User.get(1).pets.pagify # => create a page contains pets owned by user 1
86
+
87
+ Basic html helper usage:
88
+
89
+ require 'pagify/helper/html'
90
+
91
+ Create a string with page links.
92
+
93
+ Pet.pagify.pager.html.links(params[:page]){ |page|
94
+ # the block result would be used as url for each page
95
+ "/pets/list?page=#{page}"
96
+ }
97
+
98
+ Pagify::Helper::HTML.setting[:prev_text] = '<]' # globally change html setting
99
+
100
+ If you would like to use instance level setting, you shouldn't use method
101
+ pagify, new your own DataMapperPager or so to remember instance level html
102
+ setting. for example, see below:
103
+
104
+ class Pet
105
+ # same as above
106
+ def self.page num
107
+ @pager ||= begin
108
+ pager = Pagify::DataMapperPager.new(:per_page => 20)
109
+ # below would be pager instance level setting
110
+ # you can setup global setting mentioned above in your init script perhaps
111
+ pager.html.setting[:separator] = ' . '
112
+ pager.html.setting[:ellipsis] = '...'
113
+ pager
114
+ end
115
+ @pager.page(num)
116
+ end
117
+ end
118
+
119
+ Then you would use `Pet.page(3)` or `user.pets.page(2)` to retrieve data.
120
+ This would create next/prev links only.
121
+
122
+ Pet.page(1).html.links_navigate{ |page|
123
+ "/pets/list?page=#{page}"
124
+ }
125
+
126
+ This would create next/prev links and other page links
127
+
128
+ pet_pager.page(1).html.links_full{ |page|
129
+ "/pets/show?page=#{page}"
130
+ }
131
+
132
+ and you can build your pager from scratch via BasicPager.
133
+ e.g. `BasicPager.new :fetcher => lambda{|*a|[]}, :counter => lambda{0}`
134
+ this would be similar to `Pagify::NullPager`.
135
+
136
+ You can disable null page via passing `:null_page => false` to any pager,
137
+ or set `pager.null_page = false` anytime.
138
+
139
+ See example or test for more examples (and use case for `ActiveRecordPager`).
140
+
141
+ ## LICENSE:
142
+
143
+ Apache License 2.0
144
+
145
+ Copyright (c) 2008-2011, Lin Jen-Shin (godfat)
146
+
147
+ Licensed under the Apache License, Version 2.0 (the "License");
148
+ you may not use this file except in compliance with the License.
149
+ You may obtain a copy of the License at
150
+
151
+ http://www.apache.org/licenses/LICENSE-2.0
152
+
153
+ Unless required by applicable law or agreed to in writing, software
154
+ distributed under the License is distributed on an "AS IS" BASIS,
155
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
156
+ See the License for the specific language governing permissions and
157
+ limitations under the License.
data/Rakefile CHANGED
@@ -1,37 +1,19 @@
1
1
  # encoding: utf-8
2
2
 
3
- begin
4
- require 'bones'
5
- rescue LoadError
6
- abort '### Please install the "bones" gem ###'
7
- end
8
-
9
- ensure_in_path 'lib'
10
- proj = 'pagify'
11
- require "#{proj}/version"
12
-
13
- Bones{
14
- version Pagify::VERSION
15
-
16
- ruby_opts [''] # silence warning, too many in addressable and/or dm-core
17
- depend_on 'dm-core', :development => true, :version => '>=0.10.1'
18
- depend_on 'dm-aggregates', :development => true, :version => '>=0.10.1'
19
- depend_on 'activerecord', :development => true, :version => '>=2.3.4'
3
+ require "#{dir = File.dirname(__FILE__)}/task/gemgem"
4
+ Gemgem.dir = dir
20
5
 
21
- name proj
22
- url "http://github.com/godfat/#{proj}"
23
- authors 'Lin Jen-Shin (aka godfat 真常)'
24
- email 'godfat (XD) godfat.org'
6
+ ($LOAD_PATH << File.expand_path("#{Gemgem.dir}/lib")).uniq!
25
7
 
26
- history_file 'CHANGES'
27
- readme_file 'README'
28
- ignore_file '.gitignore'
29
- rdoc.include ['\w+']
30
- }
8
+ desc 'Generate gemspec'
9
+ task 'gem:spec' do
10
+ Gemgem.spec = Gemgem.create do |s|
11
+ require 'pagify/version'
12
+ s.name = 'pagify'
13
+ s.version = Pagify::VERSION
31
14
 
32
- CLEAN.include Dir['**/*.rbc']
15
+ %w[].each{ |g| s.add_runtime_dependency(g) }
16
+ end
33
17
 
34
- task :default do
35
- Rake.application.options.show_task_pattern = /./
36
- Rake.application.display_tasks_and_comments
18
+ Gemgem.write
37
19
  end
@@ -1,10 +1,12 @@
1
- = pagify todo list
1
+ # TODO
2
+
3
+ ## 1.0-
2
4
 
3
- == 1.0-
4
5
  * more docs
5
6
  * remove would_paginate
6
7
 
7
- == 1.0+
8
+ ## 1.0+
9
+
8
10
  * default chinese html setting
9
11
  * cooperate with DataMapper::Collection,
10
12
  do user.pets.pagify work???
@@ -12,7 +12,7 @@ module Pagify
12
12
  end
13
13
 
14
14
  def [] key
15
- if @attributes[key]
15
+ if @attributes.key?(key)
16
16
  @attributes[key]
17
17
  else
18
18
  @parent[key]
@@ -20,12 +20,14 @@ module Pagify
20
20
  :ellipsis => '...',
21
21
  :query_name => :page,
22
22
  :links_type => :links_full,
23
- :wrapper_class => 'pagination' })
23
+ :inactive_class => 'pagination_inactive',
24
+ :active_class => 'pagination_active',
25
+ :wrapper_class => 'pagination' })
24
26
  end
25
27
 
26
28
  def links_full page, &block
27
29
  page = normalize_page(page)
28
- "#{links_navigate(page, &block)}<br />#{links(page, &block)}"
30
+ "#{links_navigate(page, &block)}<br/>#{links(page, &block)}"
29
31
  end
30
32
 
31
33
  def links_navigate page
@@ -51,21 +53,22 @@ module Pagify
51
53
  def links page
52
54
  page = normalize_page(page)
53
55
  size = pager.size
54
- attrs = extract_html_attributes
56
+ a = extract_html_attributes
55
57
 
56
58
  prepare_links(page).map{ |i|
57
59
  if i == page
58
60
  case page
59
- when 1; setting[:first_text]
60
- when size; setting[ :last_text]
61
- else; page
61
+ when 1 ; wrap_active(setting[:first_text] || i)
62
+ when size; wrap_active(setting[ :last_text] || i)
63
+ else ; wrap_active(i)
62
64
  end
63
65
  else
64
66
  case i
65
- when 1; "<a href=\"#{yield(i)}\"#{attrs}>#{setting[:first_text]}</a>"
66
- when size; "<a href=\"#{yield(i)}\"#{attrs}>#{setting[ :last_text]}</a>"
67
- when Fixnum; "<a href=\"#{yield(i)}\"#{attrs}>#{i}</a>"
68
- else; i.to_s
67
+ when 1 ; wrap_inactive(setting[:first_text] || i, a){yield(i)}
68
+ when size; wrap_inactive(setting[ :last_text] || i, a){yield(i)}
69
+ when Fixnum
70
+ wrap_inactive(i, a){yield(i)}
71
+ else ; i.to_s
69
72
  end
70
73
  end
71
74
  }.join(setting[:separator])
@@ -73,7 +76,9 @@ module Pagify
73
76
 
74
77
  private
75
78
  def extract_html_attributes
76
- attrs = setting.additional_attributes.
79
+ attrs = {:class => setting[:inactive_class]}.
80
+ merge(setting.additional_attributes).
81
+ select{ |_, value| value }.
77
82
  map{ |key, value| "#{key}=\"#{value}\"" }.join(' ')
78
83
 
79
84
  attrs = ' ' + attrs if attrs != ''
@@ -83,6 +88,14 @@ module Pagify
83
88
  def normalize_page page
84
89
  pager.__send__(:normalize_page, page)
85
90
  end
91
+
92
+ def wrap_active label
93
+ %Q{<span class="#{setting[:active_class]}">#{label}</span>}
94
+ end
95
+
96
+ def wrap_inactive label, attr
97
+ %Q{<a href="#{yield}"#{attr}>#{label}</a>}
98
+ end
86
99
  end # of HTML
87
100
  setup HTML
88
101
  end # of Helper
@@ -1,7 +1,13 @@
1
1
 
2
2
  require 'pagify/pagifier/abstract'
3
3
 
4
- [ActiveRecord::Base, ActiveRecord::Associations::AssociationCollection].each{ |klass|
4
+ proxy = if defined?(ActiveRecord::Associations::CollectionProxy)
5
+ ActiveRecord::Associations::CollectionProxy
6
+ else
7
+ ActiveRecord::Associations::AssociationCollection
8
+ end
9
+
10
+ [ActiveRecord::Base, proxy].each{ |klass|
5
11
  klass.module_eval do
6
12
  extend Pagify::Pagifier
7
13
  def self.pagify_pager_create model, opts
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Pagify
3
- VERSION = '0.7.1'
3
+ VERSION = '0.8.0'
4
4
  end
@@ -1,44 +1,84 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = %q{pagify}
5
- s.version = "0.7.0"
4
+ s.name = "pagify"
5
+ s.version = "0.8.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Lin Jen-Shin (aka godfat 真常)"]
9
- s.date = %q{2009-11-16}
10
- s.description = %q{ Pagination tools for Array(or custom class), DataMapper and ActiveRecord
11
- Helpers for Innate/Ramaze and Rails included.}
12
- s.email = %q{godfat (XD) godfat.org}
13
- s.extra_rdoc_files = ["CHANGES", "LICENSE", "NOTICE", "README", "TODO", "pagify.gemspec"]
14
- s.files = ["CHANGES", "LICENSE", "NOTICE", "README", "Rakefile", "TODO", "lib/pagify.rb", "lib/pagify/active_record.rb", "lib/pagify/array.rb", "lib/pagify/data_mapper.rb", "lib/pagify/helper/abstract.rb", "lib/pagify/helper/detail/setting.rb", "lib/pagify/helper/detail/setup.rb", "lib/pagify/helper/detail/web.rb", "lib/pagify/helper/html.rb", "lib/pagify/helper/innate.rb", "lib/pagify/helper/rails.rb", "lib/pagify/page/basic.rb", "lib/pagify/page/null.rb", "lib/pagify/pager/active_record.rb", "lib/pagify/pager/array.rb", "lib/pagify/pager/basic.rb", "lib/pagify/pager/data_mapper.rb", "lib/pagify/pager/detail/page_accept_string_or_blank.rb", "lib/pagify/pager/null.rb", "lib/pagify/pagifier/abstract.rb", "lib/pagify/pagifier/active_record.rb", "lib/pagify/pagifier/array.rb", "lib/pagify/pagifier/data_mapper.rb", "lib/pagify/version.rb", "pagify.gemspec", "spec/pagify_spec.rb", "spec/spec_helper.rb", "test/helper.rb", "test/helper_model.rb", "test/helper_pagify.rb", "test/helper_web.rb", "test/test_active_record.rb", "test/test_array.rb", "test/test_basic.rb", "test/test_data_mapper.rb", "test/test_html.rb", "test/test_innate.rb", "test/test_null.rb", "test/test_rails.rb"]
15
- s.homepage = %q{http://github.com/godfat/pagify}
16
- s.rdoc_options = ["--charset=utf-8", "--inline-source", "--line-numbers", "--promiscuous", "--main", "README"]
8
+ s.authors = ["Lin Jen-Shin (godfat)"]
9
+ s.date = "2011-11-16"
10
+ s.description = "Pagination tools for Array(or custom class), DataMapper and ActiveRecord.\nHelpers for Innate/Ramaze and Rails included."
11
+ s.email = ["godfat (XD) godfat.org"]
12
+ s.files = [
13
+ ".gitignore",
14
+ ".gitmodules",
15
+ "CHANGES.md",
16
+ "CONTRIBUTORS",
17
+ "Gemfile",
18
+ "LICENSE",
19
+ "README.md",
20
+ "Rakefile",
21
+ "TODO.md",
22
+ "lib/pagify.rb",
23
+ "lib/pagify/active_record.rb",
24
+ "lib/pagify/array.rb",
25
+ "lib/pagify/data_mapper.rb",
26
+ "lib/pagify/helper/abstract.rb",
27
+ "lib/pagify/helper/detail/setting.rb",
28
+ "lib/pagify/helper/detail/setup.rb",
29
+ "lib/pagify/helper/detail/web.rb",
30
+ "lib/pagify/helper/html.rb",
31
+ "lib/pagify/helper/innate.rb",
32
+ "lib/pagify/helper/rails.rb",
33
+ "lib/pagify/page/basic.rb",
34
+ "lib/pagify/page/null.rb",
35
+ "lib/pagify/pager/active_record.rb",
36
+ "lib/pagify/pager/array.rb",
37
+ "lib/pagify/pager/basic.rb",
38
+ "lib/pagify/pager/data_mapper.rb",
39
+ "lib/pagify/pager/detail/page_accept_string_or_blank.rb",
40
+ "lib/pagify/pager/null.rb",
41
+ "lib/pagify/pagifier/abstract.rb",
42
+ "lib/pagify/pagifier/active_record.rb",
43
+ "lib/pagify/pagifier/array.rb",
44
+ "lib/pagify/pagifier/data_mapper.rb",
45
+ "lib/pagify/version.rb",
46
+ "misc.txt",
47
+ "pagify.gemspec",
48
+ "task/.gitignore",
49
+ "task/gemgem.rb",
50
+ "test/helper.rb",
51
+ "test/helper_model.rb",
52
+ "test/helper_pagify.rb",
53
+ "test/helper_web.rb",
54
+ "test/test_active_record.rb",
55
+ "test/test_array.rb",
56
+ "test/test_basic.rb",
57
+ "test/test_data_mapper.rb",
58
+ "test/test_html.rb",
59
+ "test/test_innate.rb",
60
+ "test/test_null.rb",
61
+ "test/test_rails.rb"]
62
+ s.homepage = "https://github.com/godfat/pagify"
17
63
  s.require_paths = ["lib"]
18
- s.rubyforge_project = %q{ludy}
19
- s.rubygems_version = %q{1.3.5}
20
- s.summary = %q{Pagination tools for Array(or custom class), DataMapper and ActiveRecord Helpers for Innate/Ramaze and Rails included.}
21
- s.test_files = ["test/test_active_record.rb", "test/test_array.rb", "test/test_basic.rb", "test/test_data_mapper.rb", "test/test_html.rb", "test/test_innate.rb", "test/test_null.rb", "test/test_rails.rb"]
64
+ s.rubygems_version = "1.8.11"
65
+ s.summary = "Pagination tools for Array(or custom class), DataMapper and ActiveRecord."
66
+ s.test_files = [
67
+ "test/test_active_record.rb",
68
+ "test/test_array.rb",
69
+ "test/test_basic.rb",
70
+ "test/test_data_mapper.rb",
71
+ "test/test_html.rb",
72
+ "test/test_innate.rb",
73
+ "test/test_null.rb",
74
+ "test/test_rails.rb"]
22
75
 
23
76
  if s.respond_to? :specification_version then
24
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
77
  s.specification_version = 3
26
78
 
27
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- s.add_development_dependency(%q<bones>, [">= 2.5.1"])
29
- s.add_development_dependency(%q<dm-core>, [">= 0.10.1"])
30
- s.add_development_dependency(%q<dm-aggregates>, [">= 0.10.1"])
31
- s.add_development_dependency(%q<activerecord>, [">= 2.3.4"])
79
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
32
80
  else
33
- s.add_dependency(%q<bones>, [">= 2.5.1"])
34
- s.add_dependency(%q<dm-core>, [">= 0.10.1"])
35
- s.add_dependency(%q<dm-aggregates>, [">= 0.10.1"])
36
- s.add_dependency(%q<activerecord>, [">= 2.3.4"])
37
81
  end
38
82
  else
39
- s.add_dependency(%q<bones>, [">= 2.5.1"])
40
- s.add_dependency(%q<dm-core>, [">= 0.10.1"])
41
- s.add_dependency(%q<dm-aggregates>, [">= 0.10.1"])
42
- s.add_dependency(%q<activerecord>, [">= 2.3.4"])
43
83
  end
44
84
  end