lib/simple_search/view_helper.rb in simple-search-0.12.0 vs lib/simple_search/view_helper.rb in simple-search-0.13.0

- old
+ new

@@ -46,11 +46,11 @@ end # # Returns page related properties in hash # - def page_properties(arel) + def page_properties(arel, page_options={}) total_rows = arel.limit(1000000).offset(0).count # check if page is in an url array matches = request.fullpath.match Regexp.new("\&([a-z_]+)\\[page|page_by\\]=") # &array[page] page_arr_key = (matches && matches.length == 2) ? matches[1] : nil @@ -70,11 +70,11 @@ :total_rows => total_rows, :last_page => last_page, :current_page => (page || 1).to_i, :rows_per_page => (page_by || 30).to_i, :page_arr_key => page_arr_key - } + }.merge(page_options) end # # Returns a url params in hash for the page number given # @@ -89,13 +89,13 @@ end # # Returns page url params in hash with the page number as key # - def page_url_params(arel, options={}) - page_props = options[:page_props] || page_properties(arel) - num_pages = options[:num_pages] || 5 + def page_url_params(arel, page_props=nil) + page_props ||= page_properties(arel) + num_pages = page_props[:num_pages] || 5 num_bf_af = (num_pages-1)/2 current_page = page_props[:current_page] last_page = page_props[:last_page] page_numbers = [1, last_page] @@ -109,14 +109,14 @@ end page_url_params end - def page_urls(arel, http_options={}) + def page_urls(arel, page_options={}, http_options={}) page_urls = [] prev_page = 0 - page_props = page_properties(arel) - page_url_params(arel, :page_props => page_props ).each { |page, url_params| + page_props = page_properties(arel, page_options) + page_url_params(arel, page_props ).each { |page, url_params| if page.to_i > (prev_page+1) # page number jumped up, need to have some indicator page_urls << "<span class='filler'>...</span>" end new_options = page_props[:current_page] == page ? http_options.merge({:class => 'current'}) : http_options page_urls << link_to(page, url_params, new_options)