<commit_before>module Refinery
  module Helpers
    module MenuHelper

      # Adds conditional caching
      def cache_if(condition, name = {}, &block)
        if condition
          cache(name, &block)
        else
          yield
        end

        # for <%= style helpers vs <% style
        nil
      end

      # This was extracted from app/views/shared/_menu_branch.html.erb
      # to remove the complexity of that template by reducing logic in the view.
      def css_for_menu_branch(menu_branch, menu_branch_counter, sibling_count = nil, collection = [], selected_item = nil)
        css = []
        css << "selected" if selected_page_or_descendant_page_selected?(menu_branch, collection, selected_item)
        css << "first" if menu_branch_counter == 0
        css << "last" if menu_branch_counter == sibling_count
        css
      end

      # New method which accepts the local_assigns hash.
      # This maps to the older css_for_menu_branch method.
      def menu_branch_css(local_assigns)
        options = {:collection => []}.merge(local_assigns)
        if options.keys.exclude?(:sibling_count) || options[:sibling_count].nil?
          options.update(:sibling_count => options[:menu_branch].shown_siblings.size)
        end
        css_for_menu_branch(options[:menu_branch],
                            options[:menu_branch_counter],
                            options[:sibling_count],
                            options[:collection],
                            options[:selected_item])
      end

      # Determines whether any page underneath the supplied page is the current page according to rails.
      # Just calls selected_page? for each descendant of the supplied page.
      # if you pass a collection it won't check its own descendants but use the collection supplied.
      def descendant_page_selected?(page, collection = [], selected_item = nil)
        return false unless page.has_descendants? or (selected_item && !selected_item.in_menu?)

        descendants = if collection.present? and (!selected_item or (selected_item && selected_item.in_menu?))
          collection.select{ |item| item.parent_id == page.id }
        else
          page.descendants
        end<commit_msg>Re-deprecate css_for_menu_branch so that people know there's a better alternative until 1.1 when it becomes the only option.<commit_after>module Refinery
  module Helpers
    module MenuHelper

      # Adds conditional caching
      def cache_if(condition, name = {}, &block)
        if condition
          cache(name, &block)
        else
          yield
        end

        # for <%= style helpers vs <% style
        nil
      end

      # This was extracted from app/views/shared/_menu_branch.html.erb
      # to remove the complexity of that template by reducing logic in the view.
      def css_for_menu_branch(menu_branch, menu_branch_counter, sibling_count = nil, collection = [], selected_item = nil, warning = true)
        # DEPRECATION. Remove at version 1.1
        if warning
          warn "\n-- DEPRECATION WARNING --"
          warn "The use of 'css_for_menu_branch' is deprecated."
          warn "Please use menu_branch_css(local_assigns) instead."
          warn "Called from: #{caller.detect{|c| c =~ %r{#{Rails.root.to_s}}}.inspect.to_s.split(':in').first}\n\n"
        end

        css = []
        css << "selected" if selected_page_or_descendant_page_selected?(menu_branch, collection, selected_item)
        css << "first" if menu_branch_counter == 0
        css << "last" if menu_branch_counter == sibling_count
        css
      end

      # New method which accepts the local_assigns hash.
      # This maps to the older css_for_menu_branch method.
      def menu_branch_css(local_assigns)
        options = {:collection => []}.merge(local_assigns)
        if options.keys.exclude?(:sibling_count) || options[:sibling_count].nil?
          options.update(:sibling_count => options[:menu_branch].shown_siblings.size)
        end
        css_for_menu_branch(options[:menu_branch],
                            options[:menu_branch_counter],
                            options[:sibling_count],
                            options[:collection],
                            options[:selected_item],
                            false)
      end

      # Determines whether any page underneath the supplied page is the current page according to rails.
      # Just calls selected_page? for each descendant of the supplied page.
      # if you pass a collection it won't check its own descendants but use the collection supplied.
      def descendant_page_selected?(page, collection = [], selected_item = nil)
        return false unless page.has_descendants? or (selected_item && !selected_item.in_menu?)

        descendants = if collection.present? and (!selected_item or (selected_item && selected_item.in_menu?))
          collection.select{ |item| item.parent_id == page.id }
        else
          page.descendants
        end
{'fraction_non_alphanumeric': 0.08217801888687964, 'fraction_numerical': 0.0012055455093429777, 'mean_word_length': 2.435472739820566, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, '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': '1200755', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1314, 'n_words': 391}