Skip to content

Commit

Permalink
Added extended body support and time handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
metajack committed Dec 22, 2008
1 parent c72db0a commit 753bd06
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
39 changes: 31 additions & 8 deletions lib/jekyll/convertible.rb
Expand Up @@ -2,7 +2,11 @@ module Jekyll
module Convertible
# Return the contents as a string
def to_s
self.content || ''
if self.is_a? Jekyll::Post
(self.content || '') + (self.extended || '')
else
self.content || ''
end
end

# Read the YAML frontmatter
Expand All @@ -12,11 +16,18 @@ def to_s
# Returns nothing
def read_yaml(base, name)
self.content = File.read(File.join(base, name))

if self.content =~ /^(---.*\n.*?)\n---.*\n/m
self.content = self.content[($1.size + 5)..-1]


if self.content =~ /^(---.*?\n.*?)\n---.*?\n(.*)/m
self.data = YAML.load($1)
self.content = $2

# if we have an extended section, separate that from content
if self.is_a? Jekyll::Post
if self.data.key? 'extended'
marker = self.data['extended']
self.content, self.extended = self.content.split(marker + "\n", 2)
end
end
end
end

Expand All @@ -28,9 +39,15 @@ def transform
when ".textile":
self.ext = ".html"
self.content = RedCloth.new(self.content).to_html
if self.is_a? Jekyll::Post and self.extended
self.extended = RedCloth.new(self.extended).to_html
end
when ".markdown":
self.ext = ".html"
self.content = Jekyll.markdown_proc.call(self.content)
if self.is_a? Jekyll::Post and self.extended
self.extended = Jekyll.markdown_proc.call(self.extended)
end
end
end

Expand All @@ -43,12 +60,18 @@ def do_layout(payload, layouts, site_payload)
# construct payload
payload = payload.merge(site_payload)
# render content
self.content = Liquid::Template.parse(self.content).render(payload, [Jekyll::Filters])
unless self.is_a? Jekyll::Post
self.content = Liquid::Template.parse(self.content).render(payload, [Jekyll::Filters])
end
self.transform

# output keeps track of what will finally be written
self.output = self.content

if self.is_a? Jekyll::Post and self.extended
self.output = self.content + self.extended
else
self.output = self.content
end

# recursively render layouts
layout = layouts[self.data["layout"]]
while layout
Expand Down
14 changes: 12 additions & 2 deletions lib/jekyll/post.rb
Expand Up @@ -19,7 +19,7 @@ def self.valid?(name)
end

attr_accessor :date, :slug, :ext
attr_accessor :data, :content, :output
attr_accessor :data, :content, :extended, :output

# Initialize this Post instance.
# +base+ is the String path to the source
Expand Down Expand Up @@ -144,11 +144,21 @@ def write(dest)
#
# Returns <Hash>
def to_liquid
if self.data.key? "time"
time = Time.parse self.data["time"]
self.date = Time.mktime(self.date.year,
self.date.month,
self.date.day,
time.hour,
time.min)
end
props = { "title" => self.data["title"] || "",
"url" => self.url,
"date" => self.date,
"id" => self.id,
"content" => self.content }
"content" => self.content,
"extended" => self.extended || ""
}
props.merge(self.data) do |key, old, new|
old
end
Expand Down

0 comments on commit 753bd06

Please sign in to comment.