textilize posts
This commit is contained in:
parent
1c93bd0ce8
commit
7fd8fd2b14
|
@ -0,0 +1 @@
|
||||||
|
test/dest/
|
|
@ -11,6 +11,7 @@ require 'time'
|
||||||
|
|
||||||
# 3rd party
|
# 3rd party
|
||||||
require 'liquid'
|
require 'liquid'
|
||||||
|
require 'redcloth'
|
||||||
|
|
||||||
# internal requires
|
# internal requires
|
||||||
require 'autoblog/site'
|
require 'autoblog/site'
|
||||||
|
|
|
@ -17,6 +17,7 @@ module AutoBlog
|
||||||
self.process(name)
|
self.process(name)
|
||||||
self.read_yaml(base, name)
|
self.read_yaml(base, name)
|
||||||
self.set_defaults
|
self.set_defaults
|
||||||
|
self.transform
|
||||||
end
|
end
|
||||||
|
|
||||||
def process(name)
|
def process(name)
|
||||||
|
@ -48,6 +49,10 @@ module AutoBlog
|
||||||
self.data["layout"] ||= "default"
|
self.data["layout"] ||= "default"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def transform
|
||||||
|
self.content = RedCloth.new(self.content).to_html
|
||||||
|
end
|
||||||
|
|
||||||
def add_layout(layouts)
|
def add_layout(layouts)
|
||||||
payload = {"page" => self.data}
|
payload = {"page" => self.data}
|
||||||
self.content = Liquid::Template.parse(self.content).render(payload)
|
self.content = Liquid::Template.parse(self.content).render(payload)
|
||||||
|
|
|
@ -23,7 +23,7 @@ class TestPost < Test::Unit::TestCase
|
||||||
p = Post.allocate
|
p = Post.allocate
|
||||||
p.process("2008-10-19-foo-bar.textile")
|
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
|
end
|
||||||
|
|
||||||
def test_read_yaml
|
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")
|
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({"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 "<h1>{{ page.title }}</h1>\n\n\n\t<p>Best <strong>post</strong> ever</p>", p.content
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_add_layout
|
def test_add_layout
|
||||||
|
@ -39,7 +47,7 @@ class TestPost < Test::Unit::TestCase
|
||||||
layouts = {"default" => "<<< {{ content }} >>>"}
|
layouts = {"default" => "<<< {{ content }} >>>"}
|
||||||
p.add_layout(layouts)
|
p.add_layout(layouts)
|
||||||
|
|
||||||
assert_equal "<<< \nh1. Foo Bar\n\nBest post ever >>>", p.content
|
assert_equal "<<< <h1>Foo Bar</h1>\n\n\n\t<p>Best <strong>post</strong> ever</p> >>>", p.content
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_write
|
def test_write
|
||||||
|
|
Loading…
Reference in New Issue