pagify 0.6.2 → 0.7.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.
data/CHANGES CHANGED
@@ -1,6 +1,8 @@
1
1
  = pagify changes history
2
2
 
3
- == pagify 1.0 / ?
3
+ == pagify 0.7.0 / 2009-11-16
4
+ * added innate helper.
5
+ * some internal refactoring
4
6
 
5
7
  == pagify 0.6.2 / 2009-08-08
6
8
  * no joke now, use pagify_links instead of would_paginate.
data/README CHANGED
@@ -120,7 +120,7 @@ by Lin Jen-Shin (aka godfat-真常[http://godfat.org])
120
120
 
121
121
  Apache License 2.0
122
122
 
123
- Copyright (c) 2008, Lin Jen-Shin (aka godfat 真常)
123
+ Copyright (c) 2008-2009, Lin Jen-Shin (aka godfat 真常)
124
124
 
125
125
  Licensed under the Apache License, Version 2.0 (the "License");
126
126
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ SUDO = '' # this prevent `rake gem:install` to use sudo
4
+
3
5
  require 'bones'
4
6
  Bones.setup
5
7
 
@@ -0,0 +1,18 @@
1
+
2
+ require 'pagify/helper/html'
3
+
4
+ module Pagify
5
+ module Helper
6
+ module Web
7
+ def pagify_links objs, opts
8
+ html = objs.pager.html
9
+ name = html.setting[:query_name]
10
+ type = html.setting[:links_type]
11
+ base = opts[:path].call
12
+ "<div class=\"#{html.setting[:wrapper_class]}\">" +
13
+ html.send(type, opts[:page][name]){ |p| base + "?#{name}=#{p}" } +
14
+ '</div>'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -17,7 +17,10 @@ module Pagify
17
17
  :outer_links => 2,
18
18
  # :step => 3,
19
19
  :separator => ' ',
20
- :ellipsis => '...' })
20
+ :ellipsis => '...',
21
+ :query_name => :page,
22
+ :links_type => :links_full,
23
+ :wrapper_class => 'pagination' })
21
24
  end
22
25
 
23
26
  def links_full page, &block
@@ -0,0 +1,16 @@
1
+
2
+ require 'pagify/helper/detail/web'
3
+
4
+ module Pagify::Helper::Innate
5
+ include Pagify::Helper::Web
6
+ def pagify_links objs, &path
7
+ super(objs, :path => lambda{ block_given? ? path.call : request.path },
8
+ :page => lambda{ |name| request[name] })
9
+ end
10
+ end
11
+
12
+ module Innate
13
+ module Helper
14
+ Pagify = Pagify::Helper::Innate
15
+ end
16
+ end
@@ -1,32 +1,16 @@
1
1
 
2
- require 'pagify/helper/html'
2
+ require 'pagify/helper/detail/web'
3
3
 
4
4
  module Pagify::Helper::Rails
5
- def default_attributes
6
- super.merge(:query_name => :page, :wrapper_class => 'pagination',
7
- :links_type => :links_full)
5
+ include Pagify::Helper::Web
6
+ def pagify_links objs, &path
7
+ super(objs, :path => lambda{ block_given? ? path.call : request.path },
8
+ :page => lambda{ |name| params[name] })
8
9
  end
9
10
 
10
- module ApplicationHelper
11
- def pagify_links objs, &path
12
- path = lambda{ request.path } unless block_given?
13
- html = objs.pager.html
14
- name = html.setting[:query_name]
15
- type = html.setting[:links_type]
16
- base = path.call
17
- "<div class=\"#{html.setting[:wrapper_class]}\">" +
18
- html.send(type, params[name]){ |p| base + "?#{name}=#{p}" } +
19
- '</div>'
20
- end
21
-
22
- alias_method :would_paginate, :pagify_links
23
- end
24
- end
25
-
26
- class Pagify::Helper::HTML
27
- extend Pagify::Helper::Rails
11
+ alias_method :would_paginate, :pagify_links
28
12
  end
