class SimplePaginate::Helpers::Tag
Public Class Methods
new(template, options = {})
click to toggle source
# File lib/simple_paginate/helpers/tags.rb, line 7 def initialize(template, options = {}) @template, @options = template, options @views_prefix = @options.delete(:views_prefix) @params = template.params @params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h) @params = @params.with_indifferent_access @params.except!(*PARAM_KEY_BLACKLIST) @params.merge!(@options.delete(:params) || {}) end
Public Instance Methods
page_url_for(page)
click to toggle source
# File lib/simple_paginate/helpers/tags.rb, line 21 def page_url_for(page) @template.url_for params_for(page).merge(only_path: true) end
to_s(locals = {})
click to toggle source
# File lib/simple_paginate/helpers/tags.rb, line 17 def to_s(locals = {}) @template.render partial: partial_path, locals: @options.merge(locals), formats: [:html] end
Private Instance Methods
params_for(page)
click to toggle source
# File lib/simple_paginate/helpers/tags.rb, line 27 def params_for(page) page_params = Rack::Utils.parse_nested_query("#{PARAM_NAME}=#{page}") page_params = @params.deep_merge(page_params) if page <= 1 PARAM_NAME.to_s.scan(/\w+/)[0..-2].inject(page_params){|h, k| h[k] }[$&] = nil end page_params end
partial_path()
click to toggle source
# File lib/simple_paginate/helpers/tags.rb, line 38 def partial_path [@views_prefix, 'simple_paginate', self.class.name.demodulize.underscore ].compact.join('/') end