Class: Dimples::Post

Inherits:
Page
  • Object
show all
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})-(.+)/

Constants included from Frontable

Frontable::SKIPPED_METADATA_KEYS

Instance Attribute Summary collapse

Attributes inherited from Page

#contents, #extension, #filename, #layout, #output_directory, #path, #title

Attributes included from Renderable

#rendered_contents

Instance Method Summary collapse

Methods inherited from Page

#output_filename, #output_path, #url, #write

Methods included from Renderable

#render, #rendering_engine, #scope

Methods included from Frontable

#read_with_front_matter

Constructor Details

#initialize(site, path) ⇒ Post

Returns a new instance of Post.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dimples/post.rb', line 18

def initialize(site, path)
  super(site, path)

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

  @filename = 'index'
  @slug = parts[4]
  @layout = @site.config[:layouts][:post]

  self.date = Date.new(parts[1].to_i, parts[2].to_i, parts[3].to_i)

  @output_directory = File.join(
    @date.strftime(@site.output_paths[:posts]),
    @slug.to_s
  )
end

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



8
9
10
# File 'lib/dimples/post.rb', line 8

def categories
  @categories
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#dayObject

Returns the value of attribute day.



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

def day
  @day
end

#monthObject

Returns the value of attribute month.



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

def month
  @month
end

#next_postObject

Returns the value of attribute next_post.



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

def next_post
  @next_post
end

#previous_postObject

Returns the value of attribute previous_post.



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

def previous_post
  @previous_post
end

#slugObject

Returns the value of attribute slug.



6
7
8
# File 'lib/dimples/post.rb', line 6

def slug
  @slug
end

#summaryObject

Returns the value of attribute summary.



7
8
9
# File 'lib/dimples/post.rb', line 7

def summary
  @summary
end

#yearObject

Returns the value of attribute year.



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

def year
  @year
end

Instance Method Details

#inspectObject



43
44
45
# File 'lib/dimples/post.rb', line 43

def inspect
  "#<#{self.class} @slug=#{@slug} @output_path=#{output_path}>"
end