Merge pull request #864 from mojombo/prioritize_plugins
Prioritize plugins & DRY subclass instantiation
This commit is contained in:
commit
5d34a4c533
|
@ -88,17 +88,8 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.converters = Jekyll::Converter.subclasses.select do |c|
|
self.converters = instantiate_subclasses(Jekyll::Converter)
|
||||||
!self.safe || c.safe
|
self.generators = instantiate_subclasses(Jekyll::Generator)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Internal: Setup the plugin search path
|
# Internal: Setup the plugin search path
|
||||||
|
@ -388,6 +379,21 @@ module Jekyll
|
||||||
end
|
end
|
||||||
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
|
# Read the entries from a particular directory for processing
|
||||||
#
|
#
|
||||||
# dir - The String relative path of the directory to read
|
# dir - The String relative path of the directory to read
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
module Jekyll
|
||||||
|
class Dummy < Generator
|
||||||
|
priority :high
|
||||||
|
|
||||||
|
def generate(site)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -139,6 +139,11 @@ class TestSite < Test::Unit::TestCase
|
||||||
assert_equal mtime3, mtime4 # no modifications, so must be the same
|
assert_equal mtime3, mtime4 # no modifications, so must be the same
|
||||||
end
|
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
|
should "read layouts" do
|
||||||
@site.read_layouts
|
@site.read_layouts
|
||||||
assert_equal ["default", "simple"].sort, @site.layouts.keys.sort
|
assert_equal ["default", "simple"].sort, @site.layouts.keys.sort
|
||||||
|
|
Loading…
Reference in New Issue