acts_as_ferret 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +6 -0
- data/doc/demo/Gemfile +18 -0
- data/doc/demo/Rakefile +3 -6
- data/doc/demo/app/controllers/application_controller.rb +3 -0
- data/doc/demo/app/helpers/application_helper.rb +0 -1
- data/doc/demo/app/views/admin/backend/search.rhtml +1 -1
- data/doc/demo/app/views/contents/edit.rhtml +1 -1
- data/doc/demo/app/views/contents/new.rhtml +1 -1
- data/doc/demo/app/views/searches/search.html.erb +1 -1
- data/doc/demo/config.ru +4 -0
- data/doc/demo/config/application.rb +57 -0
- data/doc/demo/config/boot.rb +4 -107
- data/doc/demo/config/database.yml +16 -24
- data/doc/demo/config/environment.rb +4 -68
- data/doc/demo/config/environments/development.rb +22 -12
- data/doc/demo/config/environments/production.rb +43 -13
- data/doc/demo/config/environments/test.rb +32 -16
- data/doc/demo/config/initializers/backtrace_silencers.rb +7 -0
- data/doc/demo/config/initializers/inflections.rb +10 -0
- data/doc/demo/config/initializers/mime_types.rb +5 -0
- data/doc/demo/config/initializers/secret_token.rb +7 -0
- data/doc/demo/config/initializers/session_store.rb +13 -0
- data/doc/demo/config/locales/en.yml +5 -0
- data/doc/demo/config/routes.rb +4 -5
- data/doc/demo/public/404.html +23 -5
- data/doc/demo/public/422.html +26 -0
- data/doc/demo/public/500.html +23 -5
- data/doc/demo/public/images/rails.png +0 -0
- data/doc/demo/public/index.html +50 -88
- data/doc/demo/public/javascripts/application.js +2 -0
- data/doc/demo/public/javascripts/controls.js +965 -0
- data/doc/demo/public/javascripts/dragdrop.js +974 -0
- data/doc/demo/public/javascripts/effects.js +1123 -0
- data/doc/demo/public/javascripts/prototype.js +6001 -0
- data/doc/demo/public/javascripts/rails.js +191 -0
- data/doc/demo/public/robots.txt +5 -1
- data/doc/demo/script/rails +6 -0
- data/doc/demo/test/functional/admin/backend_controller_test.rb +1 -1
- data/doc/demo/test/functional/contents_controller_test.rb +1 -2
- data/doc/demo/test/functional/searches_controller_test.rb +1 -2
- data/doc/demo/test/performance/browsing_test.rb +9 -0
- data/doc/demo/test/test_helper.rb +13 -18
- data/doc/demo/test/unit/comment_test.rb +4 -4
- data/doc/demo/test/unit/content_test.rb +6 -4
- data/doc/demo/test/unit/ferret_result_test.rb +2 -3
- data/doc/demo/test/unit/multi_index_test.rb +2 -3
- data/doc/demo/test/unit/remote_index_test.rb +2 -2
- data/doc/demo/test/unit/shared_index1_test.rb +2 -3
- data/doc/demo/test/unit/shared_index2_test.rb +2 -3
- data/doc/demo/test/unit/sort_test.rb +2 -2
- data/doc/demo/test/unit/special_content_test.rb +3 -4
- data/lib/acts_as_ferret.rb +17 -3
- data/lib/acts_as_ferret/blank_slate.rb +11 -10
- data/lib/acts_as_ferret/class_methods.rb +9 -7
- data/lib/acts_as_ferret/ferret_find_methods.rb +5 -1
- data/lib/acts_as_ferret/ferret_result.rb +11 -4
- data/lib/acts_as_ferret/multi_index.rb +8 -1
- data/lib/acts_as_ferret/search_results.rb +0 -1
- data/lib/acts_as_ferret/version.rb +1 -1
- metadata +23 -44
- data/doc/demo/test/fixtures/remote_contents.yml +0 -9
- data/doc/demo/vendor/plugins/will_paginate/LICENSE +0 -18
- data/doc/demo/vendor/plugins/will_paginate/README +0 -108
- data/doc/demo/vendor/plugins/will_paginate/Rakefile +0 -23
- data/doc/demo/vendor/plugins/will_paginate/init.rb +0 -21
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +0 -45
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +0 -44
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +0 -159
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +0 -95
- data/doc/demo/vendor/plugins/will_paginate/test/array_pagination_test.rb +0 -23
- data/doc/demo/vendor/plugins/will_paginate/test/boot.rb +0 -27
- data/doc/demo/vendor/plugins/will_paginate/test/console +0 -10
- data/doc/demo/vendor/plugins/will_paginate/test/finder_test.rb +0 -219
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/admin.rb +0 -3
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/companies.yml +0 -24
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/company.rb +0 -23
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developer.rb +0 -11
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developers_projects.yml +0 -13
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/project.rb +0 -4
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/projects.yml +0 -7
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/replies.yml +0 -20
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/reply.rb +0 -5
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/schema.sql +0 -44
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topic.rb +0 -19
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topics.yml +0 -30
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/user.rb +0 -2
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/users.yml +0 -35
- data/doc/demo/vendor/plugins/will_paginate/test/helper.rb +0 -42
- data/doc/demo/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb +0 -64
- data/doc/demo/vendor/plugins/will_paginate/test/lib/load_fixtures.rb +0 -10
- data/doc/demo/vendor/plugins/will_paginate/test/pagination_test.rb +0 -136
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
|
5
|
-
desc 'Default: run unit tests.'
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
desc 'Test the will_paginate plugin.'
|
9
|
-
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.pattern = 'test/**/*_test.rb'
|
11
|
-
t.verbose = true
|
12
|
-
end
|
13
|
-
|
14
|
-
desc 'Generate RDoc documentation for the will_paginate plugin.'
|
15
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
16
|
-
files = ['README', 'LICENSE', 'lib/**/*.rb']
|
17
|
-
rdoc.rdoc_files.add(files)
|
18
|
-
rdoc.main = "README" # page to start on
|
19
|
-
rdoc.title = "will_paginate"
|
20
|
-
rdoc.template = File.exists?(t="/Users/chris/ruby/projects/err/rock/template.rb") ? t : "/var/www/rock/template.rb"
|
21
|
-
rdoc.rdoc_dir = 'doc' # rdoc output folder
|
22
|
-
rdoc.options << '--inline-source'
|
23
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'will_paginate/core_ext'
|
2
|
-
require 'will_paginate/collection'
|
3
|
-
require 'will_paginate/finder'
|
4
|
-
require 'will_paginate/view_helpers'
|
5
|
-
|
6
|
-
ActionView::Base.send :include, WillPaginate::ViewHelpers
|
7
|
-
ActiveRecord::Base.send :include, WillPaginate::Finder
|
8
|
-
|
9
|
-
module ActiveRecord::Associations
|
10
|
-
# to support paginating finders on associations, we have to mix in the
|
11
|
-
# method_missing magic from WillPaginate::Finder::ClassMethods to AssociationProxy
|
12
|
-
# subclasses, but in a different way for Rails 1.2.x and 2.0
|
13
|
-
(AssociationCollection.instance_methods.include?(:create!) ?
|
14
|
-
AssociationCollection : AssociationCollection.subclasses.map(&:constantize)
|
15
|
-
).push(HasManyThroughAssociation).each do |klass|
|
16
|
-
klass.class_eval do
|
17
|
-
include WillPaginate::Finder::ClassMethods
|
18
|
-
alias_method_chain :method_missing, :paginate
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module WillPaginate
|
2
|
-
# Arrays returned from paginating finds are, in fact, instances of this.
|
3
|
-
# You may think of WillPaginate::Collection as an ordinary array with some
|
4
|
-
# extra properties. Those properites are used by view helpers to generate
|
5
|
-
# correct page links.
|
6
|
-
#
|
7
|
-
class Collection < Array
|
8
|
-
attr_reader :current_page, :per_page
|
9
|
-
attr_accessor :total_entries
|
10
|
-
|
11
|
-
# These collection objects are instantiated by ActiveRecord paginating
|
12
|
-
# finders; there is no need to do it manually.
|
13
|
-
#
|
14
|
-
def initialize(page, per_page, total)
|
15
|
-
@current_page = page.to_i
|
16
|
-
@per_page = per_page.to_i
|
17
|
-
@total_entries = total.to_i
|
18
|
-
@total_pages = (@total_entries / @per_page.to_f).ceil
|
19
|
-
end
|
20
|
-
|
21
|
-
# The total number of pages.
|
22
|
-
def page_count
|
23
|
-
@total_pages
|
24
|
-
end
|
25
|
-
|
26
|
-
# Current offset of the paginated collection. If we're on the first page,
|
27
|
-
# it is always 0. If we're on the 2nd page and there are 30 entries per page,
|
28
|
-
# the offset is 30. This property is useful if you want to render ordinals
|
29
|
-
# besides your records: simply start with offset + 1.
|
30
|
-
#
|
31
|
-
def offset
|
32
|
-
(current_page - 1) * per_page
|
33
|
-
end
|
34
|
-
|
35
|
-
# current_page - 1 or nil if there is no previous page
|
36
|
-
def previous_page
|
37
|
-
current_page > 1 ? (current_page - 1) : nil
|
38
|
-
end
|
39
|
-
|
40
|
-
# current_page + 1 or nil if there is no next page
|
41
|
-
def next_page
|
42
|
-
current_page < page_count ? (current_page + 1) : nil
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
unless Hash.instance_methods.include? 'except'
|
4
|
-
Hash.class_eval do
|
5
|
-
# Returns a new hash without the given keys.
|
6
|
-
def except(*keys)
|
7
|
-
rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
|
8
|
-
reject { |key,| rejected.include?(key) }
|
9
|
-
end
|
10
|
-
|
11
|
-
# Replaces the hash without only the given keys.
|
12
|
-
def except!(*keys)
|
13
|
-
replace(except(*keys))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
unless Hash.instance_methods.include? 'slice'
|
19
|
-
Hash.class_eval do
|
20
|
-
# Returns a new hash with only the given keys.
|
21
|
-
def slice(*keys)
|
22
|
-
allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
|
23
|
-
reject { |key,| !allowed.include?(key) }
|
24
|
-
end
|
25
|
-
|
26
|
-
# Replaces the hash with only the given keys.
|
27
|
-
def slice!(*keys)
|
28
|
-
replace(slice(*keys))
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
unless Array.instance_methods.include? 'paginate'
|
34
|
-
# http://www.desimcadam.com/archives/8
|
35
|
-
Array.class_eval do
|
36
|
-
def paginate(page = 1, per_page = 15)
|
37
|
-
pagination_array = WillPaginate::Collection.new(page, per_page, size)
|
38
|
-
start_index = pagination_array.offset
|
39
|
-
end_index = start_index + (per_page - 1)
|
40
|
-
array_to_concat = self[start_index..end_index]
|
41
|
-
array_to_concat.nil? ? [] : pagination_array.concat(array_to_concat)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,159 +0,0 @@
|
|
1
|
-
module WillPaginate
|
2
|
-
# A mixin for ActiveRecord::Base. Provides `per_page` class method
|
3
|
-
# and makes `paginate` finders possible with some method_missing magic.
|
4
|
-
#
|
5
|
-
# Find out more in WillPaginate::Finder::ClassMethods
|
6
|
-
#
|
7
|
-
module Finder
|
8
|
-
def self.included(base)
|
9
|
-
base.extend ClassMethods
|
10
|
-
class << base
|
11
|
-
alias_method_chain :method_missing, :paginate
|
12
|
-
define_method(:per_page) { 30 } unless respond_to?(:per_page)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# = Paginating finders for ActiveRecord models
|
17
|
-
#
|
18
|
-
# WillPaginate doesn't really add extra methods to your ActiveRecord models (except +per_page+
|
19
|
-
# unless it's already available). It simply intercepts
|
20
|
-
# the calls to paginating finders such as +paginate+, +paginate_by_user_id+ (and so on) and
|
21
|
-
# translates them to ordinary finders: +find+, +find_by_user_id+, etc. It does so with some
|
22
|
-
# method_missing magic, but you don't need to care for that. You simply use paginating finders
|
23
|
-
# same way you used ordinary ones. You only need to tell them what page you want in options.
|
24
|
-
#
|
25
|
-
# @topics = Topic.paginate :all, :page => params[:page]
|
26
|
-
#
|
27
|
-
# In paginating finders, "all" is implicit. No sense in paginating a single record, right? So:
|
28
|
-
#
|
29
|
-
# Post.paginate => Post.find :all
|
30
|
-
# Post.paginate_all_by_something => Post.find_all_by_something
|
31
|
-
# Post.paginate_by_something => Post.find_all_by_something
|
32
|
-
#
|
33
|
-
# Knowing that, the above example can be written simply as:
|
34
|
-
#
|
35
|
-
# @topics = Topic.paginate :page => params[:page]
|
36
|
-
#
|
37
|
-
# Don't forget to pass the +page+ parameter! Without it, paginating finders will raise an error.
|
38
|
-
#
|
39
|
-
# == Options
|
40
|
-
# Options for paginating finders are:
|
41
|
-
#
|
42
|
-
# page REQUIRED, but defaults to 1 if false or nil
|
43
|
-
# per_page (default is read from the model, which is 30 if not overriden)
|
44
|
-
# total entries not needed unless you want to count the records yourself somehow
|
45
|
-
# count hash of options that are used only for the call to count
|
46
|
-
#
|
47
|
-
module ClassMethods
|
48
|
-
# This methods wraps +find_by_sql+ by simply adding LIMIT and OFFSET to your SQL string
|
49
|
-
# based on the params otherwise used by paginating finds: +page+ and +per_page+.
|
50
|
-
#
|
51
|
-
# Example:
|
52
|
-
#
|
53
|
-
# @developers = Developer.paginate_by_sql ['select * from developers where salary > ?', 80000],
|
54
|
-
# :page => params[:page], :per_page => 3
|
55
|
-
#
|
56
|
-
def paginate_by_sql(sql, options)
|
57
|
-
options, page, per_page = wp_parse_options!(options)
|
58
|
-
sanitized_query = sanitize_sql(sql)
|
59
|
-
total_entries = options[:total_entries] || count_by_sql("SELECT COUNT(*) FROM (#{sanitized_query}) AS count_table")
|
60
|
-
|
61
|
-
returning WillPaginate::Collection.new(page, per_page, total_entries) do |pager|
|
62
|
-
options.update :offset => pager.offset, :limit => pager.per_page
|
63
|
-
add_limit! sanitized_query, options
|
64
|
-
pager.replace find_by_sql(sanitized_query)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def respond_to?(method, include_priv = false)
|
69
|
-
case method.to_sym
|
70
|
-
when :paginate, :paginate_by_sql
|
71
|
-
true
|
72
|
-
else
|
73
|
-
super(method.to_s.sub(/^paginate/, 'find'), include_priv)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
protected
|
78
|
-
|
79
|
-
def method_missing_with_paginate(method, *args, &block)
|
80
|
-
# did somebody tried to paginate? if not, let them be
|
81
|
-
unless method.to_s.index('paginate') == 0
|
82
|
-
return method_missing_without_paginate(method, *args, &block)
|
83
|
-
end
|
84
|
-
|
85
|
-
options, page, per_page = wp_parse_options!(args.pop)
|
86
|
-
# paginate finders are really just find_* with limit and offset
|
87
|
-
finder = method.to_s.sub /^paginate/, 'find'
|
88
|
-
# magic counting for user convenience
|
89
|
-
total_entries = wp_count!(options, args, finder)
|
90
|
-
|
91
|
-
# :all is implicit
|
92
|
-
if finder == 'find'
|
93
|
-
args.unshift(:all) if args.empty?
|
94
|
-
elsif finder.index('find_by_') == 0
|
95
|
-
finder.sub! /^find/, 'find_all'
|
96
|
-
end
|
97
|
-
|
98
|
-
::Object.returning WillPaginate::Collection.new(page, per_page, total_entries) do |pager|
|
99
|
-
args << options.update(:offset => pager.offset, :limit => pager.per_page)
|
100
|
-
pager.replace send(finder, *args)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def wp_count!(options, args, finder)
|
105
|
-
# :total_entries and :count are mutually exclusive!
|
106
|
-
unless options[:total_entries]
|
107
|
-
unless args.first.is_a? Array
|
108
|
-
# count expects (almost) the same options as find
|
109
|
-
count_options = options.except :count, :order, :select
|
110
|
-
|
111
|
-
# merge the hash found in :count
|
112
|
-
# this allows you to specify :select, :order, or anything else just for the count query
|
113
|
-
count_options.update(options.delete(:count)) if options.key? :count
|
114
|
-
# extract the conditions from calls like "paginate_by_foo_and_bar"
|
115
|
-
conditions = wp_extract_finder_conditions(finder, args, count_options)
|
116
|
-
|
117
|
-
# scope_out adds a 'with_finder' method which acts like with_scope, if it's present
|
118
|
-
# then execute the count with the scoping provided by the with_finder
|
119
|
-
count = nil
|
120
|
-
counter = Proc.new { count = count(count_options) }
|
121
|
-
|
122
|
-
if respond_to?(scoper = finder.sub(/^find/, 'with'))
|
123
|
-
send(scoper, &counter)
|
124
|
-
else
|
125
|
-
with_scope(:find => { :conditions => conditions }, &counter)
|
126
|
-
end
|
127
|
-
|
128
|
-
count.respond_to?(:length) ? count.length : count
|
129
|
-
else
|
130
|
-
# array of IDs was passed, so its size is the total number
|
131
|
-
args.first.size
|
132
|
-
end
|
133
|
-
else
|
134
|
-
options.delete(:total_entries)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def wp_parse_options!(options)
|
139
|
-
raise ArgumentError, 'hash parameters expected' unless options.respond_to? :symbolize_keys!
|
140
|
-
options.symbolize_keys!
|
141
|
-
raise ArgumentError, ':page parameter required' unless options.key? :page
|
142
|
-
page = options.delete(:page) || 1
|
143
|
-
per_page = options.delete(:per_page) || self.per_page
|
144
|
-
[options, page, per_page]
|
145
|
-
end
|
146
|
-
|
147
|
-
private
|
148
|
-
|
149
|
-
# thanks to active record for making us duplicate this code
|
150
|
-
def wp_extract_finder_conditions(finder, arguments, count_options)
|
151
|
-
return unless match = /^find_(all_by|by)_([_a-zA-Z]\w*)$/.match(finder.to_s)
|
152
|
-
|
153
|
-
attribute_names = extract_attribute_names_from_match(match)
|
154
|
-
raise "I can't make sense of #{finder}" unless all_attributes_exists?(attribute_names)
|
155
|
-
construct_attributes_from_arguments(attribute_names, arguments)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
module WillPaginate
|
2
|
-
# = Global options for pagination helpers
|
3
|
-
#
|
4
|
-
# Options for pagination helpers are optional and get their default values from the
|
5
|
-
# WillPaginate::ViewHelpers.pagination_options hash. You can write to this hash to
|
6
|
-
# override default options on the global level:
|
7
|
-
#
|
8
|
-
# WillPaginate::ViewHelpers.pagination_options[:prev_label] = 'Previous page'
|
9
|
-
#
|
10
|
-
# By putting this into your environment.rb you can easily localize link texts to previous
|
11
|
-
# and next pages, as well as override some other defaults to your liking.
|
12
|
-
module ViewHelpers
|
13
|
-
# default options that can be overriden on the global level
|
14
|
-
@@pagination_options = { :class => 'pagination',
|
15
|
-
:prev_label => '« Previous',
|
16
|
-
:next_label => 'Next »',
|
17
|
-
:inner_window => 4, # links around the current page
|
18
|
-
:outer_window => 1, # links around beginning and end
|
19
|
-
:separator => ' ', # single space is friendly to spiders and non-graphic browsers
|
20
|
-
:param_name => :page
|
21
|
-
}
|
22
|
-
mattr_reader :pagination_options
|
23
|
-
|
24
|
-
# Renders Digg-style pagination. (We know you wanna!)
|
25
|
-
# Returns nil if there is only one page in total (can't paginate that).
|
26
|
-
#
|
27
|
-
# Options for will_paginate view helper:
|
28
|
-
#
|
29
|
-
# class: CSS class name for the generated DIV (default "pagination")
|
30
|
-
# prev_label: default '« Previous',
|
31
|
-
# next_label: default 'Next »',
|
32
|
-
# inner_window: how many links are shown around the current page, defaults to 4
|
33
|
-
# outer_window: how many links are around the first and the last page, defaults to 1
|
34
|
-
# separator: string separator for page HTML elements, default " " (single space)
|
35
|
-
# param_name: parameter name for page number in URLs, defaults to "page"
|
36
|
-
#
|
37
|
-
# All extra options are passed to the generated container DIV, so eventually
|
38
|
-
# they become its HTML attributes.
|
39
|
-
#
|
40
|
-
def will_paginate(entries = @entries, options = {})
|
41
|
-
total_pages = entries.page_count
|
42
|
-
|
43
|
-
if total_pages > 1
|
44
|
-
options = options.symbolize_keys.reverse_merge(pagination_options)
|
45
|
-
page, param = entries.current_page, options.delete(:param_name)
|
46
|
-
|
47
|
-
inner_window, outer_window = options.delete(:inner_window).to_i, options.delete(:outer_window).to_i
|
48
|
-
min = page - inner_window
|
49
|
-
max = page + inner_window
|
50
|
-
# adjust lower or upper limit if other is out of bounds
|
51
|
-
if max > total_pages then min -= max - total_pages
|
52
|
-
elsif min < 1 then max += 1 - min
|
53
|
-
end
|
54
|
-
|
55
|
-
current = min..max
|
56
|
-
beginning = 1..(1 + outer_window)
|
57
|
-
tail = (total_pages - outer_window)..total_pages
|
58
|
-
visible = [beginning, current, tail].map(&:to_a).flatten.sort.uniq
|
59
|
-
links, prev = [], 0
|
60
|
-
|
61
|
-
visible.each do |n|
|
62
|
-
next if n < 1
|
63
|
-
break if n > total_pages
|
64
|
-
|
65
|
-
unless n - prev > 1
|
66
|
-
prev = n
|
67
|
-
links << page_link_or_span((n != page ? n : nil), 'current', n, param)
|
68
|
-
else
|
69
|
-
# ellipsis represents the gap between windows
|
70
|
-
prev = n - 1
|
71
|
-
links << '...'
|
72
|
-
redo
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# next and previous buttons
|
77
|
-
links.unshift page_link_or_span(entries.previous_page, 'disabled', options.delete(:prev_label), param)
|
78
|
-
links.push page_link_or_span(entries.next_page, 'disabled', options.delete(:next_label), param)
|
79
|
-
|
80
|
-
content_tag :div, links.join(options.delete(:separator)), options
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
protected
|
85
|
-
|
86
|
-
def page_link_or_span(page, span_class, text, param)
|
87
|
-
unless page
|
88
|
-
content_tag :span, text, :class => span_class
|
89
|
-
else
|
90
|
-
# page links should preserve GET parameters, so we merge params
|
91
|
-
link_to text, params.merge(param.to_sym => (page !=1 ? page : nil))
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require File.dirname(__FILE__) + '/../init'
|
3
|
-
|
4
|
-
class ArrayPaginationTest < ActiveRecordTestCase
|
5
|
-
def setup
|
6
|
-
@array = ('a'..'e').to_a
|
7
|
-
end
|
8
|
-
|
9
|
-
cases = [
|
10
|
-
{ :current => 1, :per_page => 3, :expected => %w( a b c ) },
|
11
|
-
{ :current => 2, :per_page => 3, :expected => %w( d e ) },
|
12
|
-
{ :current => 1, :per_page => 5, :expected => %w( a b c d e ) },
|
13
|
-
{ :current => 3, :per_page => 5, :expected => [] },
|
14
|
-
{ :current => -1, :per_page => 5, :expected => [] },
|
15
|
-
{ :current => 1, :per_page => -5, :expected => [] }
|
16
|
-
]
|
17
|
-
|
18
|
-
cases.each_with_index do |conditions, index|
|
19
|
-
define_method("test_case_#{index}") do
|
20
|
-
assert_equal conditions[:expected], @array.paginate(conditions[:current], conditions[:per_page])
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
plugin_root = File.join(File.dirname(__FILE__), '..')
|
2
|
-
|
3
|
-
# first look for a symlink to a copy of the framework
|
4
|
-
if framework_root = ["#{plugin_root}/rails", "#{plugin_root}/../../rails"].find { |p| File.directory? p }
|
5
|
-
print "found framework root: #{framework_root}"
|
6
|
-
# this allows for a plugin to be tested outside an app
|
7
|
-
$:.unshift "#{framework_root}/activesupport/lib", "#{framework_root}/activerecord/lib", "#{framework_root}/actionpack/lib"
|
8
|
-
else
|
9
|
-
# is the plugin installed in an application?
|
10
|
-
app_root = plugin_root + '/../../..'
|
11
|
-
|
12
|
-
if File.directory? app_root + '/config'
|
13
|
-
print 'using config/boot.rb'
|
14
|
-
ENV['RAILS_ENV'] = 'test'
|
15
|
-
require File.expand_path(app_root + '/config/boot')
|
16
|
-
else
|
17
|
-
# simply use installed gems if available
|
18
|
-
print 'using rubygems'
|
19
|
-
require 'rubygems'
|
20
|
-
gem 'actionpack'; gem 'activerecord'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
%w(action_pack active_record active_record/version action_controller active_record/fixtures).each {|f| require f}
|
25
|
-
puts " (ActiveRecord v#{ActiveRecord::VERSION::STRING})"
|
26
|
-
|
27
|
-
$:.unshift "#{plugin_root}/lib"
|
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
3
|
-
libs = []
|
4
|
-
dirname = File.dirname(__FILE__)
|
5
|
-
|
6
|
-
libs << 'irb/completion'
|
7
|
-
libs << File.join(dirname, 'lib', 'load_fixtures')
|
8
|
-
libs << File.join(dirname, '..', 'init')
|
9
|
-
|
10
|
-
exec "#{irb} #{libs.map{|l| " -r #{l}" }.join} --simple-prompt"
|