simple_page 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.2"
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 David Monagle
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = simple_page
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to simple_page
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 David Monagle. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "simple_page"
16
+ gem.homepage = "http://github.com/intrica/simple_page"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Active Record extension and view helpers to give pagination abilities}
19
+ gem.description = %Q{Extends Active Record to give pagination functions. Also supplies view helpers and generators to create customised pagination links.}
20
+ gem.email = "david.monagle@intrica.com.au"
21
+ gem.authors = ["David Monagle"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "simple_page #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 3.0.4
@@ -0,0 +1,24 @@
1
+ module SimplePageHelper
2
+ def simple_page_marker(page)
3
+ case page
4
+ when :previous
5
+ return "Previous"
6
+ when :next
7
+ return "Next"
8
+ when :first
9
+ return "First"
10
+ when :last
11
+ return "Last"
12
+ else
13
+ return page
14
+ end
15
+ end
16
+
17
+ def page_links(collection, selected_page, extras = [ :previous, :next ], page_tag_helper = lambda {|page| simple_page_marker(page)})
18
+ content_tag :ul, :class => "page_select" do
19
+ collection.page_links_generator(selected_page, :inner => 2, :outer => 1, :extras => extras) do |tag, page_number, classes|
20
+ content_tag :li, link_to(page_tag_helper.call(tag), params.merge(:page => page_number)), :class => (classes << :page).join(" ")
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,71 @@
1
+ module SimplePageExtension
2
+ def page(number)
3
+ return nil if number.nil?
4
+ offset = (number.to_i - 1) * page_size
5
+ return nil if offset < 0
6
+ self.offset(offset).limit(page_size)
7
+ end
8
+
9
+ def page_count
10
+ return @page_count unless @page_count.nil?
11
+ c = (self.count / Float(page_size)).ceil
12
+ @page_count = c == 0 ? 1 : c
13
+ @page_count
14
+ end
15
+
16
+ def page_size
17
+ @page_size || 10
18
+ end
19
+
20
+ def page_size=(size)
21
+ @page_size = size
22
+ @page_size = size == 0 ? nil : size
23
+ end
24
+
25
+ def find_page_number(reference)
26
+ count = 0
27
+ self.each do |o|
28
+ count += 1
29
+ if o.id == reference.id
30
+ return (count / Float(page_size)).ceil
31
+ end
32
+ end
33
+ end
34
+
35
+ def page_links_generator(page, options)
36
+ raise ArgumentError, "No window block supplied." unless block_given?
37
+ raise ArgumentError, "please specify a :inner option" unless inner = options[:inner]
38
+ return if self.page_count < 2
39
+ outer = options[:outer] || 0
40
+ extras = [ options[:extras] ].flatten.compact
41
+ page_number = page.to_i
42
+ last_page = self.page_count
43
+ next_page = page_number >= self.page_count ? nil : page_number + 1
44
+ prev_page = page_number > 1 ? page_number - 1 : nil
45
+ numbers = case
46
+ when page_number <= inner + 1
47
+ 1 .. 1 + 2 * inner
48
+ when page_number >= self.page_count - inner
49
+ self.page_count - 2 * inner .. self.page_count
50
+ else
51
+ page_number - inner .. page_number + inner
52
+ end.to_a
53
+ 1.upto(outer) { |n| numbers << n << self.page_count-n+1 }
54
+ numbers.uniq!
55
+ numbers.sort!
56
+ numbers.reject! { |number| !number.between?(1, self.page_count) }
57
+ returning [] do |results|
58
+ results << yield(:first, 1, []) if extras.include?(:first)
59
+ results << yield(:previous, prev_page, []) if extras.include?(:previous)
60
+ numbers.zip([nil]+numbers, numbers[1..-1]) do |number, prev_number, next_number|
61
+ classes = []
62
+ classes << :selected if page_number == number
63
+ classes << :gap_before if prev_number && prev_number < number - 1
64
+ classes << :gap_after if next_number && next_number > number + 1
65
+ results << yield(number, number, classes)
66
+ end
67
+ results << yield(:next, next_page, []) if extras.include?(:next)
68
+ results << yield(:last, self.page_count, []) if extras.include?(:last)
69
+ end.join("\n").html_safe
70
+ end
71
+ end
@@ -0,0 +1,6 @@
1
+ require "rails"
2
+
3
+ module SimplePage
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ require "simple_page/engine"
2
+ require 'simple_page/active_record_extension'
3
+
4
+ ActiveRecord::Relation.send :include, SimplePageExtension
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{simple_page}
8
+ s.version = "3.0.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Monagle"]
12
+ s.date = %q{2011-05-09}
13
+ s.description = %q{Extends Active Record to give pagination functions. Also supplies view helpers and generators to create customised pagination links.}
14
+ s.email = %q{david.monagle@intrica.com.au}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "app/helpers/simple_page_helper.rb",
27
+ "lib/simple_page.rb",
28
+ "lib/simple_page/active_record_extension.rb",
29
+ "lib/simple_page/engine.rb",
30
+ "simple_page.gemspec",
31
+ "test/helper.rb",
32
+ "test/test_simple_page.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/intrica/simple_page}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.5.3}
38
+ s.summary = %q{Active Record extension and view helpers to give pagination abilities}
39
+ s.test_files = [
40
+ "test/helper.rb",
41
+ "test/test_simple_page.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
50
+ else
51
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
57
+ end
58
+ end
59
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'simple_page'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestSimplePage < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_page
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 3
8
+ - 0
9
+ - 4
10
+ version: 3.0.4
11
+ platform: ruby
12
+ authors:
13
+ - David Monagle
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-09 00:00:00 +10:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 23
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 0
33
+ version: 1.0.0
34
+ prerelease: false
35
+ type: :development
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: jeweler
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 7
45
+ segments:
46
+ - 1
47
+ - 5
48
+ - 2
49
+ version: 1.5.2
50
+ prerelease: false
51
+ type: :development
52
+ requirement: *id002
53
+ description: Extends Active Record to give pagination functions. Also supplies view helpers and generators to create customised pagination links.
54
+ email: david.monagle@intrica.com.au
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - LICENSE.txt
61
+ - README.rdoc
62
+ files:
63
+ - .document
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.rdoc
67
+ - Rakefile
68
+ - VERSION
69
+ - app/helpers/simple_page_helper.rb
70
+ - lib/simple_page.rb
71
+ - lib/simple_page/active_record_extension.rb
72
+ - lib/simple_page/engine.rb
73
+ - simple_page.gemspec
74
+ - test/helper.rb
75
+ - test/test_simple_page.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/intrica/simple_page
78
+ licenses:
79
+ - MIT
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.5.3
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Active Record extension and view helpers to give pagination abilities
110
+ test_files:
111
+ - test/helper.rb
112
+ - test/test_simple_page.rb