diff --git a/lib/autoblog/post.rb b/lib/autoblog/post.rb index 9c5cbcd3..445d2dfe 100644 --- a/lib/autoblog/post.rb +++ b/lib/autoblog/post.rb @@ -26,8 +26,12 @@ module AutoBlog self.ext = ext end + def dir + self.date.strftime("/%Y/%m/%d/") + end + def url - self.date.strftime("/%Y/%m/%d/") + self.slug + self.dir + self.slug + ".html" end def read_yaml(base, name) @@ -53,6 +57,15 @@ module AutoBlog self.content = Liquid::Template.parse(layout).render(payload) end + + def write(dest) + FileUtils.mkdir_p(File.join(dest, self.dir)) + + path = File.join(dest, self.url) + File.open(path, 'w') do |f| + f.write(self.content) + end + end end end \ No newline at end of file diff --git a/lib/autoblog/site.rb b/lib/autoblog/site.rb index 59bda4c7..e03207f8 100644 --- a/lib/autoblog/site.rb +++ b/lib/autoblog/site.rb @@ -14,6 +14,7 @@ module AutoBlog def process self.read_layouts self.read_posts + self.write_posts end def read_layouts @@ -46,6 +47,7 @@ module AutoBlog def write_posts self.posts.each do |post| post.add_layout(self.layouts) + post.write end end end diff --git a/test/test_post.rb b/test/test_post.rb index 8b89c64f..04b65a26 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -41,4 +41,14 @@ class TestPost < Test::Unit::TestCase assert_equal "<<< \nh1. Foo Bar\n\nBest post ever >>>", p.content end + + def test_write + dest = File.join(File.dirname(__FILE__), *%w[dest]) + FileUtils.rm_rf(dest) + + p = Post.new(File.join(File.dirname(__FILE__), *%w[source posts]), "2008-10-18-foo-bar.textile") + layouts = {"default" => "<<< {{ content }} >>>"} + p.add_layout(layouts) + p.write(dest) + end end \ No newline at end of file diff --git a/test/test_site.rb b/test/test_site.rb index 119317ea..27faa2df 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -21,4 +21,10 @@ class TestSite < Test::Unit::TestCase assert_equal 1, @s.posts.size end + + def test_write_posts + @s.process + + + end end \ No newline at end of file