Merge pull request #1397 from IQAndreas/cleanup-date
Call overridden version of `to_liquid` and remove duplicate code in `Octopress::Date`
This commit is contained in:
commit
64ba603225
@ -41,6 +41,15 @@ module Octopress
|
|||||||
end
|
end
|
||||||
date_formatted
|
date_formatted
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the date-specific liquid attributes
|
||||||
|
def liquid_date_attributes
|
||||||
|
date_format = self.site.config['date_format']
|
||||||
|
date_attributes = {}
|
||||||
|
date_attributes['date_formatted'] = format_date(self.data['date'], date_format) if self.data.has_key?('date')
|
||||||
|
date_attributes['updated_formatted'] = format_date(self.data['updated'], date_format) if self.data.has_key?('updated')
|
||||||
|
date_attributes
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -51,48 +60,22 @@ module Jekyll
|
|||||||
class Post
|
class Post
|
||||||
include Octopress::Date
|
include Octopress::Date
|
||||||
|
|
||||||
# Convert this post into a Hash for use in Liquid templates.
|
# Convert this Convertible's data to a Hash suitable for use by Liquid.
|
||||||
#
|
# Overrides the default return data and adds any date-specific liquid attributes
|
||||||
# Returns <Hash>
|
alias :super_to_liquid :to_liquid
|
||||||
def to_liquid
|
def to_liquid
|
||||||
date_format = self.site.config['date_format']
|
super_to_liquid.deep_merge(liquid_date_attributes)
|
||||||
self.data.deep_merge({
|
|
||||||
"title" => self.data['title'] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '),
|
|
||||||
"url" => self.url,
|
|
||||||
"date" => self.date,
|
|
||||||
# Monkey patch
|
|
||||||
"date_formatted" => format_date(self.date, date_format),
|
|
||||||
"updated_formatted" => self.data.has_key?('updated') ? format_date(self.data['updated'], date_format) : nil,
|
|
||||||
"id" => self.id,
|
|
||||||
"categories" => self.categories,
|
|
||||||
"next" => self.next,
|
|
||||||
"previous" => self.previous,
|
|
||||||
"tags" => self.tags,
|
|
||||||
"content" => self.content })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Page
|
class Page
|
||||||
include Octopress::Date
|
include Octopress::Date
|
||||||
|
|
||||||
# Initialize a new Page.
|
# Convert this Convertible's data to a Hash suitable for use by Liquid.
|
||||||
#
|
# Overrides the default return data and adds any date-specific liquid attributes
|
||||||
# site - The Site object.
|
alias :super_to_liquid :to_liquid
|
||||||
# base - The String path to the source.
|
def to_liquid
|
||||||
# dir - The String path between the source and the file.
|
super_to_liquid.deep_merge(liquid_date_attributes)
|
||||||
# name - The String filename of the file.
|
|
||||||
def initialize(site, base, dir, name)
|
|
||||||
@site = site
|
|
||||||
@base = base
|
|
||||||
@dir = dir
|
|
||||||
@name = name
|
|
||||||
|
|
||||||
self.process(name)
|
|
||||||
self.read_yaml(File.join(base, dir), name)
|
|
||||||
# Monkey patch
|
|
||||||
date_format = self.site.config['date_format']
|
|
||||||
self.data['date_formatted'] = format_date(self.data['date'], date_format) if self.data.has_key?('date')
|
|
||||||
self.data['updated_formatted'] = format_date(self.data['updated'], date_format) if self.data.has_key?('updated')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user