Better directory structure for plugins
This commit is contained in:
parent
5fc63e2355
commit
9956e6d012
|
@ -111,15 +111,31 @@ end
|
||||||
# # Default I18n to load the en locale
|
# # Default I18n to load the en locale
|
||||||
I18n.load_path << File.expand_path("templates/locales/en.yml", Vagrant.source_root)
|
I18n.load_path << File.expand_path("templates/locales/en.yml", Vagrant.source_root)
|
||||||
|
|
||||||
# Load the core plugins that ship with Vagrant
|
# A lambda that knows how to load plugins from a single directory.
|
||||||
Vagrant.source_root.join("plugins").each_child do |directory|
|
plugin_load_proc = lambda do |directory|
|
||||||
# We only care about directories
|
# We only care about directories
|
||||||
|
return false if !directory.directory?
|
||||||
|
|
||||||
|
# If there is a plugin file in the top-level directory, then load
|
||||||
|
# that up.
|
||||||
|
plugin_file = directory.join("plugin.rb")
|
||||||
|
if plugin_file.file?
|
||||||
|
load(plugin_file)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Go through the `plugins` directory and attempt to load any plugins. The
|
||||||
|
# plugins are allowed to be in a directory in `plugins` or at most one
|
||||||
|
# directory deep within the plugins directory. So a plugin can be at
|
||||||
|
# `plugins/foo` or also at `plugins/foo/bar`, but no deeper.
|
||||||
|
Vagrant.source_root.join("plugins").each_child do |directory|
|
||||||
|
# Ignore non-directories
|
||||||
next if !directory.directory?
|
next if !directory.directory?
|
||||||
|
|
||||||
# We only care if there is a plugin file within the directory
|
# Load from this directory, and exit if we successfully loaded a plugin
|
||||||
plugin_file = directory.join("plugin.rb")
|
next if plugin_load_proc.call(directory)
|
||||||
next if !plugin_file.file?
|
|
||||||
|
|
||||||
# Load the plugin!
|
# Otherwise, attempt to load from sub-directories
|
||||||
load(plugin_file)
|
directory.each_child(&plugin_load_proc)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue