<commit_before>module EffectiveMenusHelper
  def render_menu(menu, options = {}, &block)
    menu = Effective::Menu.find_by_title(menu) if menu.kind_of?(String)
    return "<ul class='nav navbar-nav'><li>Menu '#{menu}' does not exist</li></ul>".html_safe if !menu.present?

    if (effectively_editting? && EffectivePages.authorized?(controller, :edit, menu) rescue false)
      options[:menu_id] = menu.id
      form_for(menu, :url => '/') { |form| options[:form] = form }
    end

    if block_given? && options[:form].blank?
      render_menu_items(menu.menu_items, options) { yield }
    else
      render_menu_items(menu.menu_items, options)
    end

    # if options[:for_editor]
    #else
    #  Rails.cache.fetch(menu) { render_menu_items(menu.menu_items, options) }
    #end
  end

  def render_menu_items(items, options = {}, &block)
    if options[:form].present? && options[:form].kind_of?(ActionView::Helpers::FormBuilder) == false
      raise 'Expecting ActionView::Helpers::FormBuilder object for :form => option'
    end

    html = ''

    if options[:form]
      html << "<ul class='nav navbar-nav effective-menu #{options[:class]}'"
        html << " data-effective-menu-id='#{options[:menu_id] || 0}'"
        html << " data-effective-menu-expand-html=\"#{render(:partial => 'admin/menu_items/expand').gsub('"', "'").gsub("\n", '').gsub('  ', '')}\""
        html << " data-effective-menu-new-html=\"#{render(:partial => 'admin/menu_items/new', :locals => { :item => Effective::MenuItem.new(), :form => options[:form] }).gsub('"', "'").gsub("\n", '').gsub('  ', '').gsub('[0]', '[:new]').gsub('_0_', '_:new_')}\""

        maxdepth = ((options[:maxdepth].presence || EffectivePages.menu[:maxdepth].presence).to_i rescue 0)
        html << " data-effective-menu-maxdepth='#{maxdepth}'" if maxdepth > 0

      html << ">"
    else
      html << "<ul class='nav navbar-nav#{' ' + options[:class].to_s if options[:class].present?}'>"<commit_msg>sort by lft when new record<commit_after>module EffectiveMenusHelper
  def render_menu(menu, options = {}, &block)
    menu = Effective::Menu.find_by_title(menu) if menu.kind_of?(String)
    return "<ul class='nav navbar-nav'><li>Menu '#{menu}' does not exist</li></ul>".html_safe if !menu.present?

    if (effectively_editting? && EffectivePages.authorized?(controller, :edit, menu) rescue false)
      options[:menu_id] = menu.id
      form_for(menu, :url => '/') { |form| options[:form] = form }
    end

    menu_items = menu.menu_items

    if menu.new_record?
      menu_items = menu_items.to_a.sort! { |a, b| a.lft <=> b.lft }
    end

    if block_given? && options[:form].blank?
      render_menu_items(menu_items, options) { yield }
    else
      render_menu_items(menu_items, options)
    end

    # if options[:for_editor]
    #else
    #  Rails.cache.fetch(menu) { render_menu_items(menu.menu_items, options) }
    #end
  end

  def render_menu_items(items, options = {}, &block)
    if options[:form].present? && options[:form].kind_of?(ActionView::Helpers::FormBuilder) == false
      raise 'Expecting ActionView::Helpers::FormBuilder object for :form => option'
    end

    html = ''

    if options[:form]
      html << "<ul class='nav navbar-nav effective-menu #{options[:class]}'"
        html << " data-effective-menu-id='#{options[:menu_id] || 0}'"
        html << " data-effective-menu-expand-html=\"#{render(:partial => 'admin/menu_items/expand').gsub('"', "'").gsub("\n", '').gsub('  ', '')}\""
        html << " data-effective-menu-new-html=\"#{render(:partial => 'admin/menu_items/new', :locals => { :item => Effective::MenuItem.new(), :form => options[:form] }).gsub('"', "'").gsub("\n", '').gsub('  ', '').gsub('[0]', '[:new]').gsub('_0_', '_:new_')}\""

        maxdepth = ((options[:maxdepth].presence || EffectivePages.menu[:maxdepth].presence).to_i rescue 0)
        html << " data-effective-menu-maxdepth='#{maxdepth}'" if maxdepth > 0

      html << ">"
    else
      html << "<ul class='nav navbar-nav#{' ' + options[:class].to_s if options[:class].present?}'>"
{'fraction_non_alphanumeric': 0.20093573011573504, 'fraction_numerical': 0.002462447672986949, 'mean_word_length': 3.824228028503563, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 32, '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': '2871926', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1346, 'n_words': 253}