<commit_before>require 'nokogiri'
require 'cdo/user_agent_parser'
require 'cdo/graphics/certificate_image'

module ApplicationHelper

  include LocaleHelper
  include ScriptLevelsHelper

  USER_AGENT_PARSER = UserAgentParser::Parser.new

  def browser
    @browser ||= USER_AGENT_PARSER.parse request.headers["User-Agent"]
  end

  def ago(from_time)
    s = distance_of_time_in_words_to_now(from_time)
    # XXX This is horribly broken for localization.
    s = s.gsub("about ", "")
    s = s.gsub("less than ", "")
    s = s.gsub("a minute", "1 minute")
    "#{s} ago"
  end

  def format_xml(xml)
    doc = Nokogiri::XML(xml)
    doc.to_xhtml
  end

  def gender_options
    User::GENDER_OPTIONS.map do |key, value|
      [(key ? t(key) : ''), value]
    end
  end

  def user_type_options
    User::USER_TYPE_OPTIONS.map do |user_type|
      [t("user_type.#{user_type}"), user_type]
    end
  end

  def check_mark_html
    #raw "&#x2714;"
    image_tag(image_url('white-checkmark.png'))
  end

  def activity_css_class(result)
    if result.nil?
      'not_tried'
    elsif result >= Activity::FREE_PLAY_RESULT
      'perfect'
    elsif result >= Activity::MINIMUM_PASS_RESULT
      'passed'
    else
      'attempted'
    end
  end

  def level_info(user, script_level)
    result =
      if user
        script_level.try(:user_level).try(:best_result)
      elsif session[:progress] && session[:progress][script_level.level_id]
        session[:progress][script_level.level_id]
      end
    link = build_script_level_url(script_level)
    [activity_css_class(result), link]
  end

  def show_flashes
    ret = ''
    if notice.present?
      ret += content_tag(:div, flash.notice, {class: 'alert alert-success'})
      flash.notice = nil
    end

    if alert.present?
      ret += content_tag(:div, flash.alert, {class: 'alert alert-danger'})
      flash.alert = nil
    end

    ret
  end

  def code_org_root_path
    CDO.code_org_url
  end

  def teacher_dashboard_url
    CDO.code_org_url '/teacher-dashboard'
  end

  # used by devise to redirect user after signing in
  def signed_in_root_path(resource_or_scope)
    if session[:return_to]
      return session.delete(:return_to)
    elsif resource_or_scope.is_a?(User) && resource_or_scope.teacher?
      return teacher_dashboard_url
    end
    '/'
  end

  def external_oauth_sign_out_url(provider)
    case provider.to_sym
    when :facebook
      'https://www.facebook.com/logout.php'
    when :windowslive
      'http://login.live.com/logout.srf'
    when :google_oauth2
      'https://accounts.google.com/logout'
    end
  end

  def meta_image_url(opts = {})
    app = opts[:level_source].try(:level).try(:game).try(:app) || opts[:level].try(:game).try(:app)
    
    # playlab/studio and artist/turtle can have images
    if opts[:level_source].try(:level_source_image).try(:image)
      if level_source.level_source_image.s3?
        if app == Game::ARTIST then
          level_source.level_source_image.s3_framed_url
        else
          level_source.level_source_image.s3_url
        end
      else
        url_for(controller: 'level_sources', action: 'generate_image', id: level_source.id, only_path: false)
      end
    elsif [Game::FLAPPY, Game::BOUNCE, Game::STUDIO].include? app
      asset_url "#{app}_sharing_drawing.png"
    else
      asset_url 'sharing_drawing.png'
    end
  end
<commit_msg>fix /c/ urls<commit_after>require 'nokogiri'
require 'cdo/user_agent_parser'
require 'cdo/graphics/certificate_image'

module ApplicationHelper

  include LocaleHelper
  include ScriptLevelsHelper

  USER_AGENT_PARSER = UserAgentParser::Parser.new

  def browser
    @browser ||= USER_AGENT_PARSER.parse request.headers["User-Agent"]
  end

  def ago(from_time)
    s = distance_of_time_in_words_to_now(from_time)
    # XXX This is horribly broken for localization.
    s = s.gsub("about ", "")
    s = s.gsub("less than ", "")
    s = s.gsub("a minute", "1 minute")
    "#{s} ago"
  end

  def format_xml(xml)
    doc = Nokogiri::XML(xml)
    doc.to_xhtml
  end

  def gender_options
    User::GENDER_OPTIONS.map do |key, value|
      [(key ? t(key) : ''), value]
    end
  end

  def user_type_options
    User::USER_TYPE_OPTIONS.map do |user_type|
      [t("user_type.#{user_type}"), user_type]
    end
  end

  def check_mark_html
    #raw "&#x2714;"
    image_tag(image_url('white-checkmark.png'))
  end

  def activity_css_class(result)
    if result.nil?
      'not_tried'
    elsif result >= Activity::FREE_PLAY_RESULT
      'perfect'
    elsif result >= Activity::MINIMUM_PASS_RESULT
      'passed'
    else
      'attempted'
    end
  end

  def level_info(user, script_level)
    result =
      if user
        script_level.try(:user_level).try(:best_result)
      elsif session[:progress] && session[:progress][script_level.level_id]
        session[:progress][script_level.level_id]
      end
    link = build_script_level_url(script_level)
    [activity_css_class(result), link]
  end

  def show_flashes
    ret = ''
    if notice.present?
      ret += content_tag(:div, flash.notice, {class: 'alert alert-success'})
      flash.notice = nil
    end

    if alert.present?
      ret += content_tag(:div, flash.alert, {class: 'alert alert-danger'})
      flash.alert = nil
    end

    ret
  end

  def code_org_root_path
    CDO.code_org_url
  end

  def teacher_dashboard_url
    CDO.code_org_url '/teacher-dashboard'
  end

  # used by devise to redirect user after signing in
  def signed_in_root_path(resource_or_scope)
    if session[:return_to]
      return session.delete(:return_to)
    elsif resource_or_scope.is_a?(User) && resource_or_scope.teacher?
      return teacher_dashboard_url
    end
    '/'
  end

  def external_oauth_sign_out_url(provider)
    case provider.to_sym
    when :facebook
      'https://www.facebook.com/logout.php'
    when :windowslive
      'http://login.live.com/logout.srf'
    when :google_oauth2
      'https://accounts.google.com/logout'
    end
  end

  def meta_image_url(opts = {})
    app = opts[:level_source].try(:level).try(:game).try(:app) || opts[:level].try(:game).try(:app)
    
    # playlab/studio and artist/turtle can have images
    if opts[:level_source].try(:level_source_image).try(:image)
      level_source = opts[:level_source]
      if level_source.level_source_image.s3?
        if app == Game::ARTIST then
          level_source.level_source_image.s3_framed_url
        else
          level_source.level_source_image.s3_url
        end
      else
        url_for(controller: 'level_sources', action: 'generate_image', id: level_source.id, only_path: false)
      end
    elsif [Game::FLAPPY, Game::BOUNCE, Game::STUDIO].include? app
      asset_url "#{app}_sharing_drawing.png"
    else
      asset_url 'sharing_drawing.png'
    end
  end

{'fraction_non_alphanumeric': 0.1096413874191652, 'fraction_numerical': 0.0026455026455026454, 'mean_word_length': 3.134264884568651, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '5314561', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2343, 'n_words': 460}