tomdoc and normalize new extension and converter classes

This commit is contained in:
Tom Preston-Werner 2010-04-21 14:36:01 -07:00
parent 0ba1f6c83e
commit a8efc3a0a2
3 changed files with 82 additions and 52 deletions

View File

@ -1,31 +1,43 @@
module Jekyll module Jekyll
class Converter < Extension class Converter < Extension
# Public: Get or set the pygments prefix. When an argument is specified,
class << self # the prefix will be set. If no argument is specified, the current prefix
# prefix for highlighting # will be returned.
def pygments_prefix(pygments_prefix = nil) #
# pygments_prefix - The String prefix (default: nil).
#
# Returns the String prefix.
def self.pygments_prefix(pygments_prefix = nil)
@pygments_prefix = pygments_prefix if pygments_prefix @pygments_prefix = pygments_prefix if pygments_prefix
@pygments_prefix @pygments_prefix
end end
# suffix for highlighting # Public: Get or set the pygments suffix. When an argument is specified,
def pygments_suffix(pygments_suffix = nil) # the suffix will be set. If no argument is specified, the current suffix
# will be returned.
#
# pygments_suffix - The String suffix (default: nil).
#
# Returns the String suffix.
def self.pygments_suffix(pygments_suffix = nil)
@pygments_suffix = pygments_suffix if pygments_suffix @pygments_suffix = pygments_suffix if pygments_suffix
@pygments_suffix @pygments_suffix
end end
end
# prefix for highlighting # Get the pygments prefix.
#
# Returns the String prefix.
def pygments_prefix def pygments_prefix
self.class.pygments_prefix self.class.pygments_prefix
end end
# suffix for highlighting # Get the pygments suffix.
#
# Returns the String suffix.
def pygments_suffix def pygments_suffix
self.class.pygments_suffix self.class.pygments_suffix
end end
end end
end end

View File

@ -1,29 +1,39 @@
module Jekyll module Jekyll
class Extension class Extension
PRIORITIES = { :lowest => -100, PRIORITIES = { :lowest => -100,
:low => -10, :low => -10,
:normal => 0, :normal => 0,
:high => 10, :high => 10,
:highest => 100 } :highest => 100 }
class << self # Install a hook so that subclasses are recorded. This method is only
def subclasses # ever called by Ruby itself.
@subclasses ||= [] #
end # base - The Class subclass.
#
def inherited(base) # Returns nothing.
def self.inherited(base)
subclasses << base subclasses << base
subclasses.sort! subclasses.sort!
end end
def all # The list of Classes that have been subclassed.
subclasses #
# Returns an Array of Class objects.
def self.subclasses
@subclasses ||= []
end end
# priority order of this converter # Get or set the priority of this converter. When called without an
def priority(priority = nil) # argument it returns the priority. When an argument is given, it will
# set the priority.
#
# priority - The Symbol priority (default: nil). Valid options are:
# :lowest, :low, :normal, :high, :highest
#
# Returns the Symbol priority.
def self.priority(priority = nil)
if priority && PRIORITIES.has_key?(priority) if priority && PRIORITIES.has_key?(priority)
@priority = priority @priority = priority
end end
@ -32,17 +42,21 @@ module Jekyll
# Spaceship is priority [higher -> lower] # Spaceship is priority [higher -> lower]
# #
# Returns -1, 0, 1 # other - The class to be compared.
def <=>(other) #
cmp = PRIORITIES[other.priority] <=> PRIORITIES[self.priority] # Returns -1, 0, 1.
return cmp def self.<=>(other)
end PRIORITIES[other.priority] <=> PRIORITIES[self.priority]
end end
# Initialize a new extension. This should be overridden by the subclass.
#
# config - The Hash of configuration options.
#
# Returns a new instance.
def initialize(config = {}) def initialize(config = {})
#no-op for default # no-op for default
end end
end end
end end

View File

@ -36,11 +36,15 @@ module Jekyll
end end
def setup def setup
# Check to see if LSI is enabled.
require 'classifier' if self.lsi require 'classifier' if self.lsi
self.converters = Jekyll::Converter.all.collect { |c| c.new(self.config) } self.converters = Jekyll::Converter.subclasses.map do |c|
self.generators = Jekyll::Generator.all.collect { |c| c.new(self.config) } c.new(self.config)
end
self.generators = Jekyll::Generator.subclasses.map do |c|
c.new(self.config)
end
end end
# Do the actual work of processing the site and generating the # Do the actual work of processing the site and generating the