Added the ability to configure the file extensions to be processed by each converter. Test cases included.

This commit is contained in:
Derek Prior 2011-04-12 17:03:28 -04:00
parent b3634b522a
commit 5801220a98
7 changed files with 58 additions and 5 deletions

View File

@ -64,6 +64,9 @@ module Jekyll
'pygments' => false, 'pygments' => false,
'markdown' => 'maruku', 'markdown' => 'maruku',
'permalink' => 'date', 'permalink' => 'date',
'markdown_ext' => 'markdown,mdw,mdwn,md',
'textile_ext' => 'textile',
'maruku' => { 'maruku' => {
'use_tex' => false, 'use_tex' => false,

View File

@ -65,9 +65,10 @@ module Jekyll
end end
@setup = true @setup = true
end end
def matches(ext) def matches(ext)
ext =~ /(markdown|mkdn?|md)/i rgx = '(' + @config['markdown_ext'].gsub(',','|') +')'
ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
end end
def output_ext(ext) def output_ext(ext)

View File

@ -17,7 +17,8 @@ module Jekyll
end end
def matches(ext) def matches(ext)
ext =~ /textile/i rgx = '(' + @config['textile_ext'].gsub(',','|') +')'
ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
end end
def output_ext(ext) def output_ext(ext)

View File

@ -0,0 +1,7 @@
---
date: 2011-04-12 13:07:09
---
under default configuration, this post should get processed by the identity converter. By changing
textile extension or markdown extension configuration parameters, you should be able to associate
it with either of those converters

View File

@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase
end end
should "ensure post count is as expected" do should "ensure post count is as expected" do
assert_equal 26, @site.posts.size assert_equal 28, @site.posts.size
end end
should "insert site.posts into the index" do should "insert site.posts into the index" do

View File

@ -391,6 +391,47 @@ class TestPost < Test::Unit::TestCase
post = Post.new(@site, File.join(File.dirname(__FILE__), *%w[source]), 'foo', 'bar/2008-12-12-topical-post.textile') post = Post.new(@site, File.join(File.dirname(__FILE__), *%w[source]), 'foo', 'bar/2008-12-12-topical-post.textile')
assert_equal ['foo'], post.categories assert_equal ['foo'], post.categories
end end
end end
context "converter file extension settings" do
setup do
stub(Jekyll).configuration { Jekyll::DEFAULTS }
@site = Site.new(Jekyll.configuration)
end
should "process .md as markdown under default configuration" do
post = setup_post '2011-04-12-md-extension.md'
conv = post.converter
assert conv.kind_of? Jekyll::MarkdownConverter
end
should "process .text as indentity under default configuration" do
post = setup_post '2011-04-12-text-extension.text'
conv = post.converter
assert conv.kind_of? Jekyll::IdentityConverter
end
should "process .text as markdown under alternate configuration" do
@site.config['markdown_ext'] = 'markdown,mdw,mdwn,md,text'
post = setup_post '2011-04-12-text-extension.text'
conv = post.converter
assert conv.kind_of? Jekyll::MarkdownConverter
end
should "process .md as markdown under alternate configuration" do
@site.config['markdown_ext'] = 'markdown,mdw,mdwn,md,text'
post = setup_post '2011-04-12-text-extension.text'
conv = post.converter
assert conv.kind_of? Jekyll::MarkdownConverter
end
should "process .text as textile under alternate configuration" do
@site.config['textile_ext'] = 'textile,text'
post = setup_post '2011-04-12-text-extension.text'
conv = post.converter
assert conv.kind_of? Jekyll::TextileConverter
end
end
end end