Skip to content
Browse files

Merge branch 'PluginsAsArray' of https://github.com/simensen/jekyll i…

…nto simensen-PluginsAsArray
  • Loading branch information...
2 parents 9d70088 + e6d89c6 commit 02366ae5fff8ccee465a308445172f121b979a99 @mojombo mojombo committed
Showing with 41 additions and 3 deletions.
  1. +15 −3 lib/jekyll/site.rb
  2. +26 −0 test/test_site.rb
View
18 lib/jekyll/site.rb
@@ -18,7 +18,17 @@ def initialize(config)
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 @@ def setup
# 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
26 test/test_site.rb
@@ -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

0 comments on commit 02366ae

Please sign in to comment.
Something went wrong with that request. Please try again.