Sha256: 2928774b98800c00d85eff416f304220d085175306c1fc21bf2ec6a52a1c5327

Contents?: true

Size: 1.53 KB

Versions: 8

Compression:

Stored size: 1.53 KB

Contents

module Patches
  module Kaminari
    module Helpers
      module Tag
        def self.included(klass)
          klass.class_eval do
            remove_method :page_url_for
          end
        end

        def page_url_for page
          p = params_for(page)
          p.delete :controller
          p.delete :action
          # TODO: make sure paging works with new related handling
          if p["related"]
            p["related"]["page"] = p["page"]
            p["related"]["subslot"] = true
            p = p["related"]
          end
          mark = p.delete("mark") || p.delete("name")
          Card.fetch(mark).format.path p
        end

        private

        def params_for page
          page_params = Rack::Utils.parse_nested_query "#{@param_name}=#{page}"
          page_params = @params.with_indifferent_access.deep_merge(page_params)

          if ::Kaminari.config.respond_to?(:params_on_first_page) &&
             !::Kaminari.config.params_on_first_page && page <= 1
            # This converts a hash:
            #   from: {other: "params", page: 1}
            #     to: {other: "params", page: nil}
            #   (when @param_name == "page")
            #
            #   from: {other: "params", user: {name: "yuki", page: 1}}
            #     to: {other: "params", user: {name: "yuki", page: nil}}
            #   (when @param_name == "user[page]")
            @param_name.to_s.scan(/\w+/)[0..-2]
              .inject(page_params) { |h, k| h[k] }[$&] = nil
          end

          page_params
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
card-1.96.8 config/initializers/02_patches/kaminari.rb
card-1.96.7 config/initializers/02_patches/kaminari.rb
card-1.96.6 config/initializers/02_patches/kaminari.rb
card-1.96.5 config/initializers/02_patches/kaminari.rb
card-1.96.4 config/initializers/02_patches/kaminari.rb
card-1.96.3 config/initializers/02_patches/kaminari.rb
card-1.96.2 config/initializers/02_patches/kaminari.rb
card-1.96.1 config/initializers/02_patches/kaminari.rb