Class: Brite::Post

Inherits:
Page show all
Defined in:
lib/brite/post.rb

Overview

Models a blog post. A post is essentially the same as a page, but carries a relatition with other posts that a page does not.

Instance Attribute Summary

Attributes inherited from Page

#author, #category, #date, #draft, #file, #layout, #route, #site, #summary, #tags, #title

Attributes inherited from Model

#file, #site

Instance Method Summary collapse

Methods inherited from Page

#extension, #extension=, #initialize, #inspect, #name, #output, #output=, #permalink, #root, #to_s

Methods inherited from Model

#[], #[]=, #config, #initialize, #method_missing, #part, #rendering_fields, #to_binding, #to_h, #update

Constructor Details

This class inherits a constructor from Brite::Page

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Brite::Model

Instance Method Details

#initialize_defaultsObject



11
12
13
14
15
16
17
18
19
# File 'lib/brite/post.rb', line 11

def initialize_defaults
  super

  @route  = site.config.post_route
  @layout = site.config.post_layout #@site.config.find_layout(@site.config.post_layout)

  @previous_post = nil
  @next_post     = nil
end

#next_postObject

This assumes ‘site.posts` is sorted by date.



32
33
34
35
36
37
# File 'lib/brite/post.rb', line 32

def next_post
  @next_post ||= (
    index = site.posts.index(self)
    site.posts[index + 1]
  )
end

#previous_postObject

TODO:

Rename to back_post.

This assumes ‘site.posts` is sorted by date.



24
25
26
27
28
29
# File 'lib/brite/post.rb', line 24

def previous_post
  @previous_post ||= (
    index = site.posts.index(self)
    index == 0 ? nil : site.posts[index - 1]
  )
end