<commit_before>module AdminSidebarHelper

  def actions

    actions_list = []

    returning(String.new) do |html|

      html << <<-HTML
<h2>#{t("Actions")}</h2>
      HTML

      case params[:action]
      when 'index', 'edit', 'update'
        if @current_user.can_perform?(@resource[:class], 'create')
          actions_list << "<li>#{link_to "#{t("Add")} #{@resource[:class_name_humanized].downcase}", :action => 'new'}</li>"
        end
        actions_list += more_actions
      end

      case params[:action]
      when 'new', 'create', 'update'
        actions_list << "<li>#{link_to t("Back to list"), :action => 'index'}</li>"
        actions_list << more_actions
      end

      html << <<-HTML
<ul>
#{actions_list.join("\n")}
</ul>
      HTML

      html << previous_and_next if %w( edit update ).include?(params[:action])
      html << block('parent_module')
      html << block('submodules')

    end

  end

  def more_actions
    returning(Array.new) do |actions|
      @resource[:class].typus_actions_for(params[:action]).each do |action|
        if @current_user.can_perform?(@resource[:class], action)
          actions << "<li>#{link_to action.titleize.capitalize, :action => action}</li>"
        end
      end
    end
  end

  def block(name)

    models = case name
             when 'parent_module': Typus.parent(@resource[:class_name], 'module')
             when 'submodules':    Typus.module(@resource[:class_name])
             end

    return "" if models.empty?

    returning(String.new) do |html|
      links = []
      models.each do |m|
        links << "<li>#{link_to m.titleize, :controller => m.tableize}</li>"
      end
      html << <<-HTML
<h2>#{name.humanize}</h2>
<ul>
  #{links.join("\n")}
</ul>
      HTML
    end

  end

  def previous_and_next

    links = []
    links << "<li>#{link_to t("Next"), :id => @next.id}</li>" if @next
    links << "<li>#{link_to t("Previous"), :id => @previous.id}</li>" if @previous

    return "" if links.empty?

    returning(String.new) do |html|
      html << <<-HTML
<ul>
#{links.join("\n")}
</ul>
      HTML
    end

  end

  def search

    return if Typus::Configuration.config[@resource[:class_name]]['search'].nil?

    search_params = params.dup
    %w( action controller search page ).each { |p| search_params.delete(p) }

    hidden_params = []
    search_params.each { |key, value| hidden_params << hidden_field_tag(key, value) }

    returning(String.new) do |html|
      html << <<-HTML
<h2>#{t("Search")}</h2>
<form action="" method="get">
<p><input id="search" name="search" type="text" value="#{params[:search]}"/></p>
#{hidden_params.join("\n")}
</form>
<p style="margin: -10px 0px 10px 0px;"><small>#{t("Search by")} #{Typus::Configuration.config[@resource[:class_name]]['search'].split(', ').to_sentence(:skip_last_comma => true, :connector => '&').titleize.downcase}.</small></p>
      HTML
    end

  end
<commit_msg>Renamed links to items.<commit_after>module AdminSidebarHelper

  def actions

    actions_list = []

    returning(String.new) do |html|

      html << <<-HTML
<h2>#{t("Actions")}</h2>
      HTML

      case params[:action]
      when 'index', 'edit', 'update'
        if @current_user.can_perform?(@resource[:class], 'create')
          actions_list << "<li>#{link_to "#{t("Add")} #{@resource[:class_name_humanized].downcase}", :action => 'new'}</li>"
        end
        actions_list += more_actions
      end

      case params[:action]
      when 'new', 'create', 'update'
        actions_list << "<li>#{link_to t("Back to list"), :action => 'index'}</li>"
        actions_list << more_actions
      end

      html << <<-HTML
<ul>
#{actions_list.join("\n")}
</ul>
      HTML

      html << previous_and_next if %w( edit update ).include?(params[:action])
      html << block('parent_module')
      html << block('submodules')

    end

  end

  def more_actions
    returning(Array.new) do |actions|
      @resource[:class].typus_actions_for(params[:action]).each do |action|
        if @current_user.can_perform?(@resource[:class], action)
          actions << "<li>#{link_to action.titleize.capitalize, :action => action}</li>"
        end
      end
    end
  end

  def block(name)

    models = case name
             when 'parent_module': Typus.parent(@resource[:class_name], 'module')
             when 'submodules':    Typus.module(@resource[:class_name])
             end

    return "" if models.empty?

    returning(String.new) do |html|
      items = []
      models.each do |m|
        items << "<li>#{link_to m.titleize, :controller => m.tableize}</li>"
      end
      html << <<-HTML
<h2>#{name.humanize}</h2>
<ul>
  #{items.join("\n")}
</ul>
      HTML
    end

  end

  def previous_and_next

    items = []
    items << "<li>#{link_to t("Next"), :id => @next.id}</li>" if @next
    items << "<li>#{link_to t("Previous"), :id => @previous.id}</li>" if @previous

    return "" if items.empty?

    returning(String.new) do |html|
      html << <<-HTML
<ul>
#{items.join("\n")}
</ul>
      HTML
    end

  end

  def search

    return if Typus::Configuration.config[@resource[:class_name]]['search'].nil?

    search_params = params.dup
    %w( action controller search page ).each { |p| search_params.delete(p) }

    hidden_params = []
    search_params.each { |key, value| hidden_params << hidden_field_tag(key, value) }

    returning(String.new) do |html|
      html << <<-HTML
<h2>#{t("Search")}</h2>
<form action="" method="get">
<p><input id="search" name="search" type="text" value="#{params[:search]}"/></p>
#{hidden_params.join("\n")}
</form>
<p style="margin: -10px 0px 10px 0px;"><small>#{t("Search by")} #{Typus::Configuration.config[@resource[:class_name]]['search'].split(', ').to_sentence(:skip_last_comma => true, :connector => '&').titleize.downcase}.</small></p>
      HTML
    end

  end

{'fraction_non_alphanumeric': 0.1869877049180328, 'fraction_numerical': 0.004098360655737705, 'mean_word_length': 3.0420979986197376, 'pattern_counts': {'":': 0, '<': 153, '<?xml version=': 0, '>': 85, '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': '3085874', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1944, 'n_words': 419}