Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

sort plugins by priority, so they are executed in order #478

Closed
wants to merge 1 commit into from

2 participants

@sillylogger

https://github.com/mojombo/jekyll/wiki/Plugins #Flags suggest that the priority flag will be taken into account when loading plugins. Right now they are loaded and then executed in alphabetical order, according to the file system. I dont see them respecting the priority flag at all.

This is an isolated branch for a prior pull request, thanks for looking into it. Tests are passing.

@ghost Unknown referenced this pull request
Closed

Prioritize plugins #564

@parkr parkr commented on the diff
lib/jekyll/site.rb
@@ -333,5 +324,19 @@ def getConverterImpl(klass)
raise "Converter implementation not found for #{klass}"
end
end
+
+ private
+
+ # Collect safe plugins (or all plugins if Safe mode is off) and initialize
+ # them with the Site config.
+ #
+ # Returns Array.
+ def build_plugins(plugin_array)
@parkr Owner
parkr added a note

@mattr- did this too in #841.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@parkr
Owner

Merged in 7425b2c and caa6a4e

@parkr parkr closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
27 lib/jekyll/site.rb
@@ -80,17 +80,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 = build_plugins(Jekyll::Converter.subclasses)
+ self.generators = build_plugins(Jekyll::Generator.subclasses)
end
# Read Site data from disk and load it into internal data structures.
@@ -333,5 +324,19 @@ def getConverterImpl(klass)
raise "Converter implementation not found for #{klass}"
end
end
+
+ private
+
+ # Collect safe plugins (or all plugins if Safe mode is off) and initialize
+ # them with the Site config.
+ #
+ # Returns Array.
+ def build_plugins(plugin_array)
@parkr Owner
parkr added a note

@mattr- did this too in #841.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ plugin_array.select do |c|
+ !self.safe || c.safe
+ end.sort.map do |c|
+ c.new(self.config)
+ end
+ end
end
end
View
12 test/source/_plugins/dummy.rb
@@ -0,0 +1,12 @@
+module Jekyll
+
+ class Dummy < Generator
+
+ priority :high
+
+ def generate(site)
+ end
+
+ end
+
+end
View
11 test/test_site.rb
@@ -30,7 +30,11 @@ class TestSite < Test::Unit::TestCase
context "creating sites" do
setup do
stub(Jekyll).configuration do
- Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir})
+ Jekyll::DEFAULTS.merge({
+ 'source' => source_dir,
+ 'destination' => dest_dir,
+ 'plugins' => File.join(source_dir, '_plugins')
+ })
end
@site = Site.new(Jekyll.configuration)
end
@@ -118,6 +122,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.