<commit_before>require 'fileutils'
require 'tempfile'

module AssetManifesto
  class Stylesheet < Base

    class << self
      def process_stylesheets
        Dir.glob("#{Rails.root}/public/stylesheets/**/*.css").each do |stylesheet|
          puts "Processing #{stylesheet}..."
          relative_path = stylesheet.split('/public/').last
          temp_stylesheet = Tempfile.new('temp_stylesheet.css')
          File.open(stylesheet, 'r') do |file|
            file.lines{|line| temp_stylesheet.puts AssetPathInjector.to_asset_pipeline line }
          end
          temp_stylesheet.close
          FileUtils.mv(temp_stylesheet.path, "#{Rails.root}/app/assets/#{relative_path}.erb")
          puts " - #{stylesheet} processed, it is now #{Rails.root}/app/assets/#{relative_path}.erb"
          puts " - You should verify the processed file, and then delete the source file"
        end
      end

      def create_manifests
        stylesheet_assets.each do |stylesheet_manifest|
          puts "creating stylesheet manifest files..."
          stylesheet_manifest.each do |manifest_filename, stylesheet_filenames|
            puts "  creating #{manifest_filename} manifest"
            File.open("#{Rails.root}/app/assets/stylesheets/#{manifest_filename}.css", "w") do |manifest_file|
              manifest_file.write "/* #{'#'*102}\n"
              manifest_file.write " * " + center_string("#{manifest_filename}.css") + "\n"<commit_msg>Adding the ability to process a single stylesheet<commit_after>require 'fileutils'
require 'tempfile'

module AssetManifesto
  class Stylesheet < Base

    class << self
      def process_stylesheets
        Dir.glob("#{Rails.root}/public/stylesheets/**/*.css").each do |stylesheet|
          puts "Processing #{stylesheet}..."
          relative_path = stylesheet.split('/public/').last
          temp_stylesheet = Tempfile.new('temp_stylesheet.css')
          File.open(stylesheet, 'r') do |file|
            file.lines{|line| temp_stylesheet.puts AssetPathInjector.to_asset_pipeline line }
          end
          temp_stylesheet.close
          FileUtils.mv(temp_stylesheet.path, "#{Rails.root}/app/assets/#{relative_path}.erb")
          puts " - #{stylesheet} processed, it is now #{Rails.root}/app/assets/#{relative_path}.erb"
          puts " - You should verify the processed file, and then delete the source file"
        end
      end

      def process_stylesheet stylesheet_path
        puts "Processing #{stylesheet_path}..."
        temp_stylesheet = Tempfile.new('temp_stylesheet.css')
        File.open(stylesheet_path, 'r') do |file|
          file.lines{|line| temp_stylesheet.puts AssetPathInjector.to_asset_pipeline line }
        end
        temp_stylesheet.close
        FileUtils.mv(temp_stylesheet.path, stylesheet_path)
        puts " - #{stylesheet_path} processed, verify that everything is as expected"
      end

      def create_manifests
        stylesheet_assets.each do |stylesheet_manifest|
          puts "creating stylesheet manifest files..."
          stylesheet_manifest.each do |manifest_filename, stylesheet_filenames|
            puts "  creating #{manifest_filename} manifest"
            File.open("#{Rails.root}/app/assets/stylesheets/#{manifest_filename}.css", "w") do |manifest_file|
              manifest_file.write "/* #{'#'*102}\n"
              manifest_file.write " * " + center_string("#{manifest_filename}.css") + "\n"
{'fraction_non_alphanumeric': 0.11738875878220141, 'fraction_numerical': 0.001756440281030445, 'mean_word_length': 2.8307174887892375, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '907931', 'n_tokens_mistral': 970, 'n_tokens_neox': 947, 'n_words': 204}