<commit_before># encoding: utf-8

require 'loaf/crumb_formatter'
require 'loaf/options_validator'

module Loaf
  module ViewExtensions
    include Loaf::CrumbFormatter
    include Loaf::OptionsValidator

    # Checks to see if any breadcrumbs have been added
    #
    def has_breadcrumbs?
      _breadcrumbs.present?
    end

    # Adds breadcrumbs inside view.
    #
    def breadcrumb(name, url, options={})
      _breadcrumbs.push Loaf::Crumb.new(name, url, options[:force])
    end
    alias :add_breadcrumb :breadcrumb

    # Renders breadcrumbs inside view.
    #
    def breadcrumbs(options={}, &block)
      #builder = Loaf::Builder.new(options)
      valid? options
      options = Loaf.config.merge(options)
      _breadcrumbs.each do |crumb|
        name = format_name crumb, options

        url = url_for _process_url_for(crumb.url)

        styles = (current_page?(url) || crumb.force) ? "#{options[:style_classes]}" : ''

        block.call(name, url, styles)
      end
    end

    private

    def _process_url_for(url)
      if url.is_a?(String) || url.is_a?(Symbol)
        return respond_to?(url) ? send(url) : url
      else
        return url
      end
    end

  end # ViewExtensions
end # Loaf<commit_msg>Rewrite view extensions to be more robust and add docs.<commit_after># encoding: utf-8

require 'loaf/crumb_formatter'
require 'loaf/options_validator'

module Loaf
  # A mixin to define view extensions
  module ViewExtensions
    include Loaf::CrumbFormatter
    include Loaf::OptionsValidator

    def initialize(*)
      @_breadcrumbs ||= []
      super
    end

    # Checks to see if any breadcrumbs have been added
    #
    # @return [Boolean]
    #
    # @api public
    def breadcrumbs?
      _breadcrumbs.present?
    end

    # Adds breadcrumbs inside view.
    #
    # @param [String] name
    #   the breadcrumb name
    # @param [Object] url
    #   the breadcrumb url
    # @param [Hash] options
    #   the breadcrumb options
    #
    # @api public
    def breadcrumb(name, url, options = {})
      _breadcrumbs << Loaf::Crumb.new(name, url, options)
    end
    alias_method :add_breadcrumb, :breadcrumb

    # Renders breadcrumbs inside view.
    #
    # @param [Hash] options
    #
    # @api public
    def breadcrumbs(options = {}, &block)
      # builder = Loaf::Builder.new(options)
      return enum_for(:breadcrumbs) unless block_given?
      valid?(options)
      options = Loaf.config.merge(options)
      _breadcrumbs.each do |crumb|
        name   = format_name(crumb.name, options)
        url    = url_for(_process_url_for(crumb.url))
        styles = ''
        if current_page?(url) || crumb.force
          styles << "#{options[:style_classes]}"
        end
        block.call(name, url, styles)
      end
    end

    private

    # @api private
    def _process_url_for(url)
      if url.is_a?(String) || url.is_a?(Symbol)
        return respond_to?(url) ? send(url) : url
      else
        return url
      end
    end
  end # ViewExtensions
end # Loaf
{'fraction_non_alphanumeric': 0.09897384971863621, 'fraction_numerical': 0.0006620324395895399, 'mean_word_length': 2.53864168618267, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '7120654', 'n_tokens_mistral': 982, 'n_tokens_neox': 990, 'n_words': 244}