write posts to disk
This commit is contained in:
parent
84b00cc63e
commit
1c93bd0ce8
|
@ -26,8 +26,12 @@ module AutoBlog
|
||||||
self.ext = ext
|
self.ext = ext
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dir
|
||||||
|
self.date.strftime("/%Y/%m/%d/")
|
||||||
|
end
|
||||||
|
|
||||||
def url
|
def url
|
||||||
self.date.strftime("/%Y/%m/%d/") + self.slug
|
self.dir + self.slug + ".html"
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_yaml(base, name)
|
def read_yaml(base, name)
|
||||||
|
@ -53,6 +57,15 @@ module AutoBlog
|
||||||
|
|
||||||
self.content = Liquid::Template.parse(layout).render(payload)
|
self.content = Liquid::Template.parse(layout).render(payload)
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
|
@ -14,6 +14,7 @@ module AutoBlog
|
||||||
def process
|
def process
|
||||||
self.read_layouts
|
self.read_layouts
|
||||||
self.read_posts
|
self.read_posts
|
||||||
|
self.write_posts
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_layouts
|
def read_layouts
|
||||||
|
@ -46,6 +47,7 @@ module AutoBlog
|
||||||
def write_posts
|
def write_posts
|
||||||
self.posts.each do |post|
|
self.posts.each do |post|
|
||||||
post.add_layout(self.layouts)
|
post.add_layout(self.layouts)
|
||||||
|
post.write
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,4 +41,14 @@ class TestPost < Test::Unit::TestCase
|
||||||
|
|
||||||
assert_equal "<<< \nh1. Foo Bar\n\nBest post ever >>>", p.content
|
assert_equal "<<< \nh1. Foo Bar\n\nBest post ever >>>", p.content
|
||||||
end
|
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
|
end
|
|
@ -21,4 +21,10 @@ class TestSite < Test::Unit::TestCase
|
||||||
|
|
||||||
assert_equal 1, @s.posts.size
|
assert_equal 1, @s.posts.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_write_posts
|
||||||
|
@s.process
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue