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.
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
#blog ⇒ Object
Returns the value of attribute blog.
6 7 8 |
# File 'lib/planet/post.rb', line 6 def blog @blog end |
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/planet/post.rb', line 6 def content @content end |
#date ⇒ Object
Returns the value of attribute date.
6 7 8 |
# File 'lib/planet/post.rb', line 6 def date @date end |
#rss_data ⇒ Object
Returns the value of attribute rss_data.
6 7 8 |
# File 'lib/planet/post.rb', line 6 def rss_data @rss_data end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/planet/post.rb', line 6 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/planet/post.rb', line 6 def url @url end |
Instance Method Details
#file_name ⇒ Object
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 |
#footer ⇒ Object
50 51 52 53 54 55 |
# File 'lib/planet/post.rb', line 50 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
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_h ⇒ Object 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., 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., 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
17 18 19 |
# File 'lib/planet/post.rb', line 17 def to_s "#{ header }#{ content }#{ }" end |