Merge branch 'PluginsAsArray' of https://github.com/simensen/jekyll into simensen-PluginsAsArray

This commit is contained in:
Tom Preston-Werner 2012-01-29 12:32:59 -08:00
commit 02366ae5ff
2 changed files with 41 additions and 3 deletions

View File

@ -18,7 +18,17 @@ module Jekyll
self.safe = config['safe']
self.source = File.expand_path(config['source'])
self.dest = File.expand_path(config['destination'])
self.plugins = File.expand_path(config['plugins'])
self.plugins = if config['plugins'].respond_to?('each')
# If plugins is an array, process it.
Array(config['plugins']).map { |d| File.expand_path(d) }
else
if config['plugins'].nil?
[]
else
# Otherwise process a single entry as an array.
[File.expand_path(config['plugins'])]
end
end
self.lsi = config['lsi']
self.pygments = config['pygments']
self.permalink_style = config['permalink'].to_sym
@ -73,8 +83,10 @@ module Jekyll
# If safe mode is off, load in any Ruby files under the plugins
# directory.
unless self.safe
Dir[File.join(self.plugins, "**/*.rb")].each do |f|
require f
self.plugins.each do |plugins|
Dir[File.join(plugins, "**/*.rb")].each do |f|
require f
end
end
end

View File

@ -1,6 +1,32 @@
require 'helper'
class TestSite < Test::Unit::TestCase
context "configuring sites" do
should "have an array for plugins by default" do
site = Site.new(Jekyll::DEFAULTS)
assert_equal [File.join(Dir.pwd, '_plugins')], site.plugins
end
should "have an array for plugins if passed as a string" do
site = Site.new(Jekyll::DEFAULTS.merge({'plugins' => '/tmp/plugins'}))
assert_equal ['/tmp/plugins'], site.plugins
end
should "have an array for plugins if passed as an array" do
site = Site.new(Jekyll::DEFAULTS.merge({'plugins' => ['/tmp/plugins', '/tmp/otherplugins']}))
assert_equal ['/tmp/plugins', '/tmp/otherplugins'], site.plugins
end
should "have an empty array for plugins if nothing is passed" do
site = Site.new(Jekyll::DEFAULTS.merge({'plugins' => []}))
assert_equal [], site.plugins
end
should "have an empty array for plugins if nil is passed" do
site = Site.new(Jekyll::DEFAULTS.merge({'plugins' => nil}))
assert_equal [], site.plugins
end
end
context "creating sites" do
setup do
stub(Jekyll).configuration do