Merge pull request #864 from mojombo/prioritize_plugins

Prioritize plugins & DRY subclass instantiation
This commit is contained in:
Parker Moore 2013-03-16 12:09:43 -07:00
commit 5d34a4c533
3 changed files with 30 additions and 11 deletions

View File

@ -88,17 +88,8 @@ module Jekyll
end
end
self.converters = Jekyll::Converter.subclasses.select do |c|
!self.safe || c.safe
end.map do |c|
c.new(self.config)
end
self.generators = Jekyll::Generator.subclasses.select do |c|
!self.safe || c.safe
end.map do |c|
c.new(self.config)
end
self.converters = instantiate_subclasses(Jekyll::Converter)
self.generators = instantiate_subclasses(Jekyll::Generator)
end
# Internal: Setup the plugin search path
@ -388,6 +379,21 @@ module Jekyll
end
end
# Create array of instances of the subclasses of the class or module
# passed in as argument.
#
# klass - class or module containing the subclasses which should be
# instantiated
#
# Returns array of instances of subclasses of parameter
def instantiate_subclasses(klass)
klass.subclasses.select do |c|
!self.safe || c.safe
end.sort.map do |c|
c.new(self.config)
end
end
# Read the entries from a particular directory for processing
#
# dir - The String relative path of the directory to read

View File

@ -0,0 +1,8 @@
module Jekyll
class Dummy < Generator
priority :high
def generate(site)
end
end
end

View File

@ -139,6 +139,11 @@ class TestSite < Test::Unit::TestCase
assert_equal mtime3, mtime4 # no modifications, so must be the same
end
should "setup plugins in priority order" do
assert_equal @site.converters.sort_by(&:class).map{|c|c.class.priority}, @site.converters.map{|c|c.class.priority}
assert_equal @site.generators.sort_by(&:class).map{|g|g.class.priority}, @site.generators.map{|g|g.class.priority}
end
should "read layouts" do
@site.read_layouts
assert_equal ["default", "simple"].sort, @site.layouts.keys.sort