diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/application.rb | 29 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 14 | ||||
-rw-r--r-- | railties/lib/rails/tasks.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/tasks/assets.rake | 6 |
5 files changed, 54 insertions, 1 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 1b834275a7..5b8841fd97 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -137,6 +137,35 @@ module Rails @config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd)) end + def assets + @assets ||= build_asset_environment + end + + def build_asset_environment + return unless config.asset_pipeline + require 'sprockets' + env = Sprockets::Environment.new(root.to_s) + env.static_root = root.join("public/assets") + env + end + + initializer :add_sprockets_paths do |app| + if config.asset_pipeline + [ + "app/javascripts", + "app/stylesheets", + "vendor/plugins/*/app/javascripts", + "vendor/plugins/*/app/stylesheets", + "vendor/plugins/*/javascripts", + "vendor/plugins/*/stylesheets" + ].each do |pattern| + Dir[app.root.join(pattern)].each do |dir| + app.assets.paths << dir + end + end + end + end + protected def default_asset_path diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 23b0e765ae..4ec5336f6c 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -9,7 +9,8 @@ module Rails :filter_parameters, :helpers_paths, :logger, :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, :session_options, - :time_zone, :whiny_nils, :force_ssl + :time_zone, :whiny_nils, :force_ssl, + :asset_pipeline, :precompile_assets attr_writer :log_level @@ -29,6 +30,8 @@ module Rails @log_level = nil @middleware = app_middleware @generators = app_generators + @asset_pipeline = false + @precompile_assets = [] end def compiled_asset_path diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index a45b61c99c..3cfd8f5707 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -33,6 +33,20 @@ module Rails end end + initializer :add_sprockets_route do |app| + if config.asset_pipeline + app.routes.append do + mount app.assets => "/assets" + end + end + end + + initializer :set_sprockets_logger do |app| + if config.asset_pipeline + app.assets.logger = Rails.logger + end + end + initializer :build_middleware_stack do build_middleware_stack end diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb index af52014728..4d09b0c2c0 100644 --- a/railties/lib/rails/tasks.rb +++ b/railties/lib/rails/tasks.rb @@ -3,6 +3,7 @@ $VERBOSE = nil # Load Rails rakefile extensions %w( annotations + assets documentation framework log diff --git a/railties/lib/rails/tasks/assets.rake b/railties/lib/rails/tasks/assets.rake new file mode 100644 index 0000000000..8c85180b34 --- /dev/null +++ b/railties/lib/rails/tasks/assets.rake @@ -0,0 +1,6 @@ +namespace :assets do + task :compile => :environment do + assets = Rails.application.config.precompile_assets + Rails.application.assets.precompile(*assets) + end +end |