<commit_before>require "action_controller/metal"

module ThemesForRails
  class AssetsController < ActionController::Base

    include ThemesForRails::CommonMethods
    include ThemesForRails::UrlHelpers

    def stylesheets
      handle_asset(params[:asset], params[:theme], "stylesheets")
    end

    def javascripts
      handle_asset(params[:asset], params[:theme], "javascripts")
    end

    def images
      handle_asset(params[:asset], params[:theme], "images")
    end

  private
    
    def handle_asset(asset, theme, prefix)
      find_asset(asset, theme, prefix) do |path, mime_type|
        send_file path, :type => mime_type, :disposition => "inline"
      end
    end
    
    def find_asset(asset_name, asset_theme, asset_prefix)
      path = asset_path(asset_name, asset_theme, asset_prefix)
      if File.exists?(path)
        yield path, mime_type_for(request)
      elsif File.extname(path).blank?
        asset_name = "#{asset_name}.#{extension_from(request.path_info)}"
        return find_asset(asset_name, asset_theme, asset_prefix) 
      else
        render_not_found
      end
    end

    def asset_path(asset_name, asset_theme, asset_prefix)
      File.join(theme_path_for(asset_theme), asset_prefix, asset_name)
    end

    def render_not_found
      render :text => 'not found', :status => 404
    end
      
    def mime_type_for(request)
      existing_mime_type = mime_type_from_uri(request.path_info)
      unless existing_mime_type.nil? 
        existing_mime_type.to_s
      else
        "image/#{extension_from(request.path_info)}"<commit_msg>Passing the block, duh.<commit_after>require "action_controller/metal"

module ThemesForRails
  class AssetsController < ActionController::Base

    include ThemesForRails::CommonMethods
    include ThemesForRails::UrlHelpers

    def stylesheets
      handle_asset(params[:asset], params[:theme], "stylesheets")
    end

    def javascripts
      handle_asset(params[:asset], params[:theme], "javascripts")
    end

    def images
      handle_asset(params[:asset], params[:theme], "images")
    end

  private
    
    def handle_asset(asset, theme, prefix)
      find_themed_asset(asset, theme, prefix) do |path, mime_type|
        send_file path, :type => mime_type, :disposition => "inline"
      end
    end
    
    def find_themed_asset(asset_name, asset_theme, asset_prefix, &block)
      path = asset_path(asset_name, asset_theme, asset_prefix)
      if File.exists?(path)
        yield path, mime_type_for(request)
      elsif File.extname(path).blank?
        asset_name = "#{asset_name}.#{extension_from(request.path_info)}"
        return find_themed_asset(asset_name, asset_theme, asset_prefix, &block) 
      else
        render_not_found
      end
    end

    def asset_path(asset_name, asset_theme, asset_prefix)
      File.join(theme_path_for(asset_theme), asset_prefix, asset_name)
    end

    def render_not_found
      render :text => 'not found', :status => 404
    end
      
    def mime_type_for(request)
      existing_mime_type = mime_type_from_uri(request.path_info)
      unless existing_mime_type.nil? 
        existing_mime_type.to_s
      else
        "image/#{extension_from(request.path_info)}"
{'fraction_non_alphanumeric': 0.0926905132192846, 'fraction_numerical': 0.0018662519440124418, 'mean_word_length': 3.387448840381992, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6332900', 'n_tokens_mistral': 1034, 'n_tokens_neox': 999, 'n_words': 202}