diff options
author | Parker Moore <parkrmoore@gmail.com> | 2013-11-18 09:38:47 -0800 |
---|---|---|
committer | Parker Moore <parkrmoore@gmail.com> | 2013-11-18 09:38:47 -0800 |
commit | 64ba60322571d0735a3220cdf8dba657703f64da (patch) | |
tree | f7b4c8aa8587a52fb0f8cd0b756ce48a5c8fa322 /plugins/date.rb | |
parent | 1230e018843ec3bcb17dc4297f2b0f47693a7608 (diff) | |
parent | 408cade21f44e922819871f02aa8bbc781f97ffc (diff) | |
download | my_new_personal_website-64ba60322571d0735a3220cdf8dba657703f64da.tar.xz my_new_personal_website-64ba60322571d0735a3220cdf8dba657703f64da.zip |
Merge pull request #1397 from IQAndreas/cleanup-date
Call overridden version of `to_liquid` and remove duplicate code in `Octopress::Date`
Diffstat (limited to '')
-rw-r--r-- | plugins/date.rb | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/plugins/date.rb b/plugins/date.rb index 49fb79a3..01d94737 100644 --- a/plugins/date.rb +++ b/plugins/date.rb @@ -41,6 +41,15 @@ module Octopress end date_formatted 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 @@ -51,48 +60,22 @@ module Jekyll class Post include Octopress::Date - # Convert this post into a Hash for use in Liquid templates. - # - # Returns <Hash> + # 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 + alias :super_to_liquid :to_liquid def to_liquid - date_format = self.site.config['date_format'] - 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 }) + super_to_liquid.deep_merge(liquid_date_attributes) end end class Page include Octopress::Date - # Initialize a new 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) - @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') + # 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 + alias :super_to_liquid :to_liquid + def to_liquid + super_to_liquid.deep_merge(liquid_date_attributes) end end end |