TomDoc some things.
This commit is contained in:
parent
155cbd1463
commit
a428acec1c
|
@ -3,18 +3,43 @@ require 'uri'
|
||||||
module Jekyll
|
module Jekyll
|
||||||
|
|
||||||
module Filters
|
module Filters
|
||||||
|
# Convert a Textile string into HTML output.
|
||||||
|
#
|
||||||
|
# input - The Textile String to convert.
|
||||||
|
#
|
||||||
|
# Returns the HTML formatted String.
|
||||||
def textilize(input)
|
def textilize(input)
|
||||||
TextileConverter.new.convert(input)
|
TextileConverter.new.convert(input)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Format a date in short format e.g. "27 Jan 2011".
|
||||||
|
#
|
||||||
|
# date - the Time to format.
|
||||||
|
#
|
||||||
|
# Returns the formatting String.
|
||||||
def date_to_string(date)
|
def date_to_string(date)
|
||||||
date.strftime("%d %b %Y")
|
date.strftime("%d %b %Y")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Format a date in long format e.g. "27 January 2011".
|
||||||
|
#
|
||||||
|
# date - The Time to format.
|
||||||
|
#
|
||||||
|
# Returns the formatted String.
|
||||||
def date_to_long_string(date)
|
def date_to_long_string(date)
|
||||||
date.strftime("%d %B %Y")
|
date.strftime("%d %B %Y")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Format a date for use in XML.
|
||||||
|
#
|
||||||
|
# date - The Time to format.
|
||||||
|
#
|
||||||
|
# Examples
|
||||||
|
#
|
||||||
|
# date_to_xmlschema(Time.now)
|
||||||
|
# # => "2011-04-24T20:34:46+08:00"
|
||||||
|
#
|
||||||
|
# Returns the formatted String.
|
||||||
def date_to_xmlschema(date)
|
def date_to_xmlschema(date)
|
||||||
date.xmlschema
|
date.xmlschema
|
||||||
end
|
end
|
||||||
|
@ -23,6 +48,17 @@ module Jekyll
|
||||||
CGI.escapeHTML(input)
|
CGI.escapeHTML(input)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# CGI escape a string for use in a URL. Replaces any special characters
|
||||||
|
# with appropriate %XX replacements.
|
||||||
|
#
|
||||||
|
# input - The String to escape.
|
||||||
|
#
|
||||||
|
# Examples
|
||||||
|
#
|
||||||
|
# cgi_escape('foo,bar;baz?')
|
||||||
|
# # => "foo%2Cbar%3Bbaz%3F"
|
||||||
|
#
|
||||||
|
# Returns the escaped String.
|
||||||
def cgi_escape(input)
|
def cgi_escape(input)
|
||||||
CGI::escape(input)
|
CGI::escape(input)
|
||||||
end
|
end
|
||||||
|
@ -31,10 +67,26 @@ module Jekyll
|
||||||
URI.escape(input)
|
URI.escape(input)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Count the number of words in the input string.
|
||||||
|
#
|
||||||
|
# input - The String on which to operate.
|
||||||
|
#
|
||||||
|
# Returns the Integer word count.
|
||||||
def number_of_words(input)
|
def number_of_words(input)
|
||||||
input.split.length
|
input.split.length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Join an array of things into a string by separating with commes and the
|
||||||
|
# word "and" for the last one.
|
||||||
|
#
|
||||||
|
# array - The Array of Strings to join.
|
||||||
|
#
|
||||||
|
# Examples
|
||||||
|
#
|
||||||
|
# array_to_sentence_string(["apples", "oranges", "grapes"])
|
||||||
|
# # => "apples, oranges, and grapes"
|
||||||
|
#
|
||||||
|
# Returns the formatted String.
|
||||||
def array_to_sentence_string(array)
|
def array_to_sentence_string(array)
|
||||||
connector = "and"
|
connector = "and"
|
||||||
case array.length
|
case array.length
|
||||||
|
|
|
@ -3,16 +3,23 @@ module Jekyll
|
||||||
class Layout
|
class Layout
|
||||||
include Convertible
|
include Convertible
|
||||||
|
|
||||||
attr_accessor :site
|
# Gets the Site object.
|
||||||
|
attr_reader :site
|
||||||
|
|
||||||
|
# Gets/Sets the extension of this layout.
|
||||||
attr_accessor :ext
|
attr_accessor :ext
|
||||||
attr_accessor :data, :content
|
|
||||||
|
# Gets/Sets the Hash that holds the metadata for this layout.
|
||||||
|
attr_accessor :data
|
||||||
|
|
||||||
|
# Gets/Sets the content of this layout.
|
||||||
|
attr_accessor :content
|
||||||
|
|
||||||
# Initialize a new Layout.
|
# Initialize a new Layout.
|
||||||
# +site+ is the Site
|
|
||||||
# +base+ is the String path to the <source>
|
|
||||||
# +name+ is the String filename of the post file
|
|
||||||
#
|
#
|
||||||
# Returns <Page>
|
# site - The Site.
|
||||||
|
# base - The String path to the source.
|
||||||
|
# name - The String filename of the post file.
|
||||||
def initialize(site, base, name)
|
def initialize(site, base, name)
|
||||||
@site = site
|
@site = site
|
||||||
@base = base
|
@base = base
|
||||||
|
@ -24,10 +31,11 @@ module Jekyll
|
||||||
self.read_yaml(base, name)
|
self.read_yaml(base, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Extract information from the layout filename
|
# Extract information from the layout filename.
|
||||||
# +name+ is the String filename of the layout file
|
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# name - The String filename of the layout file.
|
||||||
|
#
|
||||||
|
# Returns nothing.
|
||||||
def process(name)
|
def process(name)
|
||||||
self.ext = File.extname(name)
|
self.ext = File.extname(name)
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,12 +8,11 @@ module Jekyll
|
||||||
attr_accessor :data, :content, :output
|
attr_accessor :data, :content, :output
|
||||||
|
|
||||||
# Initialize a new Page.
|
# Initialize a new Page.
|
||||||
# +site+ is the Site
|
|
||||||
# +base+ is the String path to the <source>
|
|
||||||
# +dir+ is the String path between <source> and the file
|
|
||||||
# +name+ is the String filename of the file
|
|
||||||
#
|
#
|
||||||
# Returns <Page>
|
# site - The Site object.
|
||||||
|
# base - The String path to the source.
|
||||||
|
# dir - The String path between the source and the file.
|
||||||
|
# name - The String filename of the file.
|
||||||
def initialize(site, base, dir, name)
|
def initialize(site, base, dir, name)
|
||||||
@site = site
|
@site = site
|
||||||
@base = base
|
@base = base
|
||||||
|
@ -26,22 +25,24 @@ module Jekyll
|
||||||
|
|
||||||
# The generated directory into which the page will be placed
|
# The generated directory into which the page will be placed
|
||||||
# upon generation. This is derived from the permalink or, if
|
# upon generation. This is derived from the permalink or, if
|
||||||
# permalink is absent, set to '/'
|
# permalink is absent, we be '/'
|
||||||
#
|
#
|
||||||
# Returns <String>
|
# Returns the String destination directory.
|
||||||
def dir
|
def dir
|
||||||
url[-1, 1] == '/' ? url : File.dirname(url)
|
url[-1, 1] == '/' ? url : File.dirname(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The full path and filename of the post.
|
# The full path and filename of the post. Defined in the YAML of the post
|
||||||
# Defined in the YAML of the post body
|
# body.
|
||||||
# (Optional)
|
|
||||||
#
|
#
|
||||||
# Returns <String>
|
# Returns the String permalink or nil if none has been set.
|
||||||
def permalink
|
def permalink
|
||||||
self.data && self.data['permalink']
|
self.data && self.data['permalink']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The template of the permalink.
|
||||||
|
#
|
||||||
|
# Returns the template String.
|
||||||
def template
|
def template
|
||||||
if self.site.permalink_style == :pretty && !index? && html?
|
if self.site.permalink_style == :pretty && !index? && html?
|
||||||
"/:basename/"
|
"/:basename/"
|
||||||
|
@ -50,10 +51,9 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The generated relative url of this page
|
# The generated relative url of this page. e.g. /about.html.
|
||||||
# e.g. /about.html
|
|
||||||
#
|
#
|
||||||
# Returns <String>
|
# Returns the String url.
|
||||||
def url
|
def url
|
||||||
return @url if @url
|
return @url if @url
|
||||||
|
|
||||||
|
@ -74,20 +74,22 @@ module Jekyll
|
||||||
@url
|
@url
|
||||||
end
|
end
|
||||||
|
|
||||||
# Extract information from the page filename
|
# Extract information from the page filename.
|
||||||
# +name+ is the String filename of the page file
|
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# name - The String filename of the page file.
|
||||||
|
#
|
||||||
|
# Returns nothing.
|
||||||
def process(name)
|
def process(name)
|
||||||
self.ext = File.extname(name)
|
self.ext = File.extname(name)
|
||||||
self.basename = name[0 .. -self.ext.length-1]
|
self.basename = name[0 .. -self.ext.length-1]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add any necessary layouts to this post
|
# Add any necessary layouts to this post
|
||||||
# +layouts+ is a Hash of {"name" => "layout"}
|
|
||||||
# +site_payload+ is the site payload hash
|
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# layouts - The Hash of {"name" => "layout"}.
|
||||||
|
# site_payload - The site payload Hash.
|
||||||
|
#
|
||||||
|
# Returns nothing.
|
||||||
def render(layouts, site_payload)
|
def render(layouts, site_payload)
|
||||||
payload = {
|
payload = {
|
||||||
"page" => self.to_liquid,
|
"page" => self.to_liquid,
|
||||||
|
@ -97,6 +99,9 @@ module Jekyll
|
||||||
do_layout(payload, layouts)
|
do_layout(payload, layouts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Convert this Page's data to a Hash suitable for use by Liquid.
|
||||||
|
#
|
||||||
|
# Returns the Hash representation of this Page.
|
||||||
def to_liquid
|
def to_liquid
|
||||||
self.data.deep_merge({
|
self.data.deep_merge({
|
||||||
"url" => File.join(@dir, self.url),
|
"url" => File.join(@dir, self.url),
|
||||||
|
@ -104,20 +109,23 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
# Obtain destination path.
|
# Obtain destination path.
|
||||||
# +dest+ is the String path to the destination dir
|
|
||||||
#
|
#
|
||||||
# Returns destination file path.
|
# dest - The String path to the destination dir.
|
||||||
|
#
|
||||||
|
# Returns the destination file path String.
|
||||||
def destination(dest)
|
def destination(dest)
|
||||||
# The url needs to be unescaped in order to preserve the correct filename
|
# The url needs to be unescaped in order to preserve the correct
|
||||||
|
# filename.
|
||||||
path = File.join(dest, @dir, CGI.unescape(self.url))
|
path = File.join(dest, @dir, CGI.unescape(self.url))
|
||||||
path = File.join(path, "index.html") if self.url =~ /\/$/
|
path = File.join(path, "index.html") if self.url =~ /\/$/
|
||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
# Write the generated page file to the destination directory.
|
# Write the generated page file to the destination directory.
|
||||||
# +dest+ is the String path to the destination dir
|
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# dest - The String path to the destination dir.
|
||||||
|
#
|
||||||
|
# Returns nothing.
|
||||||
def write(dest)
|
def write(dest)
|
||||||
path = destination(dest)
|
path = destination(dest)
|
||||||
FileUtils.mkdir_p(File.dirname(path))
|
FileUtils.mkdir_p(File.dirname(path))
|
||||||
|
@ -126,14 +134,17 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the object as a debug String.
|
||||||
def inspect
|
def inspect
|
||||||
"#<Jekyll:Page @name=#{self.name.inspect}>"
|
"#<Jekyll:Page @name=#{self.name.inspect}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the Boolean of whether this Page is HTML or not.
|
||||||
def html?
|
def html?
|
||||||
output_ext == '.html'
|
output_ext == '.html'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the Boolean of whether this Page is an index file or not.
|
||||||
def index?
|
def index?
|
||||||
basename == 'index'
|
basename == 'index'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue