Skip to content

Commit

Permalink
Remove the duplication when creating Converters and Generators
Browse files Browse the repository at this point in the history
Encapsulate it in a method and give the method the class to walk the
subclass tree for to create new objects.
  • Loading branch information
mattr- authored and parkr committed Mar 16, 2013
1 parent 7425b2c commit 10ee5c8
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/jekyll/site.rb
Expand Up @@ -88,17 +88,8 @@ def setup
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
Expand Down Expand Up @@ -388,6 +379,21 @@ def getConverterImpl(klass)
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
#
# dir - The String relative path of the directory to read
Expand Down

0 comments on commit 10ee5c8

Please sign in to comment.