diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/application.rb | 31 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 9 | ||||
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 15 | ||||
-rw-r--r-- | railties/lib/rails/tasks.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/tasks/assets.rake | 6 |
5 files changed, 61 insertions, 1 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 1b834275a7..66a1f88c61 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -137,6 +137,37 @@ 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.assets.enabled + require 'sprockets' + env = Sprockets::Environment.new(root.to_s) + env.static_root = File.join(root.join("public"), config.assets.prefix) + env + end + + initializer :add_sprockets_paths do |app| + if config.assets.enabled + paths = [ + "app/javascripts", + "app/stylesheets", + "vendor/plugins/*/app/javascripts", + "vendor/plugins/*/app/stylesheets", + "vendor/plugins/*/javascripts", + "vendor/plugins/*/stylesheets" + ] + config.assets.paths + + paths.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..4a042e0033 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, + :assets attr_writer :log_level @@ -29,6 +30,12 @@ module Rails @log_level = nil @middleware = app_middleware @generators = app_generators + + @assets = ActiveSupport::OrderedOptions.new + @assets.enabled = false + @assets.paths = [] + @assets.precompile = [] + @assets.prefix = "/assets" end def compiled_asset_path diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index a45b61c99c..be063e5f25 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -33,6 +33,21 @@ module Rails end end + initializer :add_sprockets_route do |app| + assets = config.assets + if assets.enabled + app.routes.append do + mount app.assets => assets.prefix + end + end + end + + initializer :set_sprockets_logger do |app| + if config.assets.enabled + 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..396ce728a1 --- /dev/null +++ b/railties/lib/rails/tasks/assets.rake @@ -0,0 +1,6 @@ +namespace :assets do + task :compile => :environment do + assets = Rails.application.config.assets.precompile + Rails.application.assets.precompile(*assets) + end +end |