Class: Planet::Post
- Inherits:
-
Object
- Object
- Planet::Post
- Defined in:
- lib/planet/post.rb
Instance Attribute Summary collapse
-
#blog ⇒ Object
Returns the value of attribute blog.
-
#content ⇒ Object
Returns the value of attribute content.
-
#date ⇒ Object
Returns the value of attribute date.
-
#rss_data ⇒ Object
Returns the value of attribute rss_data.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #file_name ⇒ Object
- #footer ⇒ Object
- #header ⇒ Object
-
#initialize(attributes = {}) ⇒ Post
constructor
A new instance of Post.
- #to_h ⇒ Object (also: #to_hash)
- #to_s ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Post
Returns a new instance of Post.
7 8 9 10 11 12 13 14 |
# File 'lib/planet/post.rb', line 7 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
#blog ⇒ Object
Returns the value of attribute blog.
5 6 7 |
# File 'lib/planet/post.rb', line 5 def blog @blog end |
#content ⇒ Object
Returns the value of attribute content.
5 6 7 |
# File 'lib/planet/post.rb', line 5 def content @content end |
#date ⇒ Object
Returns the value of attribute date.
5 6 7 |
# File 'lib/planet/post.rb', line 5 def date @date end |
#rss_data ⇒ Object
Returns the value of attribute rss_data.
5 6 7 |
# File 'lib/planet/post.rb', line 5 def rss_data @rss_data end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/planet/post.rb', line 5 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/planet/post.rb', line 5 def url @url end |
Instance Method Details
#file_name ⇒ Object
54 55 56 57 58 59 |
# File 'lib/planet/post.rb', line 54 def file_name name_date = date ? date.strftime('%Y-%m-%d') : nil name_title = title.downcase.scan(/\w+/).join('-') [name_date, name_title].join('-') end |
#footer ⇒ Object
47 48 49 50 51 52 |
# File 'lib/planet/post.rb', line 47 def file = self.blog.planet.config.fetch('templates_directory', '_layouts/') + 'author.html' file_contents = File.read(file) Mustache.render(file_contents, self.to_hash) end |
#header ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/planet/post.rb', line 39 def header ## TODO: We need categories/tags 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_h ⇒ Object Also known as: to_hash
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/planet/post.rb', line 20 def to_h { post_content: self.content, post_title: self.title, post_date: self.date, image_url: self.blog.image, author: self.blog., blog_url: self.blog.url, blog_name: self.blog.name, 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_s ⇒ Object
16 17 18 |
# File 'lib/planet/post.rb', line 16 def to_s "#{ header }#{ content }#{ footer }" end |