Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Prioritize plugins & DRY subclass instantiation #864

Merged
merged 3 commits into from

3 participants

@parkr
Owner

Cleaned up the code from #478 with @mattr-'s code in #841.

@parkr parkr merged commit 5d34a4c into master
@parkr parkr deleted the prioritize_plugins branch
@parkr parkr referenced this pull request from a commit
@parkr parkr Update history to reflect merge of #864. df7b9f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 16, 2013
  1. @sillylogger @parkr
  2. @mattr- @parkr

    Remove the duplication when creating Converters and Generators

    mattr- authored parkr committed
    Encapsulate it in a method and give the method the class to walk the
    subclass tree for to create new objects.
  3. @sillylogger @parkr

    Sort instantiated subclasses in Site.

    sillylogger authored parkr committed
This page is out of date. Refresh to see the latest.
View
28 lib/jekyll/site.rb
@@ -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
@@ -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.sort.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
View
8 test/source/_plugins/dummy.rb
@@ -0,0 +1,8 @@
+module Jekyll
+ class Dummy < Generator
+ priority :high
+
+ def generate(site)
+ end
+ end
+end
View
5 test/test_site.rb
@@ -124,6 +124,11 @@ class TestSite < Test::Unit::TestCase
assert_equal mtime3, mtime4 # no modifications, so must be the same
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
@site.read_layouts
assert_equal ["default", "simple"].sort, @site.layouts.keys.sort
Something went wrong with that request. Please try again.