handle atom feed generation

This commit is contained in:
Tom Preston-Werner 2008-10-20 12:41:43 -07:00
parent 07fe6cd128
commit 4ef3aedb6a
4 changed files with 22 additions and 7 deletions

View File

@ -4,6 +4,14 @@ module AutoBlog
def date_to_string(date)
date.strftime("%d %b %Y")
end
def date_to_xmlschema(date)
date.xmlschema
end
def xml_escape(input)
input.gsub("<", "&lt;").gsub(">", "&gt;")
end
end
end

View File

@ -9,6 +9,8 @@ module AutoBlog
@dir = dir
@name = name
self.data = {}
self.process(name)
self.read_yaml(base, dir, name)
self.set_defaults
@ -40,8 +42,8 @@ module AutoBlog
end
end
def add_layout(layouts, posts)
payload = {"page" => self.data, "site" => {"posts" => posts}}
def add_layout(layouts, site_payload)
payload = {"page" => self.data}.merge(site_payload)
self.content = Liquid::Template.parse(self.content).render(payload, [AutoBlog::Filters])
layout = layouts[self.data["layout"]] || self.content

View File

@ -8,7 +8,7 @@ module AutoBlog
end
attr_accessor :date, :slug, :ext
attr_accessor :data, :content
attr_accessor :data, :content, :output
def initialize(base, name)
@base = base
@ -60,7 +60,7 @@ module AutoBlog
layout = layouts[self.data["layout"]] || self.content
payload = {"content" => self.content, "page" => self.data}
self.content = Liquid::Template.parse(layout).render(payload)
self.output = Liquid::Template.parse(layout).render(payload)
end
def write(dest)
@ -68,14 +68,15 @@ module AutoBlog
path = File.join(dest, self.url)
File.open(path, 'w') do |f|
f.write(self.content)
f.write(self.output)
end
end
def to_liquid
{ "title" => self.data["title"] || "",
"url" => self.url,
"date" => self.date }
"date" => self.date,
"content" => self.content }
end
end

View File

@ -63,11 +63,15 @@ module AutoBlog
transform_pages(File.join(dir, f))
else
page = Page.new(self.source, dir, f)
page.add_layout(self.layouts, self.posts)
page.add_layout(self.layouts, site_payload)
page.write(self.dest)
end
end
end
def site_payload
{"site" => {"time" => Time.now, "posts" => self.posts}}
end
end
end