Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Plugins can be specified as a list of directories to scan. #438

Merged
merged 3 commits into from

2 participants

@simensen

This will allow for maintaining a repository of plugins that several Jekyll sites can reference.

@simensen

Is this something there is any interest in? I would be happy to change it as needed if another implementation if preferred.

lib/jekyll/site.rb
@@ -18,7 +18,13 @@ 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.
+ config['plugins'].each { |directory| File.expand_path(directory) }
@mojombo Owner
mojombo added a note

This isn't doing what you expect. You need to use Array#map to get the correct result. This would also be better written using the Array method:

Array(config['plugins']).map { |d| File.expand_path(d) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mojombo
Owner

I'd love to see this rewritten with the comments above and with a few tests to verify it's working as advertised.

@simensen

OK, I went ahead and took a crack at this. Let me know if you'd like anything else changed or would like some additional testing done or would like the testing to be done differently.

@mojombo mojombo merged commit e6d89c6 into from
@mojombo
Owner

Thanks for getting those tests in. I've merged this with some changes in 4499df8 to do what I was trying to communicate earlier.

@simensen

Great! Thanks. I'm still pretty new to Ruby so I wasn't exactly sure what you were suggesting. I guess Array can accept either a string or an array? Neat. :) Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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
@@ -72,8 +82,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
Something went wrong with that request. Please try again.