Class: Monograph::ChapterTemplateContext

Inherits:
TemplateContext show all
Defined in:
lib/monograph/chapter_template_context.rb

Overview

The ChapterTemplateContext is used whenever a chapter is to be rendered within the template.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TemplateContext

#get_binding

Constructor Details

#initialize(chapter) ⇒ ChapterTemplateContext

Returns a new instance of ChapterTemplateContext.



7
8
9
# File 'lib/monograph/chapter_template_context.rb', line 7

def initialize(chapter)
  @chapter = chapter
end

Instance Attribute Details

#chapterObject (readonly)

Returns the value of attribute chapter.



5
6
7
# File 'lib/monograph/chapter_template_context.rb', line 5

def chapter
  @chapter
end

Instance Method Details

#bookObject



11
12
13
# File 'lib/monograph/chapter_template_context.rb', line 11

def book
  @chapter.book
end

#contentObject



19
20
21
# File 'lib/monograph/chapter_template_context.rb', line 19

def content
  @chapter.html
end

#next_pageObject



27
28
29
# File 'lib/monograph/chapter_template_context.rb', line 27

def next_page
  @chapter.book.chapters.select { |c| c.number == @chapter.number + 1}.first
end

#page_titleObject



15
16
17
# File 'lib/monograph/chapter_template_context.rb', line 15

def page_title
  "#{chapter.title} - #{book.title}"
end


23
24
25
# File 'lib/monograph/chapter_template_context.rb', line 23

def permalink
  @chapter.permalink + ".html"
end

#previous_pageObject



31
32
33
34
35
36
37
# File 'lib/monograph/chapter_template_context.rb', line 31

def previous_page
  if @chapter.number == 1
    BookTemplateContext.new(@chapter.book, 'contents.html')
  else
    @chapter.book.chapters.select { |c| c.number == @chapter.number - 1}.first
  end
end