<commit_before>module ActionViewExtensions
  def self.included(base)
    base.send :include, InstanceMethods
  end

  module InstanceMethods
    def textilize(content)
      super(h(content)).html_safe
    end

    # Will recursively parse a Hash and any sub hashes to be normal hashes
    # This is useful when exporting hashes to non ruby systems, which don't understand HashWithIndifferentAccess
    def hashify(element)
      if element.is_a? Hash
        element = element.to_hash if element.is_a?(HashWithIndifferentAccess)
        element.each_pair do |key, value|
          element[key] = hashify(value)
        end
      else
        # Must hashify enumerables encase their sub items are hashes
        # Can't enumerate through string as it returns strings, which are also enumerable (stack level too deep)
        if element.respond_to?(:each) && !element.is_a?(String)
          element.map{ |sub| hashify(sub) }
        else
          element
        end
      end
    end

    # Generates a tooltip with given text
    # text is textilized before display
    def tooltip(hover_element_id, text, title='')
      content = "<div style='width: 25em'>#{textilize(text)}</div>"
      "<script>" +
        "new Tip('#{hover_element_id}', '#{escape_javascript(content)}',"+
        "{title : '#{escape_javascript title}', className: 'silver_smaller_div',"+
        "showOn: 'mouseover', hideOn: { event: 'mouseout' }, fixed: false});"+
      "</script>"
    end

    def expandable_list_for(objects, show = 4)
      first, others = objects[0..(show-1)], objects[show..(objects.size-1)]
      first.each do |o|
        yield o
      end
      if others
        haml_tag 'div', :id => 'others', :style => 'display: none' do
          others.each do |o|
            yield o
          end
        end
        "#{others.size} Others - ".html_safe + link_to_function("Show/Hide", "$('others').toggle()")
      end
    end

    def calculate_nested_array
      namespaces + [current_object]
    end

    def breadcrumbs(object_or_nested_array = calculate_nested_array, path = objects_path, options = {})
      object = object_or_nested_array.is_a?(Array) ? object_or_nested_array.last : object_or_nested_array

      link_to(object.class.table_name.titleize, path) + ': ' + if object.new_record?
        'New'
      else
        if options[:index]
          (object.respond_to?(:name) ? object.name : object.to_s)
        else
          text = object.respond_to?(:name) && !object.name.blank? ? object.name : object.to_s
          if controller.respond_to?(:show) && params[:action] == 'edit'
            link_to text, objects_path
          else
            text
          end.to_s + (params[:action] == 'edit' ? ': Edit' : '')
        end
      end
    end
  end

  def boolean_select_tag(name, *args)
    options = args.extract_options!
    options ||= {}
    opts = [['Yes', '1'], ['No', '0']]
    opts = [blank_option] + opts if options[:include_blank]
    select_tag name, options_for_select(opts, options[:selected])
  end
end<commit_msg>updated breadcrumbs with bootstrap markup<commit_after>module ActionViewExtensions
  def self.included(base)
    base.send :include, InstanceMethods
  end

  module InstanceMethods
    def textilize(content)
      super(h(content)).html_safe
    end

    # Will recursively parse a Hash and any sub hashes to be normal hashes
    # This is useful when exporting hashes to non ruby systems, which don't understand HashWithIndifferentAccess
    def hashify(element)
      if element.is_a? Hash
        element = element.to_hash if element.is_a?(HashWithIndifferentAccess)
        element.each_pair do |key, value|
          element[key] = hashify(value)
        end
      else
        # Must hashify enumerables encase their sub items are hashes
        # Can't enumerate through string as it returns strings, which are also enumerable (stack level too deep)
        if element.respond_to?(:each) && !element.is_a?(String)
          element.map{ |sub| hashify(sub) }
        else
          element
        end
      end
    end

    # Generates a tooltip with given text
    # text is textilized before display
    def tooltip(hover_element_id, text, title='')
      content = "<div style='width: 25em'>#{textilize(text)}</div>"
      "<script>" +
        "new Tip('#{hover_element_id}', '#{escape_javascript(content)}',"+
        "{title : '#{escape_javascript title}', className: 'silver_smaller_div',"+
        "showOn: 'mouseover', hideOn: { event: 'mouseout' }, fixed: false});"+
      "</script>"
    end

    def expandable_list_for(objects, show = 4)
      first, others = objects[0..(show-1)], objects[show..(objects.size-1)]
      first.each do |o|
        yield o
      end
      if others
        haml_tag 'div', :id => 'others', :style => 'display: none' do
          others.each do |o|
            yield o
          end
        end
        "#{others.size} Others - ".html_safe + link_to_function("Show/Hide", "$('others').toggle()")
      end
    end

    def calculate_nested_array
      namespaces + [current_object]
    end

    def breadcrumbs(object_or_nested_array = calculate_nested_array, path = objects_path, options = {})
      object = object_or_nested_array.is_a?(Array) ? object_or_nested_array.last : object_or_nested_array
      name = object.respond_to?(:name) && !object.name.blank? ? object.name : object.to_s
      capture_haml do
        haml_tag :ul, :class =>'breadcrumb' do
          haml_tag :li do
            haml_concat link_to(object.class.table_name.titleize, path)
            haml_tag :span, '/'
          end
          if object.new_record?
            haml_tag :li, :class => 'active' do
              haml_concat 'New'
              haml_concat name
            end
          else
            if options[:index]
              haml_tag :li do
                haml_concat name
                haml_tag :span, '/'
              end
            else
              if controller.respond_to?(:show) && params[:action] == 'edit'
                haml_tag :li do
                  haml_concat link_to(name, objects_path)
                  haml_tag :span, '/'
                end
              else
                haml_tag :li do
                  haml_concat name
                  haml_tag :span, '/'
                end
              end
              if (params[:action] == 'edit')
                haml_tag :li, 'Edit', :class => 'active'
              end
            end
          end
        end
      end # end haml_tag
    end # end breadcrumbs
  end # end InstanceMethods

  def boolean_select_tag(name, *args)
    options = args.extract_options!
    options ||= {}
    opts = [['Yes', '1'], ['No', '0']]
    opts = [blank_option] + opts if options[:include_blank]
    select_tag name, options_for_select(opts, options[:selected])
  end
end
{'fraction_non_alphanumeric': 0.10977751756440281, 'fraction_numerical': 0.00234192037470726, 'mean_word_length': 2.289841116995667, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 18, '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': '670864', 'n_tokens_mistral': 2054, 'n_tokens_neox': 2036, 'n_words': 538}