From 7fd8fd2b14f3ef1f6624c3d2538d89253cf1c20e Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Sun, 19 Oct 2008 22:10:03 -0700 Subject: [PATCH] textilize posts --- .gitignore | 1 + lib/autoblog.rb | 1 + lib/autoblog/post.rb | 5 +++++ test/test_post.rb | 14 +++++++++++--- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..01535905 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +test/dest/ diff --git a/lib/autoblog.rb b/lib/autoblog.rb index 45b20461..cea9bf05 100644 --- a/lib/autoblog.rb +++ b/lib/autoblog.rb @@ -11,6 +11,7 @@ require 'time' # 3rd party require 'liquid' +require 'redcloth' # internal requires require 'autoblog/site' diff --git a/lib/autoblog/post.rb b/lib/autoblog/post.rb index 445d2dfe..3ebfebc2 100644 --- a/lib/autoblog/post.rb +++ b/lib/autoblog/post.rb @@ -17,6 +17,7 @@ module AutoBlog self.process(name) self.read_yaml(base, name) self.set_defaults + self.transform end def process(name) @@ -48,6 +49,10 @@ module AutoBlog self.data["layout"] ||= "default" end + def transform + self.content = RedCloth.new(self.content).to_html + end + def add_layout(layouts) payload = {"page" => self.data} self.content = Liquid::Template.parse(self.content).render(payload) diff --git a/test/test_post.rb b/test/test_post.rb index 04b65a26..2d1378da 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -23,7 +23,7 @@ class TestPost < Test::Unit::TestCase p = Post.allocate p.process("2008-10-19-foo-bar.textile") - assert_equal "/2008/10/19/foo-bar", p.url + assert_equal "/2008/10/19/foo-bar.html", p.url end def test_read_yaml @@ -31,7 +31,15 @@ class TestPost < Test::Unit::TestCase p.read_yaml(File.join(File.dirname(__FILE__), *%w[source posts]), "2008-10-18-foo-bar.textile") assert_equal({"title" => "Foo Bar"}, p.data) - assert_equal "\nh1. {{ page.title }}\n\nBest post ever", p.content + assert_equal "\nh1. {{ page.title }}\n\nBest *post* ever", p.content + end + + def test_transform + p = Post.allocate + p.read_yaml(File.join(File.dirname(__FILE__), *%w[source posts]), "2008-10-18-foo-bar.textile") + p.transform + + assert_equal "

{{ page.title }}

\n\n\n\t

Best post ever

", p.content end def test_add_layout @@ -39,7 +47,7 @@ class TestPost < Test::Unit::TestCase layouts = {"default" => "<<< {{ content }} >>>"} p.add_layout(layouts) - assert_equal "<<< \nh1. Foo Bar\n\nBest post ever >>>", p.content + assert_equal "<<<

Foo Bar

\n\n\n\t

Best post ever

>>>", p.content end def test_write