Class: Planet::Post

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Post

Returns a new instance of Post.



8
9
10
11
12
13
14
15
# File 'lib/planet/post.rb', line 8

def initialize(attributes = {})
  self.title      = attributes[:title]
  self.content    = attributes[:content]
  self.date       = attributes[:date]
  self.url        = attributes[:url]
  self.blog       = attributes[:blog]
  self.rss_data   = attributes[:rss_data]
end

Instance Attribute Details

#blogObject

Returns the value of attribute blog.



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

def blog
  @blog
end

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#rss_dataObject

Returns the value of attribute rss_data.



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

def rss_data
  @rss_data
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#file_nameObject



57
58
59
60
61
62
# File 'lib/planet/post.rb', line 57

def file_name
  name_date = date ? date.strftime('%Y-%m-%d') : nil
  name_title = title.downcase.scan(/\w+/).join('-')

  [name_date, name_title].join('-')[0..59] # can return a file name that is too long, so truncate here to 60 chars
end


50
51
52
53
54
55
# File 'lib/planet/post.rb', line 50

def footer
  file = self.blog.planet.config.fetch('templates_directory', '_layouts/') + 'author.html'
  file_contents = File.read(file)

  Mustache.render(file_contents, self.to_hash)
end

#headerObject



43
44
45
46
47
48
# File 'lib/planet/post.rb', line 43

def header
  file = self.blog.planet.config.fetch('templates_directory', '_layouts/') + 'header.md'
  file_contents = File.read(file)

  Mustache.render(file_contents, self.to_hash)
end

#to_hObject Also known as: to_hash



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/planet/post.rb', line 21

def to_h
  {
    post_content: self.content,
    post_title: self.title,
    post_date: self.date,
    image_url: self.blog.image,
    author: self.blog.author,
    blog_url: self.blog.url,
    blog_name: self.blog.name,
    blog_slug: self.blog.name.to_url(:limit => 50, :truncate_words => true),
    blog_categories: self.blog.categories,
    blog_tags: self.blog.tags,
    post_url: self.url,
    twitter: self.blog.twitter,
    twitter_url: "http://twitter.com/#{ self.blog.twitter }",
    post_rss_data: self.rss_data,
    blog_rss_data: self.blog.rss_data
  }
end

#to_sObject



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

def to_s
  "#{ header }#{ content }#{ footer }"
end