提交 c1a52510 编写于 作者: D David Heinemeier Hansson

Added config.plugins to control which plugins are loaded #6269 [skaes]. By...

Added config.plugins to control which plugins are loaded #6269 [skaes]. By default, everything in vendor/plugins will be loaded, but if you specify config.plugins, only those will be loaded.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5317 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 911f3db0
*SVN*
* Added config.plugins to control which plugins are loaded #6269 [skaes]. By default, everything in vendor/plugins will be loaded, but if you specify config.plugins, only those will be loaded. Example:
config.plugins = %w[ routing_navigator simply_helpful ]
* Clean up html on included error pages. [Tim Lucas]
* Fixed default 404.html and 500.htmls to remove extreme ugliness and include human language [DHH]
......
......@@ -11,12 +11,15 @@
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence those specified here
# Settings in config/environments/* take precedence over those specified here
# Skip frameworks you're not going to use (only works if using vendor/rails)
# config.frameworks -= [ :action_web_service, :action_mailer ]
# Add additional load paths for your own custom dirs
# Only load the plugins named here, by default all plugins in vendor/plugins are loaded
# config.plugins = %W( exception_notification ssl_requirement )
# Add additional load paths (these paths will be subject to auto-loading of constants)
# config.load_paths += %W( #{RAILS_ROOT}/extras )
# Force all environments to use the same logger level
......
......@@ -322,7 +322,7 @@ def find_plugins(*base_paths)
base_paths.flatten.inject([]) do |plugins, base_path|
Dir.glob(File.join(base_path, '*')).each do |path|
if plugin_path?(path)
plugins << path
plugins << path if plugin_enabled?(path)
elsif File.directory?(path)
plugins += find_plugins(path)
end
......@@ -335,6 +335,10 @@ def plugin_path?(path)
File.directory?(path) and (File.directory?(File.join(path, 'lib')) or File.file?(File.join(path, 'init.rb')))
end
def plugin_enabled?(path)
configuration.plugins.empty? || configuration.plugins.include?(File.basename(path))
end
# Load the plugin at <tt>path</tt> unless already loaded.
#
# Each plugin is initialized:
......@@ -456,6 +460,9 @@ class Configuration
# Set to +true+ if you want to be warned (noisily) when you try to invoke
# any method of +nil+. Set to +false+ for the standard Ruby behavior.
attr_accessor :whiny_nils
# The list of plugins to load. If this is set to <tt>[]</tt>, all plugins will be loaded.
attr_accessor :plugins
# The path to the root of the plugins directory. By default, it is in
# <tt>vendor/plugins</tt>.
......@@ -474,6 +481,7 @@ def initialize
self.cache_classes = default_cache_classes
self.breakpoint_server = default_breakpoint_server
self.whiny_nils = default_whiny_nils
self.plugins = default_plugins
self.plugin_paths = default_plugin_paths
self.database_configuration_file = default_database_configuration_file
......@@ -624,6 +632,10 @@ def default_whiny_nils
false
end
def default_plugins
[]
end
def default_plugin_paths
["#{root_path}/vendor/plugins"]
end
......@@ -663,4 +675,4 @@ def find_pair(key)
self.each { |i| return i if i.first == key }
return false
end
end
\ No newline at end of file
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册