<commit_before># Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  
  def is_admin?
    logged_in? and current_user.has_role?('administrator') 
  end
  
  def is_priviliged?
    is_admin? or (logged_in? and current_user.has_role?('priviliged'))
  end
  
  def is_current_controller? name
    (controller.controller_name <=> name) == 0 
  end
  
  def authorize_user_subresource
    logged_in? and (params[:user_id] == current_user.id)
  end
  
  def on_user_page?
    (controller.controller_name == "users" or
     controller.controller_name == "user_profiles" or
     controller.controller_name == "suggestion")
  end
  
  def on_admin_page?
    is_current_controller? 'admins' or 
    is_current_controller? 'categories' or
    is_current_controller? 'distributions' or
    is_current_controller? 'categories'
  end
  
  def editing_metapackage?
    not session[:cart].nil?
  end
  
  def render_flash
    out = ""
    
    flash.each do |key, value|
      out << "<span id='" << key.to_s << "'>" << value << "</span><br/>"
    end
    
    "<div class='flash'>" << out << "</div>" if not out.empty?
  end
  
  def card_editor(name,packages,session,current_user)
    cart = Cart.new
    cart.name = name
    cart.save
    packages.each do |p|
      cart.base_packages << p
    end
    session[:cart] = cart.id
    redirect_to "/users/" + current_user.id.to_s + "/metapackages/2"    
  end
  
  def change_date_time(datum) 
    if datum.nil? then
      ""
    else
      datum.strftime("%d.%m.%Y %H:%M")
    end  
  end  

  def package_link name
    link_to name, package_url(Package.find(:first,:conditions =>{:name => name.downcase}))
  end
  
  # show dependencies of a bundle or a package in structured form
  def show_rdependencies deps
    out = []
    show_rdependencies_aux deps, out
    return out.join("\n")
  end

  def show_rdependencies_aux deps, out
    out.push "<ul>"
    deps.each do |p,deps_local|
      out.push "<li>"
      meta = if p.class == Package then "" else "meta" end
      out.push "<a href=\"/#{meta}packages/#{p.id}\">#{p.name}</a>"
      show_rdependencies_aux deps_local, out 
      out.push "</li>"
    end
    out.push "</ul>"
  end

  def new_message?
    !current_user.received_messages.find(:first, :conditions=>["is_read = ?", false]).nil?
  end
  
  def received_messages?
    !current_user.received_messages.find(:first).nil?
  end
  
  def sent_messages?
    !current_user.sent_messages.find(:first).nil?
  end
  
end<commit_msg>helpers for detection of derivative<commit_after># Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  
  def is_admin?
    logged_in? and current_user.has_role?('administrator') 
  end
  
  def is_priviliged?
    is_admin? or (logged_in? and current_user.has_role?('priviliged'))
  end
  
  def is_current_controller? name
    (controller.controller_name <=> name) == 0 
  end
  
  def authorize_user_subresource
    logged_in? and (params[:user_id] == current_user.id)
  end
  
  def on_user_page?
    (controller.controller_name == "users" or
     controller.controller_name == "user_profiles" or
     controller.controller_name == "suggestion")
  end
  
  def on_admin_page?
    is_current_controller? 'admins' or 
    is_current_controller? 'categories' or
    is_current_controller? 'distributions' or
    is_current_controller? 'categories'
  end
  
  def editing_metapackage?
    not session[:cart].nil?
  end
  
  def render_flash
    out = ""
    
    flash.each do |key, value|
      out << "<span id='" << key.to_s << "'>" << value << "</span><br/>"
    end
    
    "<div class='flash'>" << out << "</div>" if not out.empty?
  end
  
  def card_editor(name,packages,session,current_user)
    cart = Cart.new
    cart.name = name
    cart.save
    packages.each do |p|
      cart.base_packages << p
    end
    session[:cart] = cart.id
    redirect_to "/users/" + current_user.id.to_s + "/metapackages/2"    
  end
  
  def change_date_time(datum) 
    if datum.nil? then
      ""
    else
      datum.strftime("%d.%m.%Y %H:%M")
    end  
  end  

  def package_link name
    link_to name, package_url(Package.find(:first,:conditions =>{:name => name.downcase}))
  end
  
  # show dependencies of a bundle or a package in structured form
  def show_rdependencies deps
    out = []
    show_rdependencies_aux deps, out
    return out.join("\n")
  end

  def show_rdependencies_aux deps, out
    out.push "<ul>"
    deps.each do |p,deps_local|
      out.push "<li>"
      meta = if p.class == Package then "" else "meta" end
      out.push "<a href=\"/#{meta}packages/#{p.id}\">#{p.name}</a>"
      show_rdependencies_aux deps_local, out 
      out.push "</li>"
    end
    out.push "</ul>"
  end

  def new_message?
    !current_user.received_messages.find(:first, :conditions=>["is_read = ?", false]).nil?
  end
  
  def received_messages?
    !current_user.received_messages.find(:first).nil?
  end
  
  def sent_messages?
    !current_user.sent_messages.find(:first).nil?
  end

  def is_gnome?
    !logged_in? or current_user.derivative.name=="Ubuntu"
  end

  def is_kde?
    logged_in? and current_user.derivative.name=="Kubuntu"
  end

  def is_xfce?
    logged_in? and current_user.derivative.name=="Xubuntu"
  end
  
end
{'fraction_non_alphanumeric': 0.12167229096362954, 'fraction_numerical': 0.0007499062617172854, 'mean_word_length': 3.0416666666666665, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 33, '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': '5695446', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1842, 'n_words': 427}