From f2f2ebfa4fdc0cd6e039382e355978aabd7365d8 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 7 May 2014 14:59:08 -0400 Subject: [PATCH] Register subclasses of subclasses of Jekyll::Plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Sass and SCSS converters are practically the same – only different in the input syntax and file extension. As such, we've created `Jekyll::Converters::Scss` which is a subclass of `Jekyll::Converter`, and `Jekyll::Converters::Sass` which is a subclass of `Jekyll::Converters::Scss`. When `Site#instantiate_classes` is called on `Jekyll::Converter`, it only instantiates the `Scss` converter, not the `Sass` converter. This change fixes that. Fixes #2334. --- lib/jekyll/plugin.rb | 23 ++++++++--------------- lib/jekyll/site.rb | 2 +- test/test_sass.rb | 8 ++++++++ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/jekyll/plugin.rb b/lib/jekyll/plugin.rb index 2613f70d..94c0b28e 100644 --- a/lib/jekyll/plugin.rb +++ b/lib/jekyll/plugin.rb @@ -6,22 +6,15 @@ module Jekyll :high => 10, :highest => 100 } - # Install a hook so that subclasses are recorded. This method is only - # ever called by Ruby itself. + # Fetch all the subclasses of this class and its subclasses' subclasses. # - # base - The Class subclass. - # - # Returns nothing. - def self.inherited(base) - subclasses << base - subclasses.sort! - end - - # The list of Classes that have been subclassed. - # - # Returns an Array of Class objects. - def self.subclasses - @subclasses ||= [] + # Returns an array of descendant classes. + def self.descendants + descendants = [] + ObjectSpace.each_object(singleton_class) do |k| + descendants.unshift k unless k == self + end + descendants end # Get or set the priority of this plugin. When called without an diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 648fad6c..288662a5 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -365,7 +365,7 @@ module Jekyll # # Returns array of instances of subclasses of parameter def instantiate_subclasses(klass) - klass.subclasses.select do |c| + klass.descendants.select do |c| !safe || c.safe end.sort.map do |c| c.new(config) diff --git a/test/test_sass.rb b/test/test_sass.rb index b03b1137..102815a0 100644 --- a/test/test_sass.rb +++ b/test/test_sass.rb @@ -14,5 +14,13 @@ class TestSass < Test::Unit::TestCase should "import SCSS partial" do assert_equal ".half {\n width: 50%; }\n", File.read(@test_css_file) end + + should "register the SCSS converter" do + assert !!@site.getConverterImpl(Jekyll::Converters::Scss), "SCSS converter implementation should exist." + end + + should "register the Sass converter" do + assert !!@site.getConverterImpl(Jekyll::Converters::Sass), "Sass converter implementation should exist." + end end end