mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Move sprockets initializers back to application
This commit is contained in:
parent
db3e310d6b
commit
612454e00e
5 changed files with 41 additions and 51 deletions
|
@ -137,6 +137,33 @@ 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 nil if !config.use_sprockets
|
||||
require 'sprockets'
|
||||
env = Sprockets::Environment.new(root.to_s)
|
||||
env.static_root = root.join("public/assets")
|
||||
env
|
||||
end
|
||||
|
||||
initializer :add_sprockets_paths do |app|
|
||||
[
|
||||
"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
|
||||
|
||||
protected
|
||||
|
||||
def default_asset_path
|
||||
|
|
|
@ -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
|
||||
:time_zone, :whiny_nils,
|
||||
:use_sprockets, :compile_assets
|
||||
|
||||
attr_writer :log_level
|
||||
|
||||
|
@ -28,6 +29,8 @@ module Rails
|
|||
@log_level = nil
|
||||
@middleware = app_middleware
|
||||
@generators = app_generators
|
||||
@use_sprockets = false
|
||||
@compile_assets = []
|
||||
end
|
||||
|
||||
def compiled_asset_path
|
||||
|
|
|
@ -33,6 +33,14 @@ module Rails
|
|||
end
|
||||
end
|
||||
|
||||
initializer :add_sprockets_route do |app|
|
||||
if config.use_sprockets
|
||||
app.routes.append do
|
||||
mount app.assets => "/assets"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
initializer :build_middleware_stack do
|
||||
build_middleware_stack
|
||||
end
|
||||
|
|
|
@ -433,56 +433,11 @@ module Rails
|
|||
end
|
||||
|
||||
def routes
|
||||
@routes ||= build_route_set
|
||||
@routes ||= ActionDispatch::Routing::RouteSet.new
|
||||
@routes.append(&Proc.new) if block_given?
|
||||
@routes
|
||||
end
|
||||
|
||||
def build_route_set
|
||||
routes = ActionDispatch::Routing::RouteSet.new
|
||||
|
||||
engine = self
|
||||
routes.append do
|
||||
if engine.config.use_sprockets
|
||||
routes.add_route(engine.assets, {:path_info => "/assets"}, {}, {}, nil, false)
|
||||
end
|
||||
end
|
||||
|
||||
routes
|
||||
end
|
||||
|
||||
def self.default_sprockets_paths
|
||||
[
|
||||
"app/javascripts",
|
||||
"app/stylesheets",
|
||||
"vendor/plugins/*/app/javascripts",
|
||||
"vendor/plugins/*/app/stylesheets",
|
||||
"vendor/plugins/*/javascripts",
|
||||
"vendor/plugins/*/stylesheets"
|
||||
]
|
||||
end
|
||||
|
||||
def assets
|
||||
@assets ||= build_asset_environment
|
||||
end
|
||||
|
||||
def build_asset_environment
|
||||
return nil if !config.use_sprockets
|
||||
|
||||
require 'sprockets'
|
||||
|
||||
env = Sprockets::Environment.new(root.to_s)
|
||||
env.static_root = root.join("public/assets")
|
||||
|
||||
self.class.default_sprockets_paths.each do |pattern|
|
||||
Dir[root.join(pattern)].each do |dir|
|
||||
env.paths << dir
|
||||
end
|
||||
end
|
||||
|
||||
env
|
||||
end
|
||||
|
||||
def initializers
|
||||
initializers = []
|
||||
railties.all { |r| initializers += r.initializers }
|
||||
|
|
|
@ -5,15 +5,12 @@ module Rails
|
|||
class Configuration < ::Rails::Railtie::Configuration
|
||||
attr_reader :root
|
||||
attr_writer :middleware, :eager_load_paths, :autoload_once_paths, :autoload_paths
|
||||
attr_accessor :plugins, :asset_path, :use_sprockets, :compile_assets
|
||||
attr_accessor :plugins, :asset_path
|
||||
|
||||
def initialize(root=nil)
|
||||
super()
|
||||
@root = root
|
||||
@generators = app_generators.dup
|
||||
|
||||
@use_sprockets = false
|
||||
@compile_assets = []
|
||||
end
|
||||
|
||||
# Returns the middleware stack for the engine.
|
||||
|
|
Loading…
Reference in a new issue