Class: Dimples::Post

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Renderable

#render, #renderer

Methods included from Writeable

#write

Methods included from Frontable

#read_with_yaml

Constructor Details

#initialize(site, path) ⇒ Post

Returns a new instance of Post.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dimples/post.rb', line 25

def initialize(site, path)
  @site = site
  @path = path

  @filename = 'index'
  @extension = @site.config['file_extensions']['posts']

  parts = File.basename(path, File.extname(path)).match(/(\d{4})-(\d{2})-(\d{2})-(.+)/)

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

  @layout = @site.config['layouts']['post']
  @categories = {}

  @draft = false

  @year = @date.strftime('%Y')
  @month = @date.strftime('%m')
  @day = @date.strftime('%d')

  @contents = read_with_yaml(path)

end

Instance Attribute Details

#contentsObject



50
51
52
# File 'lib/dimples/post.rb', line 50

def contents
  @contents
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.



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

def day
  @day
end

#draftObject

Returns the value of attribute draft.



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

def draft
  @draft
end

#extensionObject

Returns the value of attribute extension.



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

def extension
  @extension
end

#filenameObject

Returns the value of attribute filename.



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

def filename
  @filename
end

#layoutObject

Returns the value of attribute layout.



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

def layout
  @layout
end

#monthObject

Returns the value of attribute month.



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

def month
  @month
end

#next_postObject

Returns the value of attribute next_post.



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

def next_post
  @next_post
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#previous_postObject

Returns the value of attribute previous_post.



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

def previous_post
  @previous_post
end

#rendered_contentsObject

Returns the value of attribute rendered_contents.



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

def rendered_contents
  @rendered_contents
end

#slugObject

Returns the value of attribute slug.



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

def slug
  @slug
end

#templateObject

Returns the value of attribute template.



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

def template
  @template
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#yearObject

Returns the value of attribute year.



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

def year
  @year
end

Instance Method Details

#categoriesObject



65
66
67
# File 'lib/dimples/post.rb', line 65

def categories
  @categories
end

#categories=(slugs) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/dimples/post.rb', line 54

def categories=(slugs)
  @categories = {}

  slugs.each do |slug|
    @site.categories[slug] ||= Dimples::Category.new(slug)
    @site.categories[slug].posts << self

    @categories[slug] ||= @site.categories[slug]
  end
end

#output_file_path(parent_path) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/dimples/post.rb', line 69

def output_file_path(parent_path)
  parts = [parent_path]

  if @site.config['paths']['post']
    path = @date.strftime(@site.config['paths']['post'])
    parts.concat(path.split('/')) if path
  end

  parts << @slug
  parts << "#{@filename}.#{@extension}"

  File.join(parts)
end