Remove the duplication when creating Converters and Generators
Encapsulate it in a method and give the method the class to walk the subclass tree for to create new objects.
This commit is contained in:
parent
7425b2c32e
commit
10ee5c8999
|
@ -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.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
|
||||||
|
|
Loading…
Reference in New Issue