Rebased with mojombo. All tests pass. Some conflicts with Liquid and Maruku

This commit is contained in:
mreid 2009-03-12 21:25:34 +11:00
parent 4b39c44664
commit cb13ea3000
6 changed files with 37 additions and 29 deletions

View File

@ -24,24 +24,28 @@ module Jekyll
# #
# Returns nothing # Returns nothing
def transform def transform
case Jekyll.content_type case self.content_type
when :textile when 'textile'
self.ext = ".html" self.ext = ".html"
self.content = Jekyll.textile(self.content) self.content = Jekyll.textile(self.content)
when :markdown when 'markdown'
self.ext = ".html" self.ext = ".html"
self.content = Jekyll.markdown(self.content) self.content = Jekyll.markdown(self.content)
end end
end end
def determine_content_type # Determine which formatting engine to use based on this convertible's
# extension
#
# Returns one of :textile, :markdown or :unknown
def content_type
case self.ext[1..-1] case self.ext[1..-1]
when /textile/i when /textile/i
return :textile return 'textile'
when /markdown/i, /mkdn/i, /md/i when /markdown/i, /mkdn/i, /md/i
return :markdown return 'markdown'
end end
return :unknown return 'unknown'
end end
# Add any necessary layouts to this convertible document # Add any necessary layouts to this convertible document
@ -51,7 +55,7 @@ module Jekyll
# Returns nothing # Returns nothing
def do_layout(payload, layouts) def do_layout(payload, layouts)
# render and transform content (this becomes the final content of the object) # render and transform content (this becomes the final content of the object)
Jekyll.content_type = self.determine_content_type payload["content_type"] = self.content_type
self.content = Liquid::Template.parse(self.content).render(payload, [Jekyll::Filters]) self.content = Liquid::Template.parse(self.content).render(payload, [Jekyll::Filters])
self.transform self.transform

View File

@ -29,10 +29,12 @@ module Jekyll
end end
def render_pygments(context, code) def render_pygments(context, code)
if Jekyll.content_type == :markdown if context["content_type"] == :markdown
return "\n" + Albino.new(code, @lang).to_s(@options) + "\n" return "\n" + Albino.new(code, @lang).to_s(@options) + "\n"
elsif content["content_type"] == :textile
return "<notextile>" + Albino.new(code, @lang).to_s(@options) + "</notextile>"
else else
"<notextile>" + Albino.new(code, @lang).to_s(@options) + "</notextile>" return Albino.new(code, @lang).to_s(@options)
end end
end end

View File

@ -3,11 +3,11 @@ require File.dirname(__FILE__) + '/helper'
class TestGeneratedSite < Test::Unit::TestCase class TestGeneratedSite < Test::Unit::TestCase
def setup def setup
clear_dest clear_dest
config = Jekyll::DEFAULTS.clone @config = Jekyll::DEFAULTS.clone
config['source'] = File.join(File.dirname(__FILE__), *%w[source]) @config['source'] = File.join(File.dirname(__FILE__), *%w[source])
config['destination'] = dest_dir @config['destination'] = dest_dir
Jekyll.configure(config) Jekyll.configure(@config)
@s = Site.new(config) @s = Site.new(@config)
@s.process @s.process
@index = File.read(File.join(dest_dir, 'index.html')) @index = File.read(File.join(dest_dir, 'index.html'))
end end
@ -19,9 +19,8 @@ class TestGeneratedSite < Test::Unit::TestCase
def test_post_content_in_index def test_post_content_in_index
# confirm that the {{ post.content }} is rendered OK # confirm that the {{ post.content }} is rendered OK
latest_post = Dir[File.join(@source, '_posts/*')].last latest_post = Dir[File.join(@config['source'], '_posts/*')].last
post = Post.new(@source, '', File.basename(latest_post)) post = Post.new(@config['source'], '', File.basename(latest_post))
Jekyll.content_type = post.determine_content_type
post.transform post.transform
assert @index.include?(post.content) assert @index.include?(post.content)
end end

View File

@ -131,7 +131,10 @@ class TestPost < Test::Unit::TestCase
end end
def test_include def test_include
Jekyll.source = File.join(File.dirname(__FILE__), *%w[source]) config = Jekyll::DEFAULTS.clone
config['source'] = File.join(File.dirname(__FILE__), *%w[source])
Jekyll.configure(config)
p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-12-13-include.markdown") p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-12-13-include.markdown")
layouts = {"default" => Layout.new(File.join(File.dirname(__FILE__), *%w[source _layouts]), "simple.html")} layouts = {"default" => Layout.new(File.join(File.dirname(__FILE__), *%w[source _layouts]), "simple.html")}
p.render(layouts, {"site" => {"posts" => []}}) p.render(layouts, {"site" => {"posts" => []}})

View File

@ -2,11 +2,11 @@ require File.dirname(__FILE__) + '/helper'
class TestSite < Test::Unit::TestCase class TestSite < Test::Unit::TestCase
def setup def setup
config = { @config = Jekyll::DEFAULTS.clone
'source' => File.join(File.dirname(__FILE__), *%w[source]), @config['source'] = File.join(File.dirname(__FILE__), *%w[source])
'destination' => dest_dir @config['destination'] = dest_dir
} Jekyll.configure(@config)
@s = Site.new(config) @s = Site.new(@config)
end end
def test_site_init def test_site_init
@ -21,7 +21,7 @@ class TestSite < Test::Unit::TestCase
def test_read_posts def test_read_posts
@s.read_posts('') @s.read_posts('')
posts = Dir[File.join(@source, '_posts/*')] posts = Dir[File.join(@config['source'], '_posts/*')]
assert_equal posts.size - 1, @s.posts.size assert_equal posts.size - 1, @s.posts.size
end end
@ -29,7 +29,7 @@ class TestSite < Test::Unit::TestCase
clear_dest clear_dest
@s.process @s.process
posts = Dir[File.join(@source, "**", "_posts/*")] posts = Dir[File.join(@config['source'], "**", "_posts/*")]
categories = %w(bar baz category foo z_category publish_test).sort categories = %w(bar baz category foo z_category publish_test).sort
assert_equal posts.size - 1, @s.posts.size assert_equal posts.size - 1, @s.posts.size

View File

@ -21,10 +21,10 @@ CONTENT
def test_markdown_with_pygments_line_handling def test_markdown_with_pygments_line_handling
Jekyll.pygments = true Jekyll.pygments = true
Jekyll.content_type = :markdown context = {"content_type" => 'markdown'}
result = Liquid::Template.parse(@content).render({}, [Jekyll::Filters]) result = Liquid::Template.parse(@content).render(context, [Jekyll::Filters])
result = Jekyll.markdown_proc.call(result) result = Jekyll.markdown(result)
assert_no_match(/markdown\-html\-error/,result) assert_no_match(/markdown\-html\-error/,result)
end end