Class: Dimples::Post

Inherits:
Page
  • Object
show all
Defined in:
lib/dimples/post.rb

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

#contents, #metadata, #path

Instance Method Summary collapse

Methods inherited from Page

#extension, #filename, #render, #write

Methods included from Frontable

#read_with_front_matter

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

#dayObject



28
29
30
# File 'lib/dimples/post.rb', line 28

def day
  @day ||= @metadata[:date].strftime('%d')
end

#monthObject



24
25
26
# File 'lib/dimples/post.rb', line 24

def month
  @month ||= @metadata[:date].strftime('%m')
end

#yearObject



20
21
22
# File 'lib/dimples/post.rb', line 20

def year
  @year ||= @metadata[:date].strftime('%Y')
end