TomDoc convertible.rb.

This commit is contained in:
Tom Preston-Werner 2011-03-11 16:00:32 -08:00
parent 68eaadd13a
commit 6c94db1486
1 changed files with 20 additions and 15 deletions

View File

@ -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,29 +39,33 @@ 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 } }