Module: Transit::Package::Post

Extended by:
ActiveSupport::Concern
Defined in:
lib/transit/package/post.rb

Defined Under Namespace

Modules: Validations

Instance Method Summary collapse

Instance Method Details

#next_postObject

Grab the post “next” to this one, ordered by post date

Examples:

@post.next_post


45
46
47
# File 'lib/transit/package/post.rb', line 45

def next_post
  @next_post ||= self.class.only(:title, :slug).where(:post_date.gt => self.).ascending(:post_date).first
end

#previous_postObject

Grab the post “previous” to this one, ordered by post date

Examples:

@post.previous_post


37
38
39
# File 'lib/transit/package/post.rb', line 37

def previous_post
  @previous_post ||= self.class.only(:title, :slug).where(:post_date.lt => self.).descending(:post_date).first
end

#teaserObject

The “teaser” is a shortened version of a post used to display on “index” pages. Post models include a “teaser” and a “default teaser” allowing teasers to be automatically generated from the first paragraph of the html body. It is assumed that all posts will include at least one Text context containing the body of the post



61
62
63
64
# File 'lib/transit/package/post.rb', line 61

def teaser
  return self.attributes['teaser'] unless self.attributes['teaser'].to_s.blank?
  default_teaser.to_s
end

#timestampObject

Returns a timestamp formatted to a normal “post date”



51
52
53
54
# File 'lib/transit/package/post.rb', line 51

def timestamp
  return "" if self..nil?
  self..to_time.midnight.strftime("%B %d, %Y")
end