Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow converters to be registered through subclassing much like railt…

…ies in rails
  • Loading branch information...
commit 315f4c9222ef0a6af5362751e897cda1ec1fcb10 1 parent cedda3a
@krisb krisb authored
View
3  lib/jekyll.rb
@@ -27,9 +27,10 @@
require 'jekyll/tags/include'
require 'jekyll/albino'
require 'jekyll/static_file'
+require 'jekyll/converter'
+require 'jekyll/converters/identity'
require 'jekyll/converters/markdown'
require 'jekyll/converters/textile'
-require 'jekyll/converters/identity'
module Jekyll
# Default options. Overriden by values in _config.yml or command-line opts.
View
50 lib/jekyll/converter.rb
@@ -0,0 +1,50 @@
+module Jekyll
+
+ class Converter
+
+ PRIORITIES = { :lowest => -100,
+ :low => -10,
+ :normal => 0,
+ :high => 10,
+ :highest => 100 }
+
+ class << self
+ def subclasses
+ @subclasses ||= []
+ end
+
+ def inherited(base)
+ subclasses << base
+ subclasses.sort!
+ end
+
+ # priority order of this converter
+ def priority(priority = nil)
+ if priority && PRIORITIES.has_key?(priority)
+ @priority = priority
+ end
+ @priority || :normal
+ end
+
+ # priority order of this converter
+ def content_type(content_type = nil)
+ @content_type = content_type if content_type
+ @content_type || self.name.downcase.gsub(/^.*::/, '').gsub(/converter$/, '')
+ end
+
+ # Spaceship is priority [higher -> lower]
+ #
+ # Returns -1, 0, 1
+ def <=>(other)
+ cmp = PRIORITIES[other.priority] <=> PRIORITIES[self.priority]
+ return cmp
+ end
+ end
+
+ def content_type
+ self.class.content_type
+ end
+
+ end
+
+end
View
9 lib/jekyll/converters/identity.rb
@@ -1,15 +1,11 @@
module Jekyll
-
- class IdentityConverter
+ class IdentityConverter < Converter
+ priority :lowest
def initialize(config = {})
end
- def content_type
- nil
- end
-
def matches(ext)
true
end
@@ -23,5 +19,4 @@ def convert(content)
end
end
-
end
View
8 lib/jekyll/converters/markdown.rb
@@ -1,6 +1,5 @@
module Jekyll
-
- class MarkdownConverter
+ class MarkdownConverter < Converter
def initialize(config = {})
# Set the Markdown interpreter (and Maruku self.config, if necessary)
@@ -52,10 +51,6 @@ def convert(content)
end
end
- def content_type
- "markdown"
- end
-
def matches(ext)
ext =~ /(markdown|mkdn?|md)/i
end
@@ -65,5 +60,4 @@ def output_ext(ext)
end
end
-
end
View
8 lib/jekyll/converters/textile.rb
@@ -1,15 +1,10 @@
module Jekyll
-
- class TextileConverter
+ class TextileConverter < Converter
def initialize(config = {})
end
- def content_type
- "textile"
- end
-
def matches(ext)
ext =~ /textile/i
end
@@ -23,5 +18,4 @@ def convert(content)
end
end
-
end
View
9 lib/jekyll/site.rb
@@ -19,7 +19,6 @@ def initialize(config)
self.permalink_style = config['permalink'].to_sym
self.exclude = config['exclude'] || []
self.future = config['future']
- self.converters = []
self.reset
self.setup
@@ -39,11 +38,7 @@ def setup
# Check to see if LSI is enabled.
require 'classifier' if self.lsi
- # converters
- converters << Jekyll::MarkdownConverter.new(self.config)
- converters << Jekyll::TextileConverter.new(self.config)
- converters << Jekyll::IdentityConverter.new(self.config)
-
+ self.converters = Jekyll::Converter.subclasses.collect { |c| c.new(self.config) }
end
# Do the actual work of processing the site and generating the
@@ -135,7 +130,7 @@ def write
end
end
- # Reads the directories and finds posts, pages and static files that will
+ # Reads the directories and finds posts, pages and static files that will
# become part of the valid site according to the rules in +filter_entries+.
# The +dir+ String is a relative path used to call this method
# recursively as it descends through directories
Please sign in to comment.
Something went wrong with that request. Please try again.