Merge branch 'steal-envygeeks-custom-markdown-processors' of git://github.com/gjtorikian/jekyll into gjtorikian-steal-envygeeks-custom-markdown-processors

* 'steal-envygeeks-custom-markdown-processors' of git://github.com/gjtorikian/jekyll:
  Depend on Jekyll.logger.error, not $stderr
  Allow custom Markdown processors.
  New is implied by `raise`, 2nd is the message.
  Use $stderr, not STDERR, $stderr points to STDERR.
This commit is contained in:
Parker Moore 2013-12-25 23:52:50 -05:00
commit c70350e275
2 changed files with 61 additions and 13 deletions

View File

@ -8,19 +8,21 @@ module Jekyll
def setup def setup
return if @setup return if @setup
@parser = case @config['markdown'] @parser =
when 'redcarpet' case @config['markdown']
RedcarpetParser.new @config when 'redcarpet' then RedcarpetParser.new(@config)
when 'kramdown' when 'kramdown' then KramdownParser.new(@config)
KramdownParser.new @config when 'rdiscount' then RDiscountParser.new(@config)
when 'rdiscount' when 'maruku' then MarukuParser.new(@config)
RDiscountParser.new @config
when 'maruku'
MarukuParser.new @config
else else
STDERR.puts "Invalid Markdown processor: #{@config['markdown']}" # So they can't try some tricky bullshit or go down the ancestor chain, I hope.
STDERR.puts " Valid options are [ maruku | rdiscount | kramdown | redcarpet ]" if @config['markdown'] !~ /[^A-Za-z0-9]/ && self.class.constants.include?(@config['markdown'].to_sym)
raise FatalException.new("Invalid Markdown process: #{@config['markdown']}") self.class.const_get(@config['markdown']).new(@config)
else
Jekyll.logger.error "Invalid Markdown Processor:", "#{@config['markdown']}"
Jekyll.logger.error "", "Valid options are [ maruku | rdiscount | kramdown | redcarpet ]"
raise FatalException, "Invalid Markdown process: #{@config['markdown']}"
end
end end
@setup = true @setup = true
end end

View File

@ -262,6 +262,52 @@ class TestSite < Test::Unit::TestCase
end end
end end
context 'using a non-default markdown processor in the configuration' do
should 'use the non-default markdown processor' do
class Jekyll::Converters::Markdown::CustomMarkdown
def initialize(*args)
@args = args
end
def convert(*args)
""
end
end
custom_processor = "CustomMarkdown"
s = Site.new(Jekyll.configuration.merge({ 'markdown' => custom_processor }))
assert_nothing_raised do
s.process
end
# Do some cleanup, we don't like straggling stuff's.
Jekyll::Converters::Markdown.send(:remove_const, :CustomMarkdown)
end
should 'ignore, if there are any bad characters in the class name' do
module Jekyll::Converters::Markdown::Custom
class Markdown
def initialize(*args)
@args = args
end
def convert(*args)
""
end
end
end
bad_processor = "Custom::Markdown"
s = Site.new(Jekyll.configuration.merge({ 'markdown' => bad_processor }))
assert_raise Jekyll::FatalException do
s.process
end
# Do some cleanup, we don't like straggling stuff's.
Jekyll::Converters::Markdown.send(:remove_const, :Custom)
end
end
context 'with an invalid markdown processor in the configuration' do context 'with an invalid markdown processor in the configuration' do
should 'not throw an error at initialization time' do should 'not throw an error at initialization time' do
bad_processor = 'not a processor name' bad_processor = 'not a processor name'