<commit_before>require 'rails_admin/i18n_support'

module RailsAdmin
  module ApplicationHelper

    include RailsAdmin::I18nSupport

    def authorized?(*args)
      @authorization_adapter.nil? || @authorization_adapter.authorized?(*args)
    end

    def current_action?(action, abstract_model = @abstract_model, object = @object)
      @action.custom_key == action.custom_key &&
      abstract_model.try(:to_param) == @abstract_model.try(:to_param) &&
      (@object.try(:persisted?) ? @object.id == object.try(:id) : !object.try(:persisted?))
    end

    def action(key, abstract_model = nil, object = nil)
      RailsAdmin::Config::Actions.find(key, { :controller => self.controller, :abstract_model => abstract_model, :object => object })
    end

    def actions(scope = :all, abstract_model = nil, object = nil)
      RailsAdmin::Config::Actions.all(scope, { :controller => self.controller, :abstract_model => abstract_model, :object => object })
    end

    def edit_user_link
      return nil unless authorized?(:edit, _current_user.class, _current_user) && _current_user.respond_to?(:email)
      return nil unless abstract_model = RailsAdmin.config(_current_user.class).abstract_model
      return nil unless edit_action = RailsAdmin::Config::Actions.find(:edit, {:controller => self.controller, :abstract_model => abstract_model, :object => _current_user })
      link_to _current_user.email, url_for(:action => edit_action.action_name, :model_name => abstract_model.to_param, :id => _current_user.id, :controller => 'rails_admin/main')
    end

    def wording_for(label, action = @action, abstract_model = @abstract_model, object = @object)
      model_config = abstract_model.try(:config)
      object = abstract_model && object.is_a?(abstract_model.model) ? object : nil
      action = RailsAdmin::Config::Actions.find(action.to_sym) if (action.is_a?(Symbol) || action.is_a?(String))

      I18n.t("admin.actions.#{action.i18n_key}.#{label}",
        :model_label => model_config.try(:label),
        :model_label_plural => model_config.try(:label_plural),
        :object_label => model_config && object.try(model_config.object_label_method)
      )
    end

    def main_navigation
      nodes_stack = RailsAdmin::Config.visible_models(:controller => self.controller)
      nodes_stack.group_by(&:navigation_label).map do |navigation_label, nodes|

        li_stack = nodes.select{|n| n.parent.nil? || !n.parent.to_s.in?(nodes_stack.map{|c| c.abstract_model.model_name }) }.map do |node|
          model_param = node.abstract_model.to_param

          %{<li data-model="#{model_param}">
              <a class="pjax" href="#{url_for(:action => :index, :controller => 'rails_admin/main', :model_name => model_param)}">#{node.label_plural}</a>
            </li>
            #{navigation(nodes_stack, nodes_stack.select{|n| n.parent.to_s == node.abstract_model.model_name}, 1)}
          }
        end.join

        label = navigation_label || t('admin.misc.navigation')
        %{<li class='nav-header'>#{label}</li>#{li_stack}} if li_stack.present?
      end.join.html_safe
    end

    def static_navigation
      li_stack = RailsAdmin::Config.navigation_static_links.map do |title, url|
        content_tag(:li, link_to(title.to_s, url, :target => '_blank'))
      end.join

      label = RailsAdmin::Config.navigation_static_label || t('admin.misc.navigation_static_label')
      %{<li class='nav-header'>#{label}</li>#{li_stack}} if li_stack.present?
    end

    def navigation nodes_stack, nodes, level
      nodes.map do |node|
        model_param = node.abstract_model.to_param

        %{<li data-model="#{node.abstract_model.to_param}">
            <a class="pjax nav-level-#{level}" href="#{url_for(:action => :index, :controller => 'rails_admin/main', :model_name => model_param)}">#{node.label_plural}</a>
          </li>
          #{navigation(nodes_stack, nodes_stack.select{ |n| n.parent.to_s == node.abstract_model.model_name}, level + 1)}
        }
      end.join
    end

    def breadcrumb action = @action, acc = []
      begin
        (parent_actions ||= []) << action
      end while action.breadcrumb_parent && (action = action(*action.breadcrumb_parent))

      content_tag(:ul, :class => "breadcrumb") do<commit_msg>Return a blank string.<commit_after>require 'rails_admin/i18n_support'

module RailsAdmin
  module ApplicationHelper

    include RailsAdmin::I18nSupport

    def authorized?(*args)
      @authorization_adapter.nil? || @authorization_adapter.authorized?(*args)
    end

    def current_action?(action, abstract_model = @abstract_model, object = @object)
      @action.custom_key == action.custom_key &&
      abstract_model.try(:to_param) == @abstract_model.try(:to_param) &&
      (@object.try(:persisted?) ? @object.id == object.try(:id) : !object.try(:persisted?))
    end

    def action(key, abstract_model = nil, object = nil)
      RailsAdmin::Config::Actions.find(key, { :controller => self.controller, :abstract_model => abstract_model, :object => object })
    end

    def actions(scope = :all, abstract_model = nil, object = nil)
      RailsAdmin::Config::Actions.all(scope, { :controller => self.controller, :abstract_model => abstract_model, :object => object })
    end

    def edit_user_link
      return nil unless authorized?(:edit, _current_user.class, _current_user) && _current_user.respond_to?(:email)
      return nil unless abstract_model = RailsAdmin.config(_current_user.class).abstract_model
      return nil unless edit_action = RailsAdmin::Config::Actions.find(:edit, {:controller => self.controller, :abstract_model => abstract_model, :object => _current_user })
      link_to _current_user.email, url_for(:action => edit_action.action_name, :model_name => abstract_model.to_param, :id => _current_user.id, :controller => 'rails_admin/main')
    end

    def wording_for(label, action = @action, abstract_model = @abstract_model, object = @object)
      model_config = abstract_model.try(:config)
      object = abstract_model && object.is_a?(abstract_model.model) ? object : nil
      action = RailsAdmin::Config::Actions.find(action.to_sym) if (action.is_a?(Symbol) || action.is_a?(String))

      I18n.t("admin.actions.#{action.i18n_key}.#{label}",
        :model_label => model_config.try(:label),
        :model_label_plural => model_config.try(:label_plural),
        :object_label => model_config && object.try(model_config.object_label_method)
      )
    end

    def main_navigation
      nodes_stack = RailsAdmin::Config.visible_models(:controller => self.controller)
      nodes_stack.group_by(&:navigation_label).map do |navigation_label, nodes|

        li_stack = nodes.select{|n| n.parent.nil? || !n.parent.to_s.in?(nodes_stack.map{|c| c.abstract_model.model_name }) }.map do |node|
          model_param = node.abstract_model.to_param

          %{<li data-model="#{model_param}">
              <a class="pjax" href="#{url_for(:action => :index, :controller => 'rails_admin/main', :model_name => model_param)}">#{node.label_plural}</a>
            </li>
            #{navigation(nodes_stack, nodes_stack.select{|n| n.parent.to_s == node.abstract_model.model_name}, 1)}
          }
        end.join

        label = navigation_label || t('admin.misc.navigation')
        %{<li class='nav-header'>#{label}</li>#{li_stack}} if li_stack.present?
      end.join.html_safe
    end

    def static_navigation
      li_stack = RailsAdmin::Config.navigation_static_links.map do |title, url|
        content_tag(:li, link_to(title.to_s, url, :target => '_blank'))
      end.join

      label = RailsAdmin::Config.navigation_static_label || t('admin.misc.navigation_static_label')
      li_stack = %{<li class='nav-header'>#{label}</li>#{li_stack}}.html_safe if li_stack.present?
      li_stack
    end

    def navigation nodes_stack, nodes, level
      nodes.map do |node|
        model_param = node.abstract_model.to_param

        %{<li data-model="#{node.abstract_model.to_param}">
            <a class="pjax nav-level-#{level}" href="#{url_for(:action => :index, :controller => 'rails_admin/main', :model_name => model_param)}">#{node.label_plural}</a>
          </li>
          #{navigation(nodes_stack, nodes_stack.select{ |n| n.parent.to_s == node.abstract_model.model_name}, level + 1)}
        }
      end.join
    end

    def breadcrumb action = @action, acc = []
      begin
        (parent_actions ||= []) << action
      end while action.breadcrumb_parent && (action = action(*action.breadcrumb_parent))

      content_tag(:ul, :class => "breadcrumb") do
{'fraction_non_alphanumeric': 0.1438907690512312, 'fraction_numerical': 0.0023339946318123466, 'mean_word_length': 3.8011204481792715, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 77, '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': '6977615', 'n_tokens_mistral': 2721, 'n_tokens_neox': 2664, 'n_words': 476}