Skip to content
Browse files

Merge remote branch 'mwindwer/kaminari'

Conflicts:
	Gemfile
	activeadmin.gemspec
  • Loading branch information...
2 parents 44dbeeb + a5c11f3 commit c45bd41f91c3121b2144378ec6aafcd4bacb7f92 @gregbell gregbell committed Jun 1, 2011
View
3 Gemfile
@@ -27,8 +27,8 @@ end
gem "meta_search", '>= 0.9.2'
gem 'devise', '>= 1.1.2'
gem 'formtastic', '>= 1.1.0'
-gem 'will_paginate', '>= 3.0.pre2'
gem 'inherited_resources'
+gem 'kaminari', '>= 0.12.4'
gem 'sass', '>= 3.1.0'
gem 'fastercsv'
@@ -49,3 +49,4 @@ group :test do
gem 'shoulda', '2.11.2', :require => nil
gem 'launchy'
end
+
View
2 README.rdoc
@@ -399,7 +399,7 @@ Formtastic::
A DSL for semantically building amazing forms.
Devise::
User authentication is done using Devise
-WillPaginate::
+Kaminari::
Pagination for rails apps
Iconic Icons::
Excellent SVG icon set designed by P.J. Onori: http://somerandomdude.com/projects/iconic
View
11 activeadmin.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Greg Bell"]
- s.date = %q{2011-05-31}
+ s.date = %q{2011-06-01}
s.description = %q{The administration framework for Ruby on Rails.}
s.email = %q{gregdbell@gmail.com}
s.extra_rdoc_files = [
@@ -263,7 +263,7 @@ Gem::Specification.new do |s|
]
s.homepage = %q{http://github.com/gregbell/active_admin}
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.7}
+ s.rubygems_version = %q{1.7.2}
s.summary = %q{The administration framework for Ruby on Rails.}
s.test_files = [
"spec/integration/belongs_to_spec.rb",
@@ -317,16 +317,15 @@ Gem::Specification.new do |s|
]
if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
s.add_runtime_dependency(%q<meta_search>, [">= 0.9.2"])
s.add_runtime_dependency(%q<devise>, [">= 1.1.2"])
s.add_runtime_dependency(%q<formtastic>, [">= 1.1.0"])
- s.add_runtime_dependency(%q<will_paginate>, [">= 3.0.pre2"])
s.add_runtime_dependency(%q<inherited_resources>, [">= 0"])
+ s.add_runtime_dependency(%q<kaminari>, [">= 0.12.4"])
s.add_runtime_dependency(%q<sass>, [">= 3.1.0"])
s.add_runtime_dependency(%q<fastercsv>, [">= 0"])
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
@@ -338,8 +337,8 @@ Gem::Specification.new do |s|
s.add_dependency(%q<meta_search>, [">= 0.9.2"])
s.add_dependency(%q<devise>, [">= 1.1.2"])
s.add_dependency(%q<formtastic>, [">= 1.1.0"])
- s.add_dependency(%q<will_paginate>, [">= 3.0.pre2"])
s.add_dependency(%q<inherited_resources>, [">= 0"])
+ s.add_dependency(%q<kaminari>, [">= 0.12.4"])
s.add_dependency(%q<sass>, [">= 3.1.0"])
s.add_dependency(%q<fastercsv>, [">= 0"])
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
@@ -352,8 +351,8 @@ Gem::Specification.new do |s|
s.add_dependency(%q<meta_search>, [">= 0.9.2"])
s.add_dependency(%q<devise>, [">= 1.1.2"])
s.add_dependency(%q<formtastic>, [">= 1.1.0"])
- s.add_dependency(%q<will_paginate>, [">= 3.0.pre2"])
s.add_dependency(%q<inherited_resources>, [">= 0"])
+ s.add_dependency(%q<kaminari>, [">= 0.12.4"])
s.add_dependency(%q<sass>, [">= 3.1.0"])
s.add_dependency(%q<fastercsv>, [">= 0"])
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
View
7 lib/active_admin.rb
@@ -1,6 +1,6 @@
require 'meta_search'
require 'devise'
-require 'will_paginate'
+require 'kaminari'
require 'sass'
require 'active_admin/arbre'
@@ -38,7 +38,7 @@ module Configuration
# The default namespace to put controllers and routes inside. Set this
# in config/initializers/active_admin.rb using:
- #
+ #
# config.default_namespace = :super_admin
#
@@default_namespace = :admin
@@ -116,7 +116,7 @@ def setup
ActionController::Base.append_view_path ActiveAdmin.views_path
# Don't eagerload our configs, we'll deal with them ourselves
- Rails.application.config.eager_load_paths = Rails.application.config.eager_load_paths.reject do |path|
+ Rails.application.config.eager_load_paths = Rails.application.config.eager_load_paths.reject do |path|
load_paths.include?(path)
end
@@ -314,3 +314,4 @@ def dashboard_section(name, options = {}, &block)
end
require 'active_admin/comments'
+
View
6 lib/active_admin/comments/comment.rb
@@ -1,5 +1,10 @@
+require 'kaminari/models/active_record_extension'
+
module ActiveAdmin
+ # manually initialize kaminari for this model
+ ::ActiveRecord::Base.send :include, Kaminari::ActiveRecordExtension
+
class Comment < ActiveRecord::Base
self.table_name = "active_admin_comments"
@@ -13,3 +18,4 @@ class Comment < ActiveRecord::Base
end
end
+
View
5 lib/active_admin/resource_controller/collection.rb
@@ -28,7 +28,7 @@ def active_admin_collection
# This method should return an ActiveRecord::Relation object so that
# the searching and filtering can be applied on top
#
- # Note, unless you are doing something special, you should use the
+ # Note, unless you are doing something special, you should use the
# scope_to method from the Scoping module instead of overriding this
# method.
def scoped_collection
@@ -126,7 +126,7 @@ def setup_pagination_for_csv
end
def paginate(chain)
- chain.paginate(:page => params[:page], :per_page => @per_page || ActiveAdmin.default_per_page)
+ chain.page(params[:page]).per(@per_page || ActiveAdmin.default_per_page)
end
end
@@ -141,3 +141,4 @@ def paginate(chain)
end
end
end
+
View
37 lib/active_admin/views/components/paginated_collection.rb
@@ -7,7 +7,7 @@ module Views
#
# paginated_collection collection, :entry_name => "Post" do
# div do
- # h2 "Inside the
+ # h2 "Inside the
# end
# end
#
@@ -26,14 +26,14 @@ class PaginatedCollection < ActiveAdmin::Component
# Builds a new paginated collection component
#
- # @param [Array] collection A "paginated" collection from will_paginate
+ # @param [Array] collection A "paginated" collection from kaminari
# @param [Hash] options These options will be passed on to the page_entries_info
- # method supplied in will_paginate.
+ # method.
# Useful keys:
- # :entry_name - The name to dislpay for this resource collection
+ # :entry_name - The name to display for this resource collection
def build(collection, options = {})
@collection = collection
- div(page_entries_info(@collection, options), :class => "pagination_information")
+ div(page_entries_info(options).html_safe, :class => "pagination_information")
@contents = div(:class => "paginated_collection_contents")
build_pagination_with_formats
@built = true
@@ -58,17 +58,40 @@ def build_pagination_with_formats
end
def build_pagination
- text_node will_paginate(collection, :previous_label => "Previous", :next_label => "Next")
+ text_node paginate(collection)
end
# TODO: Refactor to new HTML DSL
def build_download_format_links(formats = [:csv, :xml, :json])
links = formats.collect do |format|
- link_to format.to_s.upcase, { :format => format}.merge(request.query_parameters.except(:commit, :format))
+ link_to format.to_s.upcase, { :format => format}.merge(request.query_parameters.except(:commit, :format))
end
text_node ["Download:", links].flatten.join("&nbsp;").html_safe
end
+ # modified from will_paginate
+ def page_entries_info(options = {})
+ entry_name = options[:entry_name] ||
+ (collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' '))
+
+ if collection.num_pages < 2
+ case collection.size
+ when 0; "No #{entry_name.pluralize} found"
+ when 1; "Displaying <b>1</b> #{entry_name}"
+ else; "Displaying <b>all #{collection.size}</b> #{entry_name.pluralize}"
+ end
+ else
+ offset = collection.current_page * ActiveAdmin.default_per_page
+ total = collection.total_count
+ %{Displaying #{entry_name.pluralize} <b>%d&nbsp;-&nbsp;%d</b> of <b>%d</b> in total} % [
+ offset - ActiveAdmin.default_per_page + 1,
+ offset > total ? total : offset,
+ total
+ ]
+ end
+ end
+
end
end
end
+

0 comments on commit c45bd41

Please sign in to comment.
Something went wrong with that request. Please try again.