<commit_before>require 'requirejs/rails/config'

require 'pathname'

module Requirejs
  module Rails
    class Engine < ::Rails::Engine
      ### Configuration setup
      config.before_configuration do |app|
        config.requirejs = Requirejs::Rails::Config.new(app)
        config.requirejs.precompile = [/require\.js$/]
      end

      config.before_initialize do |app|
        config = app.config

        # Process the user config file in #before_initalization (instead of #before_configuration) so that
        # environment-specific configuration can be injected into the user configuration file
        Engine.process_user_config_file(app, config)

        config.assets.precompile += config.requirejs.precompile

        # Check for the `requirejs:precompile:all` top-level Rake task and run the following initialization code.
        Rake.application.top_level_tasks.each do |task_name|
          case task_name
            when "requirejs:precompile:all"
              # Enable class reloading so that Sprockets doesn't freeze the assets environment. This allows settings
              # for JS compression to be changes on a per-file basis.
              config.cache_classes = false
          end
        end if defined?(Rake.application)

        manifest_directory = config.assets.manifest || File.join(::Rails.public_path, config.assets.prefix)
        manifest_path = File.join(manifest_directory, "rjs_manifest.yml")
        config.requirejs.manifest_path = Pathname.new(manifest_path)
      end

      ### Initializers
      initializer "requirejs.tag_included_state" do |app|
        ActiveSupport.on_load(:action_controller) do
          ::ActionController::Base.class_eval do
            attr_accessor :requirejs_included
          end
        end
      end

      if ::Rails::VERSION::STRING >= "4.0.0"
        config.after_initialize do |app|
          config = app.config
          rails_manifest_path = File.join(app.root, 'public', config.assets.prefix)
          rails_manifest = Sprockets::Manifest.new(app.assets, rails_manifest_path)
          if config.requirejs.manifest_path.exist? && rails_manifest
            rjs_digests = YAML.load(ERB.new(File.new(config.requirejs.manifest_path).read).result)
            rails_manifest.assets.merge!(rjs_digests)<commit_msg>Prevent Sprockets from freezing the assets environment on Rails 3<commit_after>require 'requirejs/rails/config'

require 'pathname'

module Requirejs
  module Rails
    class Engine < ::Rails::Engine
      ### Configuration setup
      config.before_configuration do |app|
        config.requirejs = Requirejs::Rails::Config.new(app)
        config.requirejs.precompile = [/require\.js$/]
      end

      config.before_initialize do |app|
        config = app.config

        # Process the user config file in #before_initalization (instead of #before_configuration) so that
        # environment-specific configuration can be injected into the user configuration file
        Engine.process_user_config_file(app, config)

        config.assets.precompile += config.requirejs.precompile

        # Check for the `requirejs:precompile:all` top-level Rake task and run the following initialization code.
        if defined?(Rake.application) && Rake.application.top_level_tasks == ["requirejs:precompile:all"]
          # Prevent Sprockets from freezing the assets environment, which allows JS compression to be toggled on a per-
          # file basis. This trick *will* fail if any of the lines linked to below change.

          if ::Rails::VERSION::MAJOR >= 4
            # For Rails 4 (see
            # `https://github.com/rails/sprockets-rails/blob/v2.1.2/lib/sprockets/railtie.rb#L119-121`).
            config.cache_classes = false
          else
            # For Rails 3 (see
            # `https://github.com/rails/rails/blob/v3.2.19/actionpack/lib/sprockets/bootstrap.rb#L32-34`).
            config.assets.digest = false
          end
        end

        manifest_directory = config.assets.manifest || File.join(::Rails.public_path, config.assets.prefix)
        manifest_path = File.join(manifest_directory, "rjs_manifest.yml")
        config.requirejs.manifest_path = Pathname.new(manifest_path)
      end

      ### Initializers
      initializer "requirejs.tag_included_state" do |app|
        ActiveSupport.on_load(:action_controller) do
          ::ActionController::Base.class_eval do
            attr_accessor :requirejs_included
          end
        end
      end

      if ::Rails::VERSION::MAJOR >= 4
        config.after_initialize do |app|
          config = app.config
          rails_manifest_path = File.join(app.root, 'public', config.assets.prefix)
          rails_manifest = Sprockets::Manifest.new(app.assets, rails_manifest_path)
          if config.requirejs.manifest_path.exist? && rails_manifest
            rjs_digests = YAML.load(ERB.new(File.new(config.requirejs.manifest_path).read).result)
            rails_manifest.assets.merge!(rjs_digests)
{'fraction_non_alphanumeric': 0.09061748195669607, 'fraction_numerical': 0.005012028869286287, 'mean_word_length': 2.782410917361638, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 2, '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': '6485698', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1369, 'n_words': 321}