simplify some code with Hash#fetch

This commit is contained in:
maul.esel 2013-07-22 16:02:42 +02:00
parent 9e22d23801
commit f0e2468249
2 changed files with 4 additions and 8 deletions

View File

@ -118,7 +118,7 @@ module Jekyll
self.data.deep_merge({ self.data.deep_merge({
"url" => self.url, "url" => self.url,
"content" => self.content, "content" => self.content,
"path" => self.data['path'] || path }) "path" => self.data.fetch('path', path) })
end end
# The path to the source file # The path to the source file

View File

@ -106,18 +106,14 @@ module Jekyll
# #
# Returns excerpt string. # Returns excerpt string.
def excerpt def excerpt
if self.data.has_key? 'excerpt' self.data.fetch('excerpt', self.extracted_excerpt.to_s)
self.data['excerpt']
else
self.extracted_excerpt.to_s
end
end end
# Public: the Post title, from the YAML Front-Matter or from the slug # Public: the Post title, from the YAML Front-Matter or from the slug
# #
# Returns the post title # Returns the post title
def title def title
self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' ') self.data.fetch("title", self.slug.split('-').select {|w| w.capitalize! || w }.join(' '))
end end
# Public: the path to the post relative to the site source, # Public: the path to the post relative to the site source,
@ -127,7 +123,7 @@ module Jekyll
# #
# Returns the path to the file relative to the site source # Returns the path to the file relative to the site source
def path def path
self.data['path'] || File.join(@dir, '_posts', @name).sub(/\A\//, '') self.data.fetch('path', File.join(@dir, '_posts', @name).sub(/\A\//, ''))
end end
# Compares Post objects. First compares the Post date. If the dates are # Compares Post objects. First compares the Post date. If the dates are