From ab08acace956ce834e474369967bc08650e6c6a4 Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Mon, 21 Nov 2011 21:09:39 -0600 Subject: [PATCH 1/3] Support plugins being a list of directories to scan. --- lib/jekyll/site.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 9c24f8e4..22a48a48 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -18,7 +18,13 @@ 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. + config['plugins'].each { |directory| File.expand_path(directory) } + else + # Otherwise process a single entry as an array. + [File.expand_path(config['plugins'])] + end self.lsi = config['lsi'] self.pygments = config['pygments'] self.permalink_style = config['permalink'].to_sym @@ -72,8 +78,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 From dcf546275ba5a1497fb6988b934f8c5da6900080 Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Sun, 22 Jan 2012 22:10:12 -0800 Subject: [PATCH 2/3] Tweaked plugin directory handling, tests. --- lib/jekyll/site.rb | 9 ++++++--- test/test_site.rb | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 22a48a48..0788223f 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -14,16 +14,19 @@ module Jekyll # config - A Hash containing site configuration details. def initialize(config) self.config = config.clone - self.safe = config['safe'] self.source = File.expand_path(config['source']) self.dest = File.expand_path(config['destination']) self.plugins = if config['plugins'].respond_to?('each') # If plugins is an array, process it. - config['plugins'].each { |directory| File.expand_path(directory) } + Array(config['plugins']).map { |d| File.expand_path(d) } else # Otherwise process a single entry as an array. - [File.expand_path(config['plugins'])] + if config['plugins'].nil? + [] + else + [File.expand_path(config['plugins'])] + end end self.lsi = config['lsi'] self.pygments = config['pygments'] diff --git a/test/test_site.rb b/test/test_site.rb index c9b991b7..1c9b1534 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -1,6 +1,27 @@ 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 array for plugins if nothing is passed" do + site = Site.new(Jekyll::DEFAULTS.merge({'plugins' => []})) + assert_equal [], site.plugins + end + end context "creating sites" do setup do stub(Jekyll).configuration do From e6d89c6a0f62fb72245dd266e6d7a5c7ce3c235e Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Sun, 22 Jan 2012 22:17:25 -0800 Subject: [PATCH 3/3] More testing, whitespace and comment cleanup. --- lib/jekyll/site.rb | 3 ++- test/test_site.rb | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 0788223f..c9eb481d 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -14,6 +14,7 @@ module Jekyll # config - A Hash containing site configuration details. def initialize(config) self.config = config.clone + self.safe = config['safe'] self.source = File.expand_path(config['source']) self.dest = File.expand_path(config['destination']) @@ -21,10 +22,10 @@ module Jekyll # If plugins is an array, process it. Array(config['plugins']).map { |d| File.expand_path(d) } else - # Otherwise process a single entry as an array. if config['plugins'].nil? [] else + # Otherwise process a single entry as an array. [File.expand_path(config['plugins'])] end end diff --git a/test/test_site.rb b/test/test_site.rb index 1c9b1534..d9037730 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -17,10 +17,15 @@ class TestSite < Test::Unit::TestCase assert_equal ['/tmp/plugins', '/tmp/otherplugins'], site.plugins end - should "have an array for plugins if nothing is passed" do + 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