Skip to content

Commit dcf5462

Browse files
committed
Tweaked plugin directory handling, tests.
1 parent ab08aca commit dcf5462

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/jekyll/site.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ class Site
1414
# config - A Hash containing site configuration details.
1515
def initialize(config)
1616
self.config = config.clone
17-
1817
self.safe = config['safe']
1918
self.source = File.expand_path(config['source'])
2019
self.dest = File.expand_path(config['destination'])
2120
self.plugins = if config['plugins'].respond_to?('each')
2221
# If plugins is an array, process it.
23-
config['plugins'].each { |directory| File.expand_path(directory) }
22+
Array(config['plugins']).map { |d| File.expand_path(d) }
2423
else
2524
# Otherwise process a single entry as an array.
26-
[File.expand_path(config['plugins'])]
25+
if config['plugins'].nil?
26+
[]
27+
else
28+
[File.expand_path(config['plugins'])]
29+
end
2730
end
2831
self.lsi = config['lsi']
2932
self.pygments = config['pygments']

test/test_site.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
require 'helper'
22

33
class TestSite < Test::Unit::TestCase
4+
context "configuring sites" do
5+
should "have an array for plugins by default" do
6+
site = Site.new(Jekyll::DEFAULTS)
7+
assert_equal [File.join(Dir.pwd, '_plugins')], site.plugins
8+
end
9+
10+
should "have an array for plugins if passed as a string" do
11+
site = Site.new(Jekyll::DEFAULTS.merge({'plugins' => '/tmp/plugins'}))
12+
assert_equal ['/tmp/plugins'], site.plugins
13+
end
14+
15+
should "have an array for plugins if passed as an array" do
16+
site = Site.new(Jekyll::DEFAULTS.merge({'plugins' => ['/tmp/plugins', '/tmp/otherplugins']}))
17+
assert_equal ['/tmp/plugins', '/tmp/otherplugins'], site.plugins
18+
end
19+
20+
should "have an array for plugins if nothing is passed" do
21+
site = Site.new(Jekyll::DEFAULTS.merge({'plugins' => []}))
22+
assert_equal [], site.plugins
23+
end
24+
end
425
context "creating sites" do
526
setup do
627
stub(Jekyll).configuration do

0 commit comments

Comments
 (0)