allow converters to be registered through subclassing much like railties in rails
This commit is contained in:
parent
cedda3afa3
commit
315f4c9222
|
@ -27,9 +27,10 @@ require 'jekyll/tags/highlight'
|
||||||
require 'jekyll/tags/include'
|
require 'jekyll/tags/include'
|
||||||
require 'jekyll/albino'
|
require 'jekyll/albino'
|
||||||
require 'jekyll/static_file'
|
require 'jekyll/static_file'
|
||||||
|
require 'jekyll/converter'
|
||||||
|
require 'jekyll/converters/identity'
|
||||||
require 'jekyll/converters/markdown'
|
require 'jekyll/converters/markdown'
|
||||||
require 'jekyll/converters/textile'
|
require 'jekyll/converters/textile'
|
||||||
require 'jekyll/converters/identity'
|
|
||||||
|
|
||||||
module Jekyll
|
module Jekyll
|
||||||
# Default options. Overriden by values in _config.yml or command-line opts.
|
# Default options. Overriden by values in _config.yml or command-line opts.
|
||||||
|
|
|
@ -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
|
|
@ -1,15 +1,11 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
|
class IdentityConverter < Converter
|
||||||
class IdentityConverter
|
priority :lowest
|
||||||
|
|
||||||
def initialize(config = {})
|
def initialize(config = {})
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_type
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches(ext)
|
def matches(ext)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -23,5 +19,4 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
|
class MarkdownConverter < Converter
|
||||||
class MarkdownConverter
|
|
||||||
|
|
||||||
def initialize(config = {})
|
def initialize(config = {})
|
||||||
# Set the Markdown interpreter (and Maruku self.config, if necessary)
|
# Set the Markdown interpreter (and Maruku self.config, if necessary)
|
||||||
|
@ -52,10 +51,6 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_type
|
|
||||||
"markdown"
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches(ext)
|
def matches(ext)
|
||||||
ext =~ /(markdown|mkdn?|md)/i
|
ext =~ /(markdown|mkdn?|md)/i
|
||||||
end
|
end
|
||||||
|
@ -65,5 +60,4 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
|
class TextileConverter < Converter
|
||||||
class TextileConverter
|
|
||||||
|
|
||||||
def initialize(config = {})
|
def initialize(config = {})
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_type
|
|
||||||
"textile"
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches(ext)
|
def matches(ext)
|
||||||
ext =~ /textile/i
|
ext =~ /textile/i
|
||||||
end
|
end
|
||||||
|
@ -23,5 +18,4 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,6 @@ module Jekyll
|
||||||
self.permalink_style = config['permalink'].to_sym
|
self.permalink_style = config['permalink'].to_sym
|
||||||
self.exclude = config['exclude'] || []
|
self.exclude = config['exclude'] || []
|
||||||
self.future = config['future']
|
self.future = config['future']
|
||||||
self.converters = []
|
|
||||||
|
|
||||||
self.reset
|
self.reset
|
||||||
self.setup
|
self.setup
|
||||||
|
@ -39,11 +38,7 @@ module Jekyll
|
||||||
# Check to see if LSI is enabled.
|
# Check to see if LSI is enabled.
|
||||||
require 'classifier' if self.lsi
|
require 'classifier' if self.lsi
|
||||||
|
|
||||||
# converters
|
self.converters = Jekyll::Converter.subclasses.collect { |c| c.new(self.config) }
|
||||||
converters << Jekyll::MarkdownConverter.new(self.config)
|
|
||||||
converters << Jekyll::TextileConverter.new(self.config)
|
|
||||||
converters << Jekyll::IdentityConverter.new(self.config)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Do the actual work of processing the site and generating the
|
# Do the actual work of processing the site and generating the
|
||||||
|
@ -135,7 +130,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
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+.
|
# 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
|
# The +dir+ String is a relative path used to call this method
|
||||||
# recursively as it descends through directories
|
# recursively as it descends through directories
|
||||||
|
|
Loading…
Reference in New Issue