<commit_before>module TypusHelper

  MODELS = YAML.load_file("#{RAILS_ROOT}/config/typus.yml")

  def head
    @block = <<-HTML
    <title>#{Typus::Configuration.options[:app_name]} &rsaquo; #{page_title}</title>
    <link rel=\"shortcut icon\" href=\"/favicon.ico\" type=\"image/x-icon\" />
    <meta http-equiv=\"imagetoolbar\" content=\"no\" />
    <meta name=\"description\" content=\"\" />
    <meta name=\"keywords\" content=\"\" />
    <meta name=\"author\" content=\"\" />
    <meta name=\"copyright\" content=\"\" />
    <meta name=\"generator\" content=\"\" />
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
    #{stylesheet_link_tag "typus", :media => "screen"}
    #{javascript_include_tag :defaults}
    HTML
    return @block
  end

  def header
    @block = <<-HTML
    <h1>#{Typus::Configuration.options[:app_name]} #{feedback}</span></h1>
    <h2>#{Typus::Configuration.options[:app_description]}</h2>
    HTML
    return @block
  end

  def breadcrumbs
    @block = "<p>"
    if params[:model]
      @block += "<a href=\"/#{Typus::Configuration.options[:prefix]}/\">Home</a>"
      case params[:action]
      when "index"
        @block += " &rsaquo; #{params[:model].capitalize}</li>\n"
      when "edit"
        @block += " &rsaquo; <a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}\">#{params[:model].capitalize}</a></li>\n"
        @block += " &rsaquo; Edit</li>\n"
      when "new"
        @block += " &rsaquo; <a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}\">#{params[:model].capitalize}</a></li>\n"
        @block += " &rsaquo; New</li>\n"
      end
    else
      @block += "Home"
    end
    @block += "</p>"
    return @block
  end

  def modules
    @block = "<div id=\"list\">"
    @models = MODELS.to_a
    @modules = []
    @models.each { |model| @modules += model[1]['module'].to_a }
    @modules.uniq.each do |m|
      @block += "<table>\n"
      @block += "<tr><th colspan=\"2\">#{m.capitalize}</th></tr>\n"
      MODELS.each do |model|
        @block += "<tr class=\"#{cycle('even', 'odd')}\"><td><a href=\"/#{Typus::Configuration.options[:prefix]}/#{model[0].downcase.pluralize}\">#{model[0].pluralize}</a><br /><small>#{model[1]['copy']}</small></td><td align=\"right\" valign=\"bottom\"><small><a href=\"/#{Typus::Configuration.options[:prefix]}/#{model[0].downcase.pluralize}/new\">Add</a></small></td></tr>\n" if model[1]['module'] == m
      end
      @block += "</table>\n"
      @block += "<br /><div style=\"clear\"></div>"
    end
    @block += "</div>"
    return @block
  end

  def actions
    @block = "<h2>Actions</h2>\n"
    case params[:action]
    when "index"
      @block += <<-HTML
        <ul>
          <li><a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}/new\">Add #{params[:model].singularize.capitalize}</a></li>
        </ul>
      HTML
    when "new"
      @block += <<-HTML
        <ul>
          <li><a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}\">Back to list</a></li>
        </ul>
      HTML
    when "edit"
      @block += <<-HTML
        <ul>
          #{'<li>' + (link_to "Next #{params[:model].singularize.capitalize}", :action => "edit", :id => @next.id) + '</li>' if @next} 
          #{'<li>' + (link_to "Previous #{params[:model].singularize.capitalize}", :action => 'edit', :id => @previous.id) + '<li>' if @previous}
        </ul>
        <ul>
          <li><a href="/#{Typus::Configuration.options[:prefix]}/#{params[:model]}">Back to list</a></li>
        </ul>
      HTML
    end
    
    # More Actions
    if MODELS[@model.to_s]["actions"]
      @block += "<h2>More Actions</h2>"
      @block += "<ul>"
      @model.actions.each { |a| @block += "<li><a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}/#{a[0]}\">#{a[0].humanize}</a></li>" if a[1] == params[:action] }
      @block += "</ul>"
    end
    
    return @block
  end

  def search
    if MODELS[@model.to_s]["search"]
      @search = <<-HTML
      <h2>Search</h2>
      <form action="/#{Typus::Configuration.options[:prefix]}/#{params[:model]}" method="get">
      <p><input id="query" name="query" type="text" value="#{params[:query]}"/></p>
      </form>
      HTML
    end
    return @search
  end

  def filters
    if MODELS[@model.to_s]["filters"]
      @filters = "<h2>Filter"
      @filters += " <small><a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}\">Remove</a></small>" if request.env['QUERY_STRING']
      @filters += "</h2>"
      @model.filters.each do |f|
        case f[1]
        when "boolean"
          @filters += "<h3>By #{f[0].humanize}</h3>\n"
          @filters += "<ul>\n"<commit_msg>Only more actions when they exist<commit_after>module TypusHelper

  MODELS = YAML.load_file("#{RAILS_ROOT}/config/typus.yml")

  def head
    @block = <<-HTML
    <title>#{Typus::Configuration.options[:app_name]} &rsaquo; #{page_title}</title>
    <link rel=\"shortcut icon\" href=\"/favicon.ico\" type=\"image/x-icon\" />
    <meta http-equiv=\"imagetoolbar\" content=\"no\" />
    <meta name=\"description\" content=\"\" />
    <meta name=\"keywords\" content=\"\" />
    <meta name=\"author\" content=\"\" />
    <meta name=\"copyright\" content=\"\" />
    <meta name=\"generator\" content=\"\" />
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
    #{stylesheet_link_tag "typus", :media => "screen"}
    #{javascript_include_tag :defaults}
    HTML
    return @block
  end

  def header
    @block = <<-HTML
    <h1>#{Typus::Configuration.options[:app_name]} #{feedback}</span></h1>
    <h2>#{Typus::Configuration.options[:app_description]}</h2>
    HTML
    return @block
  end

  def breadcrumbs
    @block = "<p>"
    if params[:model]
      @block += "<a href=\"/#{Typus::Configuration.options[:prefix]}/\">Home</a>"
      case params[:action]
      when "index"
        @block += " &rsaquo; #{params[:model].capitalize}</li>\n"
      when "edit"
        @block += " &rsaquo; <a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}\">#{params[:model].capitalize}</a></li>\n"
        @block += " &rsaquo; Edit</li>\n"
      when "new"
        @block += " &rsaquo; <a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}\">#{params[:model].capitalize}</a></li>\n"
        @block += " &rsaquo; New</li>\n"
      end
    else
      @block += "Home"
    end
    @block += "</p>"
    return @block
  end

  def modules
    @block = "<div id=\"list\">"
    @models = MODELS.to_a
    @modules = []
    @models.each { |model| @modules += model[1]['module'].to_a }
    @modules.uniq.each do |m|
      @block += "<table>\n"
      @block += "<tr><th colspan=\"2\">#{m.capitalize}</th></tr>\n"
      MODELS.each do |model|
        @block += "<tr class=\"#{cycle('even', 'odd')}\"><td><a href=\"/#{Typus::Configuration.options[:prefix]}/#{model[0].downcase.pluralize}\">#{model[0].pluralize}</a><br /><small>#{model[1]['copy']}</small></td><td align=\"right\" valign=\"bottom\"><small><a href=\"/#{Typus::Configuration.options[:prefix]}/#{model[0].downcase.pluralize}/new\">Add</a></small></td></tr>\n" if model[1]['module'] == m
      end
      @block += "</table>\n"
      @block += "<br /><div style=\"clear\"></div>"
    end
    @block += "</div>"
    return @block
  end

  def actions
    @block = "<h2>Actions</h2>\n"
    case params[:action]
    when "index"
      @block += <<-HTML
        <ul>
          <li><a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}/new\">Add #{params[:model].singularize.capitalize}</a></li>
        </ul>
      HTML
    when "new"
      @block += <<-HTML
        <ul>
          <li><a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}\">Back to list</a></li>
        </ul>
      HTML
    when "edit"
      @block += <<-HTML
        <ul>
          #{'<li>' + (link_to "Next #{params[:model].singularize.capitalize}", :action => "edit", :id => @next.id) + '</li>' if @next} 
          #{'<li>' + (link_to "Previous #{params[:model].singularize.capitalize}", :action => 'edit', :id => @previous.id) + '<li>' if @previous}
        </ul>
        <ul>
          <li><a href="/#{Typus::Configuration.options[:prefix]}/#{params[:model]}">Back to list</a></li>
        </ul>
      HTML
    end
    
    # More Actions
    if MODELS[@model.to_s]["actions"]
      @more_actions = ""
      @model.actions.each { |a| @more_actions += "<li><a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}/#{a[0]}\">#{a[0].humanize}</a></li>" if a[1] == params[:action] }
      unless @more_actions.empty?
        @block += <<-HTML
          <h2>More Actions</h2>
          <ul>
            #{@more_actions}
          </ul>
        HTML
      end
    end
    
    return @block
  end

  def search
    if MODELS[@model.to_s]["search"]
      @search = <<-HTML
      <h2>Search</h2>
      <form action="/#{Typus::Configuration.options[:prefix]}/#{params[:model]}" method="get">
      <p><input id="query" name="query" type="text" value="#{params[:query]}"/></p>
      </form>
      HTML
    end
    return @search
  end

  def filters
    if MODELS[@model.to_s]["filters"]
      @filters = "<h2>Filter"
      @filters += " <small><a href=\"/#{Typus::Configuration.options[:prefix]}/#{params[:model]}\">Remove</a></small>" if request.env['QUERY_STRING']
      @filters += "</h2>"
      @model.filters.each do |f|
        case f[1]
        when "boolean"
          @filters += "<h3>By #{f[0].humanize}</h3>\n"
          @filters += "<ul>\n"
{'fraction_non_alphanumeric': 0.24247491638795987, 'fraction_numerical': 0.0056438127090301, 'mean_word_length': 2.8538058799838906, 'pattern_counts': {'":': 0, '<': 237, '<?xml version=': 0, '>': 221, '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': '3366494', 'n_tokens_mistral': 3319, 'n_tokens_neox': 3291, 'n_words': 575}