Sha256: 14d77f47fbd33d612c0a97297f55e7cd0e6c16269c833a552cbaf788c0d3704c

Contents?: true

Size: 754 Bytes

Versions: 10

Compression:

Stored size: 754 Bytes

Contents

require 'routing_filter/base'

module RoutingFilter
  class Pagination < Base
    def around_recognize(path, env, &block)
      page = extract_page!(path)
      returning yield(path, env) do |params|
        params[:page] = page.to_i if page
      end
    end

    def around_generate(*args, &block)
      page = args.extract_options!.delete(:page)
      returning yield do |result|
        if page && page != 1
          url = result.is_a?(Array) ? result.first : result
          append_page!(url, page)
        end
      end
    end

    protected

      def extract_page!(path)
        path.sub! %r(/pages/([\d]+)/?$), ''
        $1
      end

      def append_page!(url, page)
        url.sub!(/($|\?)/) { "/pages/#{page}#{$1}" }
      end
  end
end

Version data entries

10 entries across 10 versions & 6 rubygems

Version Path
strikeroff-routing-filter-0.0.1 lib/routing_filter/pagination.rb
strikeroff-routing-filter-0.0.2 lib/routing_filter/pagination.rb
svenfuchs-routing-filter-0.0.1 lib/routing_filter/pagination.rb
trollied-0.1.2 test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb
trollied-0.1.1 test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb
trollied-0.1.0 test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb
mongo_translatable-0.1.0 test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb
oembed_provider-0.1.1 test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb
oembed_provider-0.1.0 test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb
routing-filter-0.0.1 lib/routing_filter/pagination.rb