<commit_before>module Gretel
  module HelperMethods
    include ActionView::Helpers::UrlHelper
    def controller # hack because ActionView::Helpers::UrlHelper needs a controller method
    end
    
    def self.included(base)
      base.send :helper_method, :breadcrumbs, :breadcrumb
    end
    
    def breadcrumb(*args)
      options = args.extract_options!
      name, object = args[0], args[1]
      
      if name
        @_breadcrumb_name = name
        @_breadcrumb_object = object
      else
        if @_breadcrumb_name
          crumb = breadcrumb_for(@_breadcrumb_name, @_breadcrumb_object, options)
        elsif options[:show_root_alone]
          crumb = breadcrumb_for(:root, options)
        end
      end
      
      if crumb && options[:pretext]
        crumb = options[:pretext].html_safe + " " + crumb
      end
      
      crumb
    end
    
    def breadcrumbs(*args)
      options = args.extract_options!
      
      if @_breadcrumb_name
        links = []

        crumb = Crumbs.get_crumb(@_breadcrumb_name, @_breadcrumb_object)
        while link = crumb.links.pop
          links.unshift ViewLink.new(link.text, link.url, link.options)
        end

        while crumb = crumb.parent
          last_parent = crumb.name
          crumb = Crumbs.get_crumb(crumb.name, crumb.object)
          while link = crumb.links.pop
            links.unshift ViewLink.new(link.text, link.url, link.options)
          end
        end

        if options[:autoroot] && @_breadcrumb_name != :root && last_parent != :root
          crumb = Crumbs.get_crumb(:root)
          while link = crumb.links.pop
            links.unshift ViewLink.new(link.text, link.url, link.options)
          end
        end

        last_link = links.pop

        out = []
        while link = links.shift
          out << ViewLink.new(link.text, link.url, link.options)
        end

        if last_link
          out << ViewLink.new(last_link.text, last_link.url, last_link.options, true)
        end
      else
        out = []
      end

      out
    end
    
    def breadcrumb_for(*args)
      options = args.extract_options!
      name, object = args[0], args[1]
      
      links = breadcrumbs(name, object, options)
      
      last_link = links.pop
      
      out = []
      while link = links.shift
        if options[:use_microformats]
          out << content_tag(:div, link_to(content_tag(:span, link.text, :itemprop => "title"), link.url, link.options.merge(:itemprop => "url")), :itemscope => "", :itemtype => "http://data-vocabulary.org/Breadcrumb")
        else
          out << link_to(link.text, link.url)
        end
      end
      
      if last_link
        if options[:link_last] || options[:link_current]
          if options[:use_microformats]
            out << content_tag(:div, link_to(content_tag(:span, last_link.text, :class => "current", :itemprop => "title"), last_link.url, last_link.options.merge(:itemprop => "url")), :itemscope => "", :itemtype => "http://data-vocabulary.org/Breadcrumb")
          else
            out << link_to(last_link.text, last_link.url, :class => "current")
          end
        else
          if options[:use_microformats]
            out << content_tag(:div, content_tag(:span, last_link.text, :class => "current", :itemprop => "title"), :itemscope => "", :itemtype => "http://data-vocabulary.org/Breadcrumb")
          else
            out << content_tag(:span, last_link.text, :class => "current")
          end
        end
      end
      
      out.join(options[:separator] || " &gt; ").html_safe
    end
  end
end<commit_msg>support blank urls<commit_after>module Gretel
  module HelperMethods
    include ActionView::Helpers::UrlHelper
    def controller # hack because ActionView::Helpers::UrlHelper needs a controller method
    end
    
    def self.included(base)
      base.send :helper_method, :breadcrumbs, :breadcrumb
    end
    
    def breadcrumb(*args)
      options = args.extract_options!
      name, object = args[0], args[1]
      
      if name
        @_breadcrumb_name = name
        @_breadcrumb_object = object
      else
        if @_breadcrumb_name
          crumb = breadcrumb_for(@_breadcrumb_name, @_breadcrumb_object, options)
        elsif options[:show_root_alone]
          crumb = breadcrumb_for(:root, options)
        end
      end
      
      if crumb && options[:pretext]
        crumb = options[:pretext].html_safe + " " + crumb
      end
      
      crumb
    end
    
    def breadcrumbs(*args)
      options = args.extract_options!
      
      if @_breadcrumb_name
        links = []

        crumb = Crumbs.get_crumb(@_breadcrumb_name, @_breadcrumb_object)
        while link = crumb.links.pop
          links.unshift ViewLink.new(link.text, link.url, link.options)
        end

        while crumb = crumb.parent
          last_parent = crumb.name
          crumb = Crumbs.get_crumb(crumb.name, crumb.object)
          while link = crumb.links.pop
            links.unshift ViewLink.new(link.text, link.url, link.options)
          end
        end

        if options[:autoroot] && @_breadcrumb_name != :root && last_parent != :root
          crumb = Crumbs.get_crumb(:root)
          while link = crumb.links.pop
            links.unshift ViewLink.new(link.text, link.url, link.options)
          end
        end

        last_link = links.pop

        out = []
        while link = links.shift
          out << ViewLink.new(link.text, link.url, link.options)
        end

        if last_link
          out << ViewLink.new(last_link.text, last_link.url, last_link.options, true)
        end
      else
        out = []
      end

      out
    end
    
    def breadcrumb_for(*args)
      options = args.extract_options!
      name, object = args[0], args[1]
      
      links = breadcrumbs(name, object, options)
      
      last_link = links.pop
      
      out = []
      while link = links.shift
        out << get_crumb(link.text, link.url, options[:use_microformats], "", link.options)
      end
      
      if last_link
        if options[:link_last] || options[:link_current]
          out << get_crumb(last_link.text, last_link.url, options[:use_microformats], "current", last_link.options)
        else
          out << get_crumb(last_link.text, nil, options[:use_microformats], "current")
        end
      end
      
      out.join(options[:separator] || " &gt; ").html_safe
    end
    
    def get_crumb(text, url, use_microformats, css_class, options = {})
      if url.blank?
        if use_microformats
          content_tag(:div, content_tag(:span, text, :class => css_class, :itemprop => "title"), :itemscope => "", :itemtype => "http://data-vocabulary.org/Breadcrumb")
        else
          content_tag(:span, text, :class => css_class)
        end
      else
        if use_microformats
          content_tag(:div, link_to(content_tag(:span, text, :class => css_class, :itemprop => "title"), url, options.merge(:itemprop => "url")), :itemscope => "", :itemtype => "http://data-vocabulary.org/Breadcrumb")
        else
          link_to(text, url, :class => css_class)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1116083916083916, 'fraction_numerical': 0.0011188811188811189, 'mean_word_length': 2.135028496273564, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '2461380', 'n_tokens_mistral': 2244, 'n_tokens_neox': 2235, 'n_words': 467}