Class: Dimples::Post
Overview
A single dated post on a site.
Constant Summary collapse
- POST_FILENAME =
/(\d{4})-(\d{2})-(\d{2})-(.+)/.freeze
Constants included from Frontable
Frontable::FRONT_MATTER_PATTERN
Instance Attribute Summary
Attributes inherited from Page
Instance Method Summary collapse
- #day ⇒ Object
-
#initialize(site, path) ⇒ Post
constructor
A new instance of Post.
- #month ⇒ Object
- #year ⇒ Object
Methods inherited from Page
#extension, #filename, #render, #write
Methods included from Frontable
Constructor Details
#initialize(site, path) ⇒ Post
Returns a new instance of Post.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/dimples/post.rb', line 8 def initialize(site, path) super parts = File.basename(path, File.extname(path)).match(POST_FILENAME) @metadata[:layout] ||= @site.config.layouts.post @metadata[:date] = Date.new(parts[1].to_i, parts[2].to_i, parts[3].to_i) @metadata[:slug] = parts[4] @metadata[:categories] ||= [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Dimples::Page
Instance Method Details
#day ⇒ Object
28 29 30 |
# File 'lib/dimples/post.rb', line 28 def day @day ||= @metadata[:date].strftime('%d') end |
#month ⇒ Object
24 25 26 |
# File 'lib/dimples/post.rb', line 24 def month @month ||= @metadata[:date].strftime('%m') end |
#year ⇒ Object
20 21 22 |
# File 'lib/dimples/post.rb', line 20 def year @year ||= @metadata[:date].strftime('%Y') end |