<commit_before>require 'singleton'

module SimpleNavigation
  
  # Responsible for evaluating and handling the config/navigation.rb file. 
  class Configuration
    include Singleton
    
    attr_accessor :renderer, :selected_class, :autogenerate_item_ids, :id_generator, :auto_highlight
    attr_reader :render_all_levels
    attr_reader :primary_navigation

    class << self

      # Evals the config_file for the given navigation_context inside the specified context (usually a controller or view)
      def eval_config(context, navigation_context = :default)
        SimpleNavigation.controller = extract_controller_from context
        SimpleNavigation.template = SimpleNavigation.controller.instance_variable_get(:@template)
        context_for_eval.instance_eval(SimpleNavigation.config_files[navigation_context])
      end
      
      # Starts processing the configuration
      def run(&block)
        block.call Configuration.instance
      end    

      # Returns the context in which the config file should be evaluated.
      # This is preferably the template, otherwise te controller
      def context_for_eval
        raise 'no context set for evaluation the config file' unless SimpleNavigation.template || SimpleNavigation.controller
        SimpleNavigation.template || SimpleNavigation.controller
      end

      # Extracts a controller from the context.
      def extract_controller_from(context)
        if context.respond_to? :controller
          context.controller
        else
          context
        end
      end
      
    end #class << self
    
    # Sets the config's default-settings
    def initialize
      @renderer = SimpleNavigation::Renderer::List
      @selected_class = 'selected'
      @autogenerate_item_ids = true
      @id_generator = Proc.new {|id| id.to_s }
      @auto_highlight = true
    end
  
    def render_all_levels=(do_it)
      ActiveSupport::Deprecation.warn("Setting render_all_levels in the config-file has been deprected. Please use render_navigation(:expand_all => true) instead")
      @render_all_levels = do_it
    end<commit_msg>+ api doc<commit_after>require 'singleton'

module SimpleNavigation
  
  # Responsible for evaluating and handling the config/navigation.rb file. 
  class Configuration
    include Singleton
    
    attr_accessor :renderer, :selected_class, :autogenerate_item_ids, :id_generator, :auto_highlight
    attr_reader :render_all_levels
    attr_reader :primary_navigation

    class << self

      # Evals the config_file for the given navigation_context inside the specified context (usually a controller or view)
      def eval_config(context, navigation_context = :default)
        SimpleNavigation.controller = extract_controller_from context
        SimpleNavigation.template = SimpleNavigation.controller.instance_variable_get(:@template)
        context_for_eval.instance_eval(SimpleNavigation.config_files[navigation_context])
      end
      
      # Starts processing the configuration
      def run(&block)
        block.call Configuration.instance
      end    

      # Returns the context in which the config file should be evaluated.
      # This is preferably the template, otherwise te controller
      def context_for_eval
        raise 'no context set for evaluation the config file' unless SimpleNavigation.template || SimpleNavigation.controller
        SimpleNavigation.template || SimpleNavigation.controller
      end

      # Extracts a controller from the context.
      def extract_controller_from(context)
        if context.respond_to? :controller
          context.controller
        else
          context
        end
      end
      
    end #class << self
    
    # Sets the config's default-settings
    def initialize
      @renderer = SimpleNavigation::Renderer::List
      @selected_class = 'selected'
      @autogenerate_item_ids = true
      @id_generator = Proc.new {|id| id.to_s }
      @auto_highlight = true
    end
  
    # Adds a deprecation warning when this options is set in the config file
    def render_all_levels=(do_it)
      ActiveSupport::Deprecation.warn("Setting render_all_levels in the config-file has been deprected. Please use render_navigation(:expand_all => true) instead")
      @render_all_levels = do_it
    end
{'fraction_non_alphanumeric': 0.05707602339181286, 'fraction_numerical': 0.0, 'mean_word_length': 3.171707317073171, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '916419', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1060, 'n_words': 326}