lib/requirejs/rails/engine.rb in requirejs-rails-0.9.4 vs lib/requirejs/rails/engine.rb in requirejs-rails-0.9.5

- old
+ new

@@ -19,18 +19,24 @@ 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 + 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 if defined?(Rake.application) + 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 @@ -42,10 +48,10 @@ attr_accessor :requirejs_included end end end - if ::Rails::VERSION::STRING >= "4.0.0" + 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