Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit e9ced374d433fbd4e74e22a4f92a3766bc7a71e1 @rspeicher committed Oct 22, 2010
@@ -0,0 +1,3 @@
+pkg/*
+*.gem
+.bundle
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in will_paginate_renderers.gemspec
+gemspec
@@ -0,0 +1,35 @@
+PATH
+ remote: .
+ specs:
+ will_paginate_renderers (0.0.1)
+ will_paginate (= 3.0.pre2)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ diff-lcs (1.1.2)
+ mocha (0.9.8)
+ rake
+ rake (0.8.7)
+ rspec (2.0.1)
+ rspec-core (~> 2.0.1)
+ rspec-expectations (~> 2.0.1)
+ rspec-mocks (~> 2.0.1)
+ rspec-core (2.0.1)
+ rspec-expectations (2.0.1)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.1)
+ rspec-core (~> 2.0.1)
+ rspec-expectations (~> 2.0.1)
+ will_paginate (3.0.pre2)
+ yard (0.6.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ mocha (~> 0.9)
+ rspec (~> 2.0.0)
+ will_paginate (= 3.0.pre2)
+ will_paginate_renderers!
+ yard
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 rspeicher
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
+# Will Paginate Renderers
+
+A collection of custom renderers for use with the
+[will_paginate](http://github.com/mislav/will_paginate) view helper.
+
+## Renderers Provided
+
+### Gmail
+
+![](http://img.skitch.com/20101022-kf5u89brk4q66rfiyc2xs4wyug.jpg)
+
+### Twitter
+
+![](http://img.skitch.com/20101022-gsii3yq94kex2f2tgwnwuf1k8j.jpg)
+
+## Usage
+
+will_paginate_renderers requires the development version of will_paginate,
+which is currently 3.0.pre2
+
+### Rails 3
+
+**Gemfile**
+
+ gem 'will_paginate_renderers'
+
+**Views**
+
+ # Use the Twitter renderer
+ will_paginate(@posts, :renderer => WillPaginateRenderers::Twitter.new)
+
+## Note on Patches/Pull Requests
+
+* Fork
+* Code
+* Commit
+* Push
+* Pull Request
+
+## Copyright
+
+Copyright (c) 2010 Robert Speicher. See LICENSE for details.
@@ -0,0 +1,12 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+require 'rspec/core/rake_task'
+
+desc 'Default: run specs.'
+task :default => :spec
+
+desc "Run specs"
+RSpec::Core::RakeTask.new do |t|
+ t.pattern = "./spec/**/*_spec.rb"
+end
@@ -0,0 +1 @@
+Autotest.add_discovery { "rspec2" }
@@ -0,0 +1,37 @@
+require 'will_paginate/view_helpers/link_renderer'
+
+# = Will Paginate Renderers
+#
+# A collection of custom renderers for the +will_paginate+ helper.
+#
+# == Renderers
+#
+# === Gmail
+#
+# Oldest/Older and Newer/Newest links as needed, as well as
+# "(start) - (end) of (total)" text.
+#
+# === Twitter
+#
+# A single "More" button when there are more results in the collection.
+module WillPaginateRenderers
+ autoload :Gmail, 'will_paginate_renderers/gmail'
+ autoload :Twitter, 'will_paginate_renderers/twitter'
+
+ def self.pagination_options() @pagination_options; end
+ def self.pagination_options=(value) @pagination_options = value; end
+ self.pagination_options = {
+ :twitter_label => 'More',
+ :twitter_class => 'twitter_pagination',
+
+ :gmail_newest_label => "« Newest",
+ :gmail_newer_label => "< Newer",
+ :gmail_older_label => "Older >",
+ :gmail_oldest_label => "Oldest »",
+ :gmail_newest_class => "gmail_newest",
+ :gmail_newer_class => "gmail_newer",
+ :gmail_older_class => "gmail_older",
+ :gmail_oldest_class => "gmail_oldest",
+ :gmail_window_class => "gmail_window",
+ }
+end
@@ -0,0 +1,83 @@
+module WillPaginateRenderers
+ # = Gmail
+ #
+ # A custom WillPaginate link renderer that emulates the Gmail-style
+ # Oldest, Older, (info), Newer, Newest links
+ #
+ # == Customization
+ #
+ # Changing the labels:
+ # WillPaginateRenderers.pagination_options[:gmail_newest_label] = "Newest"
+ # WillPaginateRenderers.pagination_options[:gmail_newer_label] = "Newer"
+ # WillPaginateRenderers.pagination_options[:gmail_older_label] = "Older"
+ # WillPaginateRenderers.pagination_options[:gmail_oldest_label] = "Oldest"
+ #
+ # Changing the CSS class of the links:
+ # WillPaginateRenderers.pagination_options[:gmail_newest_class] = 'newest'
+ # WillPaginateRenderers.pagination_options[:gmail_newer_class] = 'newer'
+ # WillPaginateRenderers.pagination_options[:gmail_older_class] = 'older'
+ # WillPaginateRenderers.pagination_options[:gmail_oldest_class] = 'oldest'
+ # WillPaginateRenderers.pagination_options[:gmail_window_class] = 'window'
+ #
+ # == Option Defaults
+ #
+ # * +gmail_newest_label+: "« Newest"
+ # * +gmail_newer_label+: "< Newer"
+ # * +gmail_older_label+: "Older >"
+ # * +gmail_oldest_label+: "Oldest »"
+ # * +gmail_newest_class+: "gmail_newest"
+ # * +gmail_newer_class+: "gmail_newer"
+ # * +gmail_older_class+: "gmail_older"
+ # * +gmail_oldest_class+: "gmail_oldest"
+ # * +gmail:window_class+: "gmail_window"
+ class Gmail < ::WillPaginate::ViewHelpers::LinkRenderer
+ def pagination
+ [:newest, :newer, :window, :older, :oldest]
+ end
+
+ protected
+
+ def newest
+ return unless @collection.current_page > 2
+
+ previous_or_next_page(1,
+ WillPaginateRenderers.pagination_options[:gmail_newest_label],
+ WillPaginateRenderers.pagination_options[:gmail_newest_class])
+ end
+
+ def newer
+ return unless @collection.previous_page
+
+ previous_or_next_page(@collection.previous_page,
+ WillPaginateRenderers.pagination_options[:gmail_newer_label],
+ WillPaginateRenderers.pagination_options[:gmail_newer_class])
+ end
+
+ def older
+ return unless @collection.next_page
+
+ previous_or_next_page(@collection.next_page,
+ WillPaginateRenderers.pagination_options[:gmail_older_label],
+ WillPaginateRenderers.pagination_options[:gmail_older_class])
+ end
+
+ def oldest
+ return unless @collection.current_page < @collection.total_pages - 1
+
+ previous_or_next_page(@collection.total_pages,
+ WillPaginateRenderers.pagination_options[:gmail_oldest_label],
+ WillPaginateRenderers.pagination_options[:gmail_oldest_class])
+ end
+
+ # Renders the "x - y of z" text
+ def window
+ base = @collection.offset
+ high = base + @collection.per_page
+ high = @collection.total_entries if high > @collection.total_entries
+
+ # TODO: What's the best way to allow customization of this text, particularly "of"?
+ tag(:span, " #{base + 1} - #{high} of #{@collection.total_entries} ",
+ :class => WillPaginateRenderers.pagination_options[:gmail_window_class])
+ end
+ end
+end
@@ -0,0 +1,34 @@
+module WillPaginateRenderers
+ # = Twitter
+ #
+ # A custom WillPaginate link renderer that emulates the Twitter style
+ # "More" link.
+ #
+ # == Customization
+ #
+ # Changing the label:
+ # WillPaginateRenderers.pagination_options[:twitter_label] = "View More"
+ #
+ # Changing the CSS class of the link:
+ # WillPaginateRenderers.pagination_options[:twitter_class] = 'custom_css'
+ #
+ # == Option Defaults
+ #
+ # * +twitter_label+: "More"
+ # * +twitter_class+: +twitter_pagination+
+ class Twitter < ::WillPaginate::ViewHelpers::LinkRenderer
+ def pagination
+ [:next_page]
+ end
+
+ protected
+
+ def next_page
+ return unless @collection.next_page
+
+ previous_or_next_page(@collection.next_page,
+ WillPaginateRenderers.pagination_options[:twitter_label],
+ WillPaginateRenderers.pagination_options[:twitter_class])
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module WillPaginateRenderers
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,56 @@
+$:.unshift(File.expand_path('../../lib', __FILE__))
+
+require 'will_paginate_renderers'
+
+require 'will_paginate/collection'
+require 'will_paginate/view_helpers/base'
+
+# Copied from will_paginate's spec_helper
+module MyExtras
+ protected
+
+ def collection(params = {})
+ if params[:total_pages]
+ params[:per_page] = 1
+ params[:total_entries] = params[:total_pages]
+ end
+ WillPaginate::Collection.new(params[:page] || 1, params[:per_page] || 30, params[:total_entries])
+ end
+
+ def have_deprecation
+ DeprecationMatcher.new
+ end
+end
+
+# Copied from will_paginate's spec_helper
+class DeprecationMatcher
+ def initialize
+ @old_behavior = WillPaginate::Deprecation.behavior
+ @messages = []
+ WillPaginate::Deprecation.behavior = lambda { |message, callstack|
+ @messages << message
+ }
+ end
+
+ def matches?(block)
+ block.call
+ !@messages.empty?
+ ensure
+ WillPaginate::Deprecation.behavior = @old_behavior
+ end
+
+ def failure_message
+ "expected block to raise a deprecation warning"
+ end
+
+ def negative_failure_message
+ "expected block not to raise deprecation warnings, #{@messages.size} raised"
+ end
+end
+
+RSpec.configure do |c|
+ c.mock_with :mocha
+
+ c.include(WillPaginate::ViewHelpers::Base)
+ c.include(MyExtras)
+end
Oops, something went wrong.

0 comments on commit e9ced37

Please sign in to comment.