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