From 6c94db1486fa3205027b3aa387dad6588e740cde Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Fri, 11 Mar 2011 16:00:32 -0800 Subject: [PATCH] TomDoc convertible.rb. --- lib/jekyll/convertible.rb | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index cee04b6e..1723fa0d 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -10,16 +10,17 @@ # self.output= module Jekyll module Convertible - # Return the contents as a string + # Returns the contents as a String. def to_s self.content || '' end - # Read the YAML frontmatter - # +base+ is the String path to the dir containing the file - # +name+ is the String filename of the file + # Read the YAML frontmatter. # - # Returns nothing + # base - The String path to the dir containing the file. + # name - The String filename of the file. + # + # Returns nothing. def read_yaml(base, name) self.content = File.read(File.join(base, name)) @@ -38,42 +39,46 @@ module Jekyll # Transform the contents based on the content type. # - # Returns nothing + # Returns nothing. def transform self.content = converter.convert(self.content) end - # Determine the extension depending on content_type + # Determine the extension depending on content_type. # - # Returns the extensions for the output file + # Returns the String extension for the output file. + # e.g. ".html" for an HTML output file. def output_ext converter.output_ext(self.ext) end # Determine which converter to use based on this convertible's - # extension + # extension. + # + # Returns the Converter instance. def converter @converter ||= self.site.converters.find { |c| c.matches(self.ext) } end - # Add any necessary layouts to this convertible document - # +layouts+ is a Hash of {"name" => "layout"} - # +site_payload+ is the site payload hash + # Add any necessary layouts to this convertible document. # - # Returns nothing + # payload - The site payload Hash. + # layouts - A Hash of {"name" => "layout"}. + # + # Returns nothing. def do_layout(payload, layouts) info = { :filters => [Jekyll::Filters], :registers => { :site => self.site } } # render and transform content (this becomes the final content of the object) payload["pygments_prefix"] = converter.pygments_prefix payload["pygments_suffix"] = converter.pygments_suffix - + begin self.content = Liquid::Template.parse(self.content).render(payload, info) rescue => e puts "Liquid Exception: #{e.message} in #{self.data["layout"]}" end - + self.transform # output keeps track of what will finally be written