<commit_before>class Admin::ThemesController < Admin::BaseController
  require 'open-uri'
  require 'time'
  require 'rexml/document'

  cache_sweeper :blog_sweeper

  def index
    @themes = Theme.find_all
    @themes.each do |theme|
      theme.description_html = TextFilter.filter_text(this_blog, theme.description, nil, [:markdown,:smartypants])
    end
    @active = this_blog.current_theme
  end

  def preview
    send_file "#{Theme.themes_root}/#{params[:theme]}/preview.png", :type => 'image/png', :disposition => 'inline', :stream => false
  end

  def switchto
    this_blog.theme = params[:theme]
    this_blog.save
    zap_theme_caches
    this_blog.current_theme(:reload)
    flash[:notice] = _("Theme changed successfully")
    redirect_to :action => 'index'
  end

  def editor
    case params[:type].to_s
    when "stylesheet"
      path = this_blog.current_theme.path + "/stylesheets/"
      if params[:file] =~ /css$/
        filename = params[:file]
      else
        flash[:error] = _("You are not authorized to open this file")
        return
      end
    when "layout"
      path = this_blog.current_theme.path + "/layouts/"
      if params[:file] =~ /rhtml$|erb$/
        filename = params[:file]
      else
        flash[:error] = _("You are not authorized to open this file")
        return
      end
    end<commit_msg>Fixes a crash when changing to a theme having helpers if it was not loaded by default<commit_after>class Admin::ThemesController < Admin::BaseController
  require 'open-uri'
  require 'time'
  require 'rexml/document'

  cache_sweeper :blog_sweeper

  def index
    @themes = Theme.find_all
    @themes.each do |theme|
      theme.description_html = TextFilter.filter_text(this_blog, theme.description, nil, [:markdown,:smartypants])
    end
    @active = this_blog.current_theme
  end

  def preview
    send_file "#{Theme.themes_root}/#{params[:theme]}/preview.png", :type => 'image/png', :disposition => 'inline', :stream => false
  end

  def switchto
    this_blog.theme = params[:theme]
    this_blog.save
    zap_theme_caches
    this_blog.current_theme(:reload)
    flash[:notice] = _("Theme changed successfully")
    require "#{this_blog.current_theme.path}/helpers/theme_helper.rb" if File.exists? "#{this_blog.current_theme.path}/helpers/theme_helper.rb"
    redirect_to :action => 'index'
  end

  def editor
    case params[:type].to_s
    when "stylesheet"
      path = this_blog.current_theme.path + "/stylesheets/"
      if params[:file] =~ /css$/
        filename = params[:file]
      else
        flash[:error] = _("You are not authorized to open this file")
        return
      end
    when "layout"
      path = this_blog.current_theme.path + "/layouts/"
      if params[:file] =~ /rhtml$|erb$/
        filename = params[:file]
      else
        flash[:error] = _("You are not authorized to open this file")
        return
      end
    end
{'fraction_non_alphanumeric': 0.11881868131868131, 'fraction_numerical': 0.0, 'mean_word_length': 3.0741258741258743, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6333478', 'n_tokens_mistral': 921, 'n_tokens_neox': 898, 'n_words': 224}