Class: Dimples::Post

Inherits:
Object
  • Object
show all
Includes:
Frontable, Renderable, Writeable
Defined in:
lib/dimples/post.rb

Overview

A class that models a single site post.

Constant Summary collapse

FILENAME_DATE =
/(\d{4})-(\d{2})-(\d{2})-(.+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Renderable

#build_scope, #render, #renderer

Methods included from Writeable

#write

Methods included from Frontable

#apply_metadata, #read_with_front_matter

Constructor Details

#initialize(site, path) ⇒ Post

Returns a new instance of Post.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dimples/post.rb', line 29

def initialize(site, path)
  @site = site
  @path = path
  @filename = 'index'
  @extension = 'html'

  parts = File.basename(path, File.extname(path)).match(FILENAME_DATE)

  @slug = parts[4]
  self.date = Time.mktime(parts[1], parts[2], parts[3])

  @layout = @site.config['layouts']['post']
  @contents = read_with_front_matter(path)
end

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



12
13
14
# File 'lib/dimples/post.rb', line 12

def categories
  @categories
end

#contentsObject

Returns the value of attribute contents.



17
18
19
# File 'lib/dimples/post.rb', line 17

def contents
  @contents
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#dayObject

Returns the value of attribute day.



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

def day
  @day
end

#extensionObject

Returns the value of attribute extension.



15
16
17
# File 'lib/dimples/post.rb', line 15

def extension
  @extension
end

#filenameObject

Returns the value of attribute filename.



14
15
16
# File 'lib/dimples/post.rb', line 14

def filename
  @filename
end

#layoutObject

Returns the value of attribute layout.



16
17
18
# File 'lib/dimples/post.rb', line 16

def layout
  @layout
end

#monthObject

Returns the value of attribute month.



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

def month
  @month
end

#next_postObject

Returns the value of attribute next_post.



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

def next_post
  @next_post
end

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/dimples/post.rb', line 10

def path
  @path
end

#previous_postObject

Returns the value of attribute previous_post.



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

def previous_post
  @previous_post
end

#rendered_contentsObject

Returns the value of attribute rendered_contents.



22
23
24
# File 'lib/dimples/post.rb', line 22

def rendered_contents
  @rendered_contents
end

#slugObject

Returns the value of attribute slug.



18
19
20
# File 'lib/dimples/post.rb', line 18

def slug
  @slug
end

#templateObject

Returns the value of attribute template.



13
14
15
# File 'lib/dimples/post.rb', line 13

def template
  @template
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/dimples/post.rb', line 11

def title
  @title
end

#yearObject

Returns the value of attribute year.



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

def year
  @year
end

Instance Method Details

#output_path(parent_path) ⇒ Object



52
53
54
55
# File 'lib/dimples/post.rb', line 52

def output_path(parent_path)
  parent_path = @date.strftime(parent_path) if parent_path.match?(/%/)
  File.join([parent_path, @slug.to_s, "#{@filename}.#{@extension}"])
end