Merge pull request #4342 from jekyll/pr/remove-objectspace-and-use-inherited
Merge pull request 4342
This commit is contained in:
commit
3c0a1386ea
|
@ -1,4 +1,3 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class Generator < Plugin
|
Generator = Class.new(Plugin)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +1,39 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class Plugin
|
class Plugin
|
||||||
PRIORITIES = { :lowest => -100,
|
PRIORITIES = {
|
||||||
:low => -10,
|
:low => -10,
|
||||||
|
:highest => 100,
|
||||||
|
:lowest => -100,
|
||||||
:normal => 0,
|
:normal => 0,
|
||||||
:high => 10,
|
:high => 10
|
||||||
:highest => 100 }
|
}
|
||||||
|
|
||||||
# Fetch all the subclasses of this class and its subclasses' subclasses.
|
|
||||||
#
|
#
|
||||||
# Returns an array of descendant classes.
|
|
||||||
def self.descendants
|
def self.inherited(const)
|
||||||
descendants = []
|
return catch_inheritance(const) do |const_|
|
||||||
ObjectSpace.each_object(singleton_class) do |k|
|
catch_inheritance(const_)
|
||||||
descendants.unshift k unless k == self
|
|
||||||
end
|
end
|
||||||
descendants
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
def self.catch_inheritance(const)
|
||||||
|
const.define_singleton_method :inherited do |const_|
|
||||||
|
(@children ||= Set.new).add const_
|
||||||
|
if block_given?
|
||||||
|
yield const_
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
def self.descendants
|
||||||
|
@children ||= Set.new
|
||||||
|
out = @children.map(&:descendants)
|
||||||
|
out << self unless superclass == Plugin
|
||||||
|
Set.new(out).flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get or set the priority of this plugin. When called without an
|
# Get or set the priority of this plugin. When called without an
|
||||||
|
|
|
@ -263,25 +263,21 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the implementation class for the given Converter.
|
# Get the implementation class for the given Converter.
|
||||||
#
|
|
||||||
# klass - The Class of the Converter to fetch.
|
|
||||||
#
|
|
||||||
# Returns the Converter instance implementing the given Converter.
|
# Returns the Converter instance implementing the given Converter.
|
||||||
|
# klass - The Class of the Converter to fetch.
|
||||||
|
|
||||||
def find_converter_instance(klass)
|
def find_converter_instance(klass)
|
||||||
converters.find { |c| c.class == klass } || proc { raise "No converter for #{klass}" }.call
|
converters.find { |klass_| klass_.instance_of?(klass) } || \
|
||||||
|
raise("No Converters found for #{klass}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# klass - class or module containing the subclasses.
|
||||||
|
# Returns array of instances of subclasses of parameter.
|
||||||
# Create array of instances of the subclasses of the class or module
|
# Create array of instances of the subclasses of the class or module
|
||||||
# passed in as argument.
|
# 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)
|
def instantiate_subclasses(klass)
|
||||||
klass.descendants.select do |c|
|
klass.descendants.select { |c| !safe || c.safe }.sort.map do |c|
|
||||||
!safe || c.safe
|
|
||||||
end.sort.map do |c|
|
|
||||||
c.new(config)
|
c.new(config)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue