├── install.rb ├── uninstall.rb ├── lib ├── partial_renderer.rb └── will_paginate │ └── partial_renderer.rb ├── init.rb ├── test ├── test_helper.rb └── partial_renderer_test.rb ├── tasks └── partial_renderer_tasks.rake ├── generators └── partial_renderer │ ├── templates │ ├── pagination.haml │ └── pagination.erb │ ├── USAGE │ └── partial_renderer_generator.rb ├── Rakefile ├── README └── MIT-LICENSE /install.rb: -------------------------------------------------------------------------------- 1 | # Install hook code here 2 | -------------------------------------------------------------------------------- /uninstall.rb: -------------------------------------------------------------------------------- 1 | # Uninstall hook code here 2 | -------------------------------------------------------------------------------- /lib/partial_renderer.rb: -------------------------------------------------------------------------------- 1 | require 'will_paginate/partial_renderer' 2 | -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "lib", "partial_renderer") 2 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'active_support' 3 | require 'active_support/test_case' -------------------------------------------------------------------------------- /tasks/partial_renderer_tasks.rake: -------------------------------------------------------------------------------- 1 | # desc "Explaining what the task does" 2 | # task :partial_renderer do 3 | # # Task goes here 4 | # end 5 | -------------------------------------------------------------------------------- /test/partial_renderer_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class PartialRendererTest < ActiveSupport::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /generators/partial_renderer/templates/pagination.haml: -------------------------------------------------------------------------------- 1 | - if previous_page 2 | = link_to options[:previous_label], url_for_page(previous_page) 3 | - else 4 | = options[:previous_label] 5 | 6 | - for i in first_page.upto(last_page) 7 | - if i == current_page 8 | = i 9 | - else 10 | = link_to i, url_for_page(i) 11 | 12 | - if next_page 13 | = link_to options[:next_label], url_for_page(next_page) 14 | - else 15 | = options[:next_label] 16 | -------------------------------------------------------------------------------- /generators/partial_renderer/templates/pagination.erb: -------------------------------------------------------------------------------- 1 | <% if previous_page %> 2 | <%= link_to options[:previous_label], url_for_page(previous_page) %> 3 | <% else %> 4 | <% = options[:previous_label] %> 5 | <% end %> 6 | 7 | <% for i in first_page.upto(last_page) %> 8 | <% if i == current_page %> 9 | <%= i %> 10 | <% else %> 11 | <%= link_to i, url_for_page(i) %> 12 | <% end %> 13 | <% end %> 14 | 15 | <% if next_page %> 16 | <%= link_to options[:next_label], url_for_page(next_page) %> 17 | <% else %> 18 | <%= options[:next_label] %> 19 | <% end %> 20 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 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 partial_renderer plugin.' 9 | Rake::TestTask.new(:test) do |t| 10 | t.libs << 'lib' 11 | t.libs << 'test' 12 | t.pattern = 'test/**/*_test.rb' 13 | t.verbose = true 14 | end 15 | 16 | desc 'Generate documentation for the partial_renderer plugin.' 17 | Rake::RDocTask.new(:rdoc) do |rdoc| 18 | rdoc.rdoc_dir = 'rdoc' 19 | rdoc.title = 'PartialRenderer' 20 | rdoc.options << '--line-numbers' << '--inline-source' 21 | rdoc.rdoc_files.include('README') 22 | rdoc.rdoc_files.include('lib/**/*.rb') 23 | end 24 | -------------------------------------------------------------------------------- /generators/partial_renderer/USAGE: -------------------------------------------------------------------------------- 1 | Description: 2 | Partial renderer generates view partial for use with WillPaginate::PartialRenderer class. 3 | Partial can be in haml(default) or erb format. 4 | You can specify the name of partial, default is 'pagination' ('app/views/_pagination.haml') 5 | 6 | Example: 7 | ./script/generate partial_renderer go 8 | 9 | This will create: 10 | app/views/_partial.haml 11 | 12 | With partial name arg 13 | ./script/generate partial_renderer pages 14 | 15 | This will create: 16 | app/views/_pages.haml 17 | 18 | With partial name and format args 19 | ./script/generate partial_renderer pages --format=erb 20 | 21 | This will create: 22 | app/views/_pages.erb 23 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | PartialRenderer 2 | =============== 3 | 4 | PartialRenderer let's you to use view partials for displaying pagination. 5 | Default generated partial's look is similar to those LinkRenderer renders 6 | 7 | 8 | To install use command 9 | ./script/plugin install git://github.com/html/partial_renderer.git 10 | 11 | or 12 | 13 | git submodule add git://github.com/html/partial_renderer.git vendor/plugins/partial_renderer/ 14 | 15 | 16 | and generate simple view partial 17 | 18 | ./script/generate partial_renderer go 19 | 20 | Example 21 | ======= 22 | 23 | ./script/generate partial_renderer go 24 | 25 | create app/views/_pagination.haml 26 | 27 | Now you have pagination like with WillPaginate::LinkRenderer, but you can change it's look and feel in your view partial 28 | 29 | Copyright (c) 2009 Olexiy Zamkoviy, released under the MIT license 30 | -------------------------------------------------------------------------------- /generators/partial_renderer/partial_renderer_generator.rb: -------------------------------------------------------------------------------- 1 | class PartialRendererGenerator < Rails::Generator::NamedBase 2 | 3 | def initialize(runtime_args, runtime_options = {}) 4 | super 5 | 6 | if runtime_args[0] == 'go' 7 | options[:file_name] = 'pagination' 8 | else 9 | options[:file_name] = runtime_args[0] 10 | end 11 | 12 | if options[:format].nil? 13 | options[:format] = 'haml' 14 | end 15 | 16 | end 17 | 18 | def manifest 19 | 20 | record do |m| 21 | m.file "pagination.#{options[:format]}", "app/views/_#{options[:file_name]}.#{options[:format]}" 22 | end 23 | end 24 | 25 | def add_options!(opt) 26 | opt.separator '' 27 | opt.separator 'Options:' 28 | opt.on("--haml", "Generate haml template") { |v| options[:format] = "haml"; } 29 | opt.on("--erb", "Generate erb template") { |v| options[:format] = "erb"; } 30 | 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 [name of plugin creator] 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. 21 | -------------------------------------------------------------------------------- /lib/will_paginate/partial_renderer.rb: -------------------------------------------------------------------------------- 1 | require "will_paginate" 2 | 3 | module WillPaginate 4 | class PartialRenderer < (WillPaginate::VERSION::MAJOR == 2 ? WillPaginate::LinkRenderer : WillPaginate::ViewHelpers::LinkRenderer) 5 | def prepare(collection, options, template) 6 | @collection = collection 7 | @options = options 8 | @template = template 9 | 10 | if WillPaginate::VERSION::MAJOR == 2 11 | if !@template.respond_to?(:url_for_page) 12 | m = method(:url_for) 13 | @template.instance_eval do |cl| 14 | @url_for_page = m 15 | def url_for_page(page) 16 | @url_for_page.call page 17 | end 18 | end 19 | end 20 | else 21 | if !@template.respond_to?(:url_for_page) 22 | @template.instance_eval do |cl| 23 | def url_for_page(page) 24 | @template.url_for(:page => page) 25 | end 26 | end 27 | end 28 | end 29 | end 30 | 31 | def to_html 32 | locals = { 33 | :first_page => 1, 34 | :last_page => @collection.total_pages, 35 | :previous_page => @collection.previous_page, 36 | :next_page => @collection.next_page, 37 | :total_pages => @collection.total_pages, 38 | :current_page => @collection.current_page, 39 | :per_page => @collection.per_page, 40 | :options => @options 41 | } 42 | 43 | @template.render :partial => @options[:partial], :locals => locals 44 | end 45 | end 46 | end 47 | 48 | WillPaginate::ViewHelpers::pagination_options[:renderer] = 'WillPaginate::PartialRenderer' 49 | WillPaginate::ViewHelpers::pagination_options[:partial] = '/pagination' 50 | --------------------------------------------------------------------------------