railtie.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. require "action_controller/railtie"
  2. module Sprockets
  3. autoload :Bootstrap, "sprockets/bootstrap"
  4. autoload :Helpers, "sprockets/helpers"
  5. autoload :Compressors, "sprockets/compressors"
  6. autoload :LazyCompressor, "sprockets/compressors"
  7. autoload :NullCompressor, "sprockets/compressors"
  8. autoload :StaticCompiler, "sprockets/static_compiler"
  9. # TODO: Get rid of config.assets.enabled
  10. class Railtie < ::Rails::Railtie
  11. rake_tasks do
  12. load "sprockets/assets.rake"
  13. end
  14. initializer "sprockets.environment", :group => :all do |app|
  15. config = app.config
  16. next unless config.assets.enabled
  17. require 'sprockets'
  18. app.assets = Sprockets::Environment.new(app.root.to_s) do |env|
  19. env.version = ::Rails.env + "-#{config.assets.version}"
  20. if config.assets.logger != false
  21. env.logger = config.assets.logger || ::Rails.logger
  22. end
  23. if config.assets.cache_store != false
  24. env.cache = ActiveSupport::Cache.lookup_store(config.assets.cache_store) || ::Rails.cache
  25. end
  26. end
  27. if config.assets.manifest
  28. path = File.join(config.assets.manifest, "manifest.yml")
  29. else
  30. path = File.join(Rails.public_path, config.assets.prefix, "manifest.yml")
  31. end
  32. if File.exist?(path)
  33. config.assets.digests = YAML.load_file(path)
  34. end
  35. ActiveSupport.on_load(:action_view) do
  36. include ::Sprockets::Helpers::RailsHelper
  37. app.assets.context_class.instance_eval do
  38. include ::Sprockets::Helpers::IsolatedHelper
  39. include ::Sprockets::Helpers::RailsHelper
  40. end
  41. end
  42. end
  43. # We need to configure this after initialization to ensure we collect
  44. # paths from all engines. This hook is invoked exactly before routes
  45. # are compiled, and so that other Railties have an opportunity to
  46. # register compressors.
  47. config.after_initialize do |app|
  48. Sprockets::Bootstrap.new(app).run
  49. end
  50. end
  51. end