class Planet::Post

Attributes

blog[RW]
content[RW]
date[RW]
rss_data[RW]
title[RW]
url[RW]

Public Class Methods

new(attributes = {}) click to toggle source
# 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

Public Instance Methods

file_name() click to toggle source
# 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
header() click to toggle source
# 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() click to toggle source
# 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
Also aliased as: to_hash
to_hash()
Alias for: to_h
to_s() click to toggle source
# File lib/planet/post.rb, line 17
def to_s
  "#{ header }#{ content }#{ footer }"
end