29
13
 
30
14
  module ApplicationHelper
31
- include Pagify::Helper::Rails::ApplicationHelper
15
+ include Pagify::Helper::Rails
32
16
  end
@@ -9,18 +9,27 @@ module Pagify
9
9
 
10
10
  def initialize model_class, opts = {}, query = {}
11
11
  @model = model_class
12
- query ||= {}
13
12
  query_opts = reject_pager_opts(opts)
14
13
 
15
14
  super(opts.merge(
16
15
  :fetcher => lambda{ |offset, per_page|
17
- model.send :with_scope, query do
16
+ # TODO: i am not sure why do we need this check?
17
+ if query == model.query
18
18
  model.all(query_opts.merge(:offset => offset, :limit => per_page))
19
+ else
20
+ model.send(:with_scope, query) do
21
+ model.all(query_opts.merge(:offset => offset, :limit => per_page))
22
+ end
19
23
  end
20
24
  },
21
25
  :counter => lambda{
22
- model.send :with_scope, query do
26
+ # TODO: i am not sure why do we need this check?
27
+ if query == model.query
23
28
  model.count(query_opts)
29
+ else
30
+ model.send(:with_scope, query) do
31
+ model.count(query_opts)
32
+ end
24
33
  end
25
34
  }))
26
35
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Pagify
3
- VERSION = '0.6.2'
3
+ VERSION = '0.7.0'
4
4
  end
@@ -2,22 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{pagify}
5
- s.version = "0.6.2"
5
+ s.version = "0.7.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 \347\234\237\345\270\270)"]
9
- s.date = %q{2009-08-08}
8
+ s.authors = ["Lin Jen-Shin (aka godfat 真常)"]
9
+ s.date = %q{2009-11-16}
10
10
  s.description = %q{ Pagination tools for Array(or custom class), DataMapper and ActiveRecord}
11
11
  s.email = %q{godfat (XD) godfat.org}
12
12
  s.extra_rdoc_files = ["CHANGES", "LICENSE", "NOTICE", "README", "TODO", "pagify.gemspec"]
