Class: Dimples::Post
Constant Summary collapse
- POST_FILENAME =
/(\d{4})-(\d{2})-(\d{2})-(.+)/
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, #inspect, #render, #write
Methods included from Frontable
Constructor Details
#initialize(site, path) ⇒ Post
Returns a new instance of Post.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/dimples/post.rb', line 7 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
27 28 29 |
# File 'lib/dimples/post.rb', line 27 def day @day ||= @metadata[:date].strftime('%d') end |
#month ⇒ Object
23 24 25 |
# File 'lib/dimples/post.rb', line 23 def month @month ||= @metadata[:date].strftime('%m') end |
#year ⇒ Object
19 20 21 |
# File 'lib/dimples/post.rb', line 19 def year @year ||= @metadata[:date].strftime('%Y') end |