Class: Dimples::Post
Overview
A single dated post on a site.
Constant Summary collapse
- POST_FILENAME =
/(\d{4})-(\d{2})-(\d{2})-(.+)/.freeze
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
- #url ⇒ Object
- #year ⇒ Object
Methods inherited from Page
#extension, #filename, #render, #write
Constructor Details
#initialize(site, path) ⇒ Post
Returns a new instance of Post.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dimples/post.rb', line 8 def initialize(site, path) super parts = File.basename(path, File.extname(path)).match(POST_FILENAME) [:layout] ||= @site.config.layouts.post [:date] = Date.new(parts[1].to_i, parts[2].to_i, parts[3].to_i) [:slug] = parts[4] [:categories] ||= [] [:draft] ||= false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Dimples::Page
Instance Method Details
#day ⇒ Object
34 35 36 |
# File 'lib/dimples/post.rb', line 34 def day @day ||= [:date].strftime('%d') end |
#month ⇒ Object
30 31 32 |
# File 'lib/dimples/post.rb', line 30 def month @month ||= [:date].strftime('%m') end |
#url ⇒ Object
21 22 23 24 |
# File 'lib/dimples/post.rb', line 21 def url path = date.strftime(draft ? @site.config.paths.drafts : @site.config.paths.posts) "/#{path}/#{slug}/" end |
#year ⇒ Object
26 27 28 |
# File 'lib/dimples/post.rb', line 26 def year @year ||= [:date].strftime('%Y') end |