13
- 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/html.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/test_active_record.rb", "test/test_array.rb", "test/test_basic.rb", "test/test_data_mapper.rb", "test/test_html.rb", "test/test_null.rb", "test/test_rails.rb"]
13
+ 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"]
14
14
  s.homepage = %q{http://github.com/godfat/pagify}
15
15
  s.rdoc_options = ["--charset=utf-8", "--inline-source", "--line-numbers", "--promiscuous", "--main", "README"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{ludy}
18
18
  s.rubygems_version = %q{1.3.5}
19
19
  s.summary = %q{Pagination tools for Array(or custom class), DataMapper and ActiveRecord}
20
- 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_null.rb", "test/test_rails.rb"]
20
+ 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"]
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -79,7 +79,7 @@ class GemPackageTask < Rake::PackageTask
79
79
  end
80
80
  end
81
81
  end
82
-
82
+
83
83
  def gem_file
84
84
  if @gem_spec.platform == Gem::Platform::RUBY
85
85
  "#{package_name}.gem"
@@ -6,7 +6,7 @@ require 'fileutils'
6
6
  require 'ostruct'
7
7
  require 'find'
8
8
 
9
- class OpenStruct; undef :gem if defined? :gem; end
9
+ class OpenStruct; undef :gem if defined? :gem; end
10
10
 
11
11
  # TODO: make my own openstruct type object that includes descriptions
12
12
  # TODO: use the descriptions to output help on the available bones options
@@ -251,7 +251,7 @@ def manifest
251
251
  files = []
252
252
  exclude = PROJ.exclude.dup
253
253
  comment = %r/^\s*#/
254
-
254
+
255
255
  # process the ignore file and add the items there to the exclude list
256
256
  if test(?f, PROJ.ignore_file)
257
257
  ary = []
@@ -32,7 +32,7 @@ namespace :spec do
32
32
  t.rcov_opts = PROJ.rcov.opts + ['--exclude', 'spec']
33
33
  end
34
34
 
35
- RCov::VerifyTask.new(:verify) do |t|
35
+ RCov::VerifyTask.new(:verify) do |t|
36
36
  t.threshold = PROJ.rcov.threshold
37
37
  t.index_html = File.join(PROJ.rcov.dir, 'index.html')
38
38
  t.require_exact_threshold = PROJ.rcov.threshold_exact
@@ -34,7 +34,7 @@ namespace :svn do
34
34
 
35
35
  puts "Creating SVN tag '#{tag}'"
36
36
  unless system "svn cp -m '#{msg}' #{trunk} #{tag}"
37
- abort "Tag creation failed"
37
+ abort "Tag creation failed"
38
38
  end
39
39
  end
40
40
 
@@ -11,8 +11,6 @@ TestCase = begin
11
11
  end
12
12
 
13
13
  require 'pagify'
14
- #gem 'dm-core', '<0.10'
15
- #gem 'dm-aggregates', '<0.10'
16
14
  require 'dm-core'
17
15
  require 'dm-aggregates'
18
16
  require 'active_record'
@@ -22,7 +22,7 @@ module SuiteForModel
22
22
  assert_equal 1, users.page
23
23
  assert_equal send(:User).first, users.first
24
24
  assert_equal 2, users.size
25
- assert_equal send(:User).first(:offset => 2, :limit => 1), users.next.first
25
+ assert_equal send(:User).first(:offset => 2), users.next.first
26
26
  assert_equal 1, users.next.size
27
27
  assert_equal Pagify::NullPage.new(users.pager), users.next.next
28
28
  end
@@ -65,19 +65,4 @@ module SuiteForModel
65
65
  end
66
66
  end
67
67
 
68
- # include Extlib::Hook
69
- #
70
- # private
71
- # def i_give_up
72
- # if self.class == TestActiveRecord
73
- # skip "it's toooooo hard to implement this for active record!! patch wanted!"
74
- # end
75
- # end
76
- #
77
- # [:test_same_pager_with_same_opts,
78
- # :test_page_correctness,
79
- # :test_condition_chain].each{ |test|
80
- # before test.to_sym, :i_give_up
81
- # }
82
-
83
68
  end
@@ -1,5 +1,5 @@
1
1
 
2
- class TestPagify < TestCase
2
+ module PagifyCase
3
3
  def self.data; @data ||= (0..100).to_a; end
4
4
  def for_pager pager
5
5
  # assume data.size is 101, data is [0,1,2,3...]
@@ -0,0 +1,23 @@
1
+
2
+ module WebCase
3
+ def setup
4
+ @data = (0..9).to_a.pagify(:per_page => 2, :page => 3)
5
+ end
6
+
7
+ def test_query_name
8
+ assert_equal(:page, Pagify::Helper::HTML.setting[:query_name])
9
+ assert_equal(:page, Pagify::ArrayPager.new([]).html.setting[:query_name])
10
+ end
11
+
12
+ def test_pagify_links
13
+ assert_equal('<div class="pagination"><a href="/a/b?page=2">&lt; Previous</a> <a href="/a/b?page=4">Next &gt;</a><br /><a href="/a/b?page=1">&laquo; First</a> <a href="/a/b?page=2">2</a> 3 <a href="/a/b?page=4">4</a> <a href="/a/b?page=5">Last &raquo;</a></div>', pagify_links(@data))
14
+
15
+ @data.pager.html.setting[:links_type] = :links
16
+
17
+ assert_equal('<div class="pagination"><a href="/a/b?page=1">&laquo; First</a> <a href="/a/b?page=2">2</a> 3 <a href="/a/b?page=4">4</a> <a href="/a/b?page=5">Last &raquo;</a></div>', pagify_links(@data))
18
+ end
19
+
20
+ def test_custom_path
21
+ assert_equal('<div class="pagination"><a href="XD?page=2">&lt; Previous</a> <a href="XD?page=4">Next &gt;</a><br /><a href="XD?page=1">&laquo; First</a> <a href="XD?page=2">2</a> 3 <a href="XD?page=4">4</a> <a href="XD?page=5">Last &raquo;</a></div>', pagify_links(@data){'XD'})
22
+ end
23
+ end
@@ -5,7 +5,8 @@ require 'test/helper_model'
5
5
 
6
6
  require 'pagify/active_record'
7
7
 
8
- class TestActiveRecord < TestPagify
8
+ class TestActiveRecord < TestCase
9
+ include PagifyCase
9
10
  def test_for_active_record
10
11
  for_pager Pagify::ActiveRecordPager.new(Topic)
11
12
  end
@@ -16,7 +17,7 @@ class TestActiveRecord < TestPagify
16
17
  101
17
18
  end
18
19
  def find all, opts = {}
19
- TestPagify.data[opts[:offset], opts[:limit]]
20
+ PagifyCase.data[opts[:offset], opts[:limit]]
20
21
  end
21
22
  end
22
23
  end
@@ -2,7 +2,8 @@
2
2
  require 'test/helper'
3
3
  require 'test/helper_pagify'
4
4
 
5
- class TestArray < TestPagify
5
+ class TestArray < TestCase
6
+ include PagifyCase
6
7
  def test_offset_bug
7
8
  a = (0..9).to_a
8
9
  pager = Pagify::ArrayPager.new a
@@ -13,7 +14,7 @@ class TestArray < TestPagify
13
14
  end
14
15
 
15
16
  def test_for_array
16
- for_pager Pagify::ArrayPager.new(TestPagify.data)
17
+ for_pager Pagify::ArrayPager.new(PagifyCase.data)
17
18
  end
18
19
 
19
20
  end
@@ -2,18 +2,19 @@
2
2
  require 'test/helper'
3
3
  require 'test/helper_pagify'
4
4
 
5
- class TestBasic < TestPagify
5
+ class TestBasic < TestCase
6
+ include PagifyCase
6
7
  def test_basic
7
8
  pager = Pagify::BasicPager.new(
8
9
  :fetcher => lambda{ |offset, per_page|
9
10
  # if for rails,
10
11
  # Data.find :all, :offset => offset, :limit => per_page
11
- TestPagify.data[offset, per_page]
12
+ PagifyCase.data[offset, per_page]
12
13
  },
13
14
  :counter => lambda{
14
15
  # if for rails,
15
16
  # Data.count
16
- TestPagify.data.size
17
+ PagifyCase.data.size
17
18
  })
18
19
 
19
20
  for_pager pager
@@ -5,7 +5,8 @@ require 'test/helper_model'
5
5
 
6
6
  require 'pagify/data_mapper'
7
7
 
8
- class TestDataMapper < TestPagify
8
+ class TestDataMapper < TestCase
9
+ include PagifyCase
9
10
  def test_for_data_mapper
10
11
  for_pager Pagify::DataMapperPager.new(Topic)
11
12
  end
@@ -16,10 +17,10 @@ class TestDataMapper < TestPagify
16
17
  101
17
18
  end
18
19
  def all opts = {}
19
- TestPagify.data[opts[:offset], opts[:limit]]
20
+ PagifyCase.data[opts[:offset], opts[:limit]]
20
21
  end
21
22
  def query
22
- nil
23
+ {}
23
24
  end
24
25
  private
25
26
  def with_scope query
@@ -0,0 +1,13 @@
1
+
2
+ require 'test/helper'
3
+ require 'test/helper_web'
4
+ require 'pagify/helper/innate'
5
+
6
+ class TestInnate < TestCase
7
+ include WebCase
8
+ include Innate::Helper::Pagify
9
+ # fake
10
+ def request
11
+ Struct.new(:path, :page).new('/a/b', 3)
12
+ end
13
+ end
@@ -1,9 +1,10 @@
1
1
 
2
2
  require 'test/helper'
3
- require 'pagify/array'
3
+ require 'test/helper_web'
4
4
  require 'pagify/helper/rails'
5
5
 
6
6
  class TestRails < TestCase
7
+ include WebCase
7
8
  include ApplicationHelper
8
9
  # fake
9
10
  def request
@@ -12,25 +13,4 @@ class TestRails < TestCase
12
13
  def params
13
14
  {:page => 3}
14
15
  end
15
-
16
- def setup
17
- @data = (0..9).to_a.pagify(:per_page => 2, :page => 3)
18
- end
19
-
20
- def test_query_name
21
- assert_equal(:page, Pagify::Helper::HTML.setting[:query_name])
22
- assert_equal(:page, Pagify::ArrayPager.new([]).html.setting[:query_name])
23
- end
24
-
25
- def test_would_paginate
26
- assert_equal('<div class="pagination"><a href="/a/b?page=2">&lt; Previous</a> <a href="/a/b?page=4">Next &gt;</a><br /><a href="/a/b?page=1">&laquo; First</a> <a href="/a/b?page=2">2</a> 3 <a href="/a/b?page=4">4</a> <a href="/a/b?page=5">Last &raquo;</a></div>', pagify_links(@data))
27
-
28
- @data.pager.html.setting[:links_type] = :links
29
-
30
- assert_equal('<div class="pagination"><a href="/a/b?page=1">&laquo; First</a> <a href="/a/b?page=2">2</a> 3 <a href="/a/b?page=4">4</a> <a href="/a/b?page=5">Last &raquo;</a></div>', pagify_links(@data))
31
- end
32
-
33
- def test_custom_path
34
- assert_equal('<div class="pagination"><a href="XD?page=2">&lt; Previous</a> <a href="XD?page=4">Next &gt;</a><br /><a href="XD?page=1">&laquo; First</a> <a href="XD?page=2">2</a> 3 <a href="XD?page=4">4</a> <a href="XD?page=5">Last &raquo;</a></div>', pagify_links(@data){'XD'})
35
- end
36
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Lin Jen-Shin (aka godfat \xE7\x9C\x9F\xE5\xB8\xB8)"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-08 00:00:00 +08:00
12
+ date: 2009-11-16 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -79,7 +79,9 @@ files:
79
79
  - lib/pagify/helper/abstract.rb
80
80
  - lib/pagify/helper/detail/setting.rb
81
81
  - lib/pagify/helper/detail/setup.rb
82
+ - lib/pagify/helper/detail/web.rb
82
83
  - lib/pagify/helper/html.rb
84
+ - lib/pagify/helper/innate.rb
83
85
  - lib/pagify/helper/rails.rb
84
86
  - lib/pagify/page/basic.rb
85
87
  - lib/pagify/page/null.rb
@@ -113,11 +115,13 @@ files:
113
115
  - test/helper.rb
114
116
  - test/helper_model.rb
115
117
  - test/helper_pagify.rb
118
+ - test/helper_web.rb
116
119
  - test/test_active_record.rb
117
120
  - test/test_array.rb
118
121
  - test/test_basic.rb
119
122
  - test/test_data_mapper.rb
120
123
  - test/test_html.rb
124
+ - test/test_innate.rb
121
125
  - test/test_null.rb
122
126
  - test/test_rails.rb
123
127
  has_rdoc: true
@@ -159,5 +163,6 @@ test_files:
159
163
  - test/test_basic.rb
160
164
  - test/test_data_mapper.rb
161
165
  - test/test_html.rb
166
+ - test/test_innate.rb
162
167
  - test/test_null.rb
163
168
  - test/test_rails.rb