write posts to disk
This commit is contained in:
parent
84b00cc63e
commit
1c93bd0ce8
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -21,4 +21,10 @@ class TestSite < Test::Unit::TestCase
|
|||
|
||||
assert_equal 1, @s.posts.size
|
||||
end
|
||||
|
||||
def test_write_posts
|
||||
@s.process
|
||||
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue