<commit_before>#
# defines a one-stop shop for displaying pagination links using the method
# pagination_links().
#
# all the code should use pagination_links() rather than call
# will_paginate() directly.
#
module Common::Ui::PaginationHelper

  protected

#  def letter_pagination_labels
#    $letter_pagination_labels_list ||= ("A".."Z").to_a + ["#"]
#  end

#  def letter_pagination_links(url_opts = {}, pagination_opts = {}, &url_proc)
#    url_proc = method :url_for if url_proc.nil?
#    available_letters = pagination_opts[:available_letters]
#    if available_letters and !available_letters.grep(/^[^a-z]/i).empty?
#      # we have things that are not letters in the mix
#      available_letters << "#"
#    end

#    render  :partial => 'pages/letter_pagination',
#                        :locals => {:letter_labels => letter_pagination_labels,
#                                    :available_letters => pagination_opts[:available_letters],
#                                    :url_proc => url_proc,
#                                    :url_opts => url_opts,
#                                    }
#  end

  #
  # Default pagination link options:
  #
  #   :class        => 'pagination',
  #   :previous_label   => '&laquo; Previous',
  #   :next_label   => 'Next &raquo;',
  #   :inner_window => 4, # links around the current page
  #   :outer_window => 1, # links around beginning and end
  #   :separator    => ' ',
  #   :param_name   => :page,
  #   :params       => nil,
  #   :renderer     => 'WillPaginate::ViewHelper::LinkRenderer',
  #   :page_links   => true,    # when false, only previous/next links are rendered
  #   :container    => true
  #
  def pagination_links(things, options={})
    return unless things.respond_to?(:total_pages)

    defaults = {
     :previous_label => ("&laquo; %s" % :pagination_previous.t).html_safe,
     :next_label => ("%s &raquo;" % :pagination_next.t).html_safe,
     :inner_window => 2,
     :outer_window => 0
    }

    if defined? page_search_path
      if xhr_page_search?
        defaults[:renderer] = LinkRenderer::AjaxPages
      else
        defaults[:renderer] = LinkRenderer::Pages
      end
    elsif request.xhr?
      defaults[:renderer] = (current_template_format == :html) ?
       LinkRenderer::ModalAjax :
       LinkRenderer::Ajax
    else
      defaults[:renderer] = LinkRenderer::Dispatch
    end
    will_paginate(things, defaults.merge(options))
  end

  def current_template_format
    ## FIXME: this is likely going to break during the next rails upgrade.
    ##   We should figure out a better way to choose the link renderer.
    @renderer.instance_variable_get("@template").mime_type.symbol
  end

  #
  # returns true if the array of things is actually paginated
  #
  def paginated?(things)
    things.is_a?(WillPaginate::Collection) and things.total_entries > things.per_page
  end

  #
  # used at the top of a page where you want a little space after the pagination links,
  # but only if there are any pagination links.
  #
  def top_pagination_links(things, options={})<commit_msg>fixed bug with how we use the new version of will-paginate<commit_after>#
# defines a one-stop shop for displaying pagination links using the method
# pagination_links().
#
# all the code should use pagination_links() rather than call
# will_paginate() directly.
#
module Common::Ui::PaginationHelper

  protected

#  def letter_pagination_labels
#    $letter_pagination_labels_list ||= ("A".."Z").to_a + ["#"]
#  end

#  def letter_pagination_links(url_opts = {}, pagination_opts = {}, &url_proc)
#    url_proc = method :url_for if url_proc.nil?
#    available_letters = pagination_opts[:available_letters]
#    if available_letters and !available_letters.grep(/^[^a-z]/i).empty?
#      # we have things that are not letters in the mix
#      available_letters << "#"
#    end

#    render  :partial => 'pages/letter_pagination',
#                        :locals => {:letter_labels => letter_pagination_labels,
#                                    :available_letters => pagination_opts[:available_letters],
#                                    :url_proc => url_proc,
#                                    :url_opts => url_opts,
#                                    }
#  end

  #
  # Default pagination link options:
  #
  #   :class        => 'pagination',
  #   :previous_label   => '&laquo; Previous',
  #   :next_label   => 'Next &raquo;',
  #   :inner_window => 4, # links around the current page
  #   :outer_window => 1, # links around beginning and end
  #   :separator    => ' ',
  #   :param_name   => :page,
  #   :params       => nil,
  #   :renderer     => 'WillPaginate::ViewHelper::LinkRenderer',
  #   :page_links   => true,    # when false, only previous/next links are rendered
  #   :container    => true
  #
  def pagination_links(things, options={})
    return unless things.respond_to?(:total_pages)

    defaults = {
     :previous_label => ("&laquo; %s" % :pagination_previous.t).html_safe,
     :next_label => ("%s &raquo;" % :pagination_next.t).html_safe,
     :inner_window => 2,
     :outer_window => 0
    }

    if defined? page_search_path
      if xhr_page_search?
        defaults[:renderer] = LinkRenderer::AjaxPages
      else
        defaults[:renderer] = LinkRenderer::Pages
      end
    elsif request.xhr?
      defaults[:renderer] = (current_template_format == :html) ?
       LinkRenderer::ModalAjax :
       LinkRenderer::Ajax
    else
      defaults[:renderer] = LinkRenderer::Dispatch
    end
    will_paginate(things, defaults.merge(options))
  end

  def current_template_format
    ## FIXME: this is likely going to break during the next rails upgrade.
    ##   We should figure out a better way to choose the link renderer.
    @renderer.instance_variable_get("@template").mime_type.symbol
  end

  #
  # returns true if the array of things is actually paginated
  #
  def paginated?(things)
    things.respond_to?(:total_entries) && things.total_entries > things.per_page
  end

  #
  # used at the top of a page where you want a little space after the pagination links,
  # but only if there are any pagination links.
  #
  def top_pagination_links(things, options={})
{'fraction_non_alphanumeric': 0.11268969970939618, 'fraction_numerical': 0.0012915724895059735, 'mean_word_length': 2.782051282051282, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '357624', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1866, 'n_words': 474}