<commit_before>module Nav
  class Builder
    def initialize( template, options = {} )
      @template, @options = template, options
      @actions = []
      
      yield self if block_given?
    end

    def action( name, options = {}, html_options = {} )
      wrapper_options = {
        :current => html_options.delete(:current),
        :disabled => html_options.delete(:disabled),
        :force_current => html_options.delete(:force_current),
        :url => options,
        :prepend => html_options.delete(:prepend),
        :append => html_options.delete(:append)
      }
      
      @actions << [link_to(name, options, html_options), wrapper_options, options]
    end

    def to_s
      content_tag( :ul, actions.html_safe, @options ).html_safe if actions?
    end


    private

    def actions
      @actions.collect { |a| action_wrapper(*a) }.join
    end

    def actions?
      @actions.any?
    end

    def action_wrapper( contents, options = {}, url_for_options = {} )
      present = [contents, options, url_for_options] # the one we're dealing with
      present_index  = @actions.index( present )
      
      before_present = @actions.at( present_index - 1 ) if present_index > 0
      after_present  = @actions.at( present_index + 1 ) if present_index < @actions.size

      classes = []
      classes << "first" if @actions.first == present
      classes << "last"  if @actions.last == present
      classes << "current"  if current?( *present )
      classes << "disabled" if options.delete(:disabled)
      classes << "before_current" if after_present && current?( *after_present )
      classes << "after_current"  if before_present && current?( *before_present )
      classes << classes.join("_") if classes.any?

      contents = options[:prepend].to_s + contents + options[:append].to_s

      content_tag :li, contents.html_safe, :class => classes.join(" ")
    end

    def current?( contents, options = {}, url_for_options = {} )
      current = options[:current]
      
      is_current = case current
        when TrueClass then true
        when Regexp then request_uri.match(current).nil? ? false : true
        when Proc then current.call
        else false
      end

      return true if is_current && !options[:disabled] && options[:force_current]
      return true if is_current || !url_for_options.is_a?(Symbol) && @template.current_page?(url_for_options) && url_for_options != {} && !options[:disabled]

      false
    end

    def request_uri
      @request_uri or @request_uri = @template.request.request_uri
    end


    def content_tag( *args )
      @template.content_tag( *args ).html_safe
    end

    def link_to( *args )
      @template.link_to( *args ).html_safe
    end
  end
end
<commit_msg>Rails 3 fix for request_uri deprecation<commit_after>module Nav
  class Builder
    def initialize( template, options = {} )
      @template, @options = template, options
      @actions = []
      
      yield self if block_given?
    end

    def action( name, options = {}, html_options = {} )
      wrapper_options = {
        :current => html_options.delete(:current),
        :disabled => html_options.delete(:disabled),
        :force_current => html_options.delete(:force_current),
        :url => options,
        :prepend => html_options.delete(:prepend),
        :append => html_options.delete(:append)
      }
      
      @actions << [link_to(name, options, html_options), wrapper_options, options]
    end

    def to_s
      content_tag( :ul, actions.html_safe, @options ).html_safe if actions?
    end


    private

    def actions
      @actions.collect { |a| action_wrapper(*a) }.join
    end

    def actions?
      @actions.any?
    end

    def action_wrapper( contents, options = {}, url_for_options = {} )
      present = [contents, options, url_for_options] # the one we're dealing with
      present_index  = @actions.index( present )
      
      before_present = @actions.at( present_index - 1 ) if present_index > 0
      after_present  = @actions.at( present_index + 1 ) if present_index < @actions.size

      classes = []
      classes << "first" if @actions.first == present
      classes << "last"  if @actions.last == present
      classes << "current"  if current?( *present )
      classes << "disabled" if options.delete(:disabled)
      classes << "before_current" if after_present && current?( *after_present )
      classes << "after_current"  if before_present && current?( *before_present )
      classes << classes.join("_") if classes.any?

      contents = options[:prepend].to_s + contents + options[:append].to_s

      content_tag :li, contents.html_safe, :class => classes.join(" ")
    end

    def current?( contents, options = {}, url_for_options = {} )
      current = options[:current]
      
      is_current = case current
        when TrueClass then true
        when Regexp then request_uri.match(current).nil? ? false : true
        when Proc then current.call
        else false
      end

      return true if is_current && !options[:disabled] && options[:force_current]
      return true if is_current || !url_for_options.is_a?(Symbol) && @template.current_page?(url_for_options) && url_for_options != {} && !options[:disabled]

      false
    end

    def content_tag( *args )
      @template.content_tag( *args ).html_safe
    end

    def link_to( *args )
      @template.link_to( *args ).html_safe
    end

    def request_uri
      @request_uri or @request_uri = request.respond_to?(:request_uri) ? request.request_uri : request.url
    end

    def request
      @template.request
    end
  end
end

{'fraction_non_alphanumeric': 0.11490572749911064, 'fraction_numerical': 0.0012451085023123443, 'mean_word_length': 2.7586898395721926, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '306067', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1623, 'n_words': 427}