Class: Monograph::BookTemplateContext

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

Overview

The BookTemplateContext is used whenever a non-chapter page (cover, contents) is to be rendered within the template.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TemplateContext

#get_binding

Constructor Details

#initialize(book, template) ⇒ BookTemplateContext

Returns a new instance of BookTemplateContext.



8
9
10
11
# File 'lib/monograph/book_template_context.rb', line 8

def initialize(book, template)
  @book = book
  @template = template
end

Instance Attribute Details

#bookObject (readonly)

Returns the value of attribute book.



6
7
8
# File 'lib/monograph/book_template_context.rb', line 6

def book
  @book
end

Instance Method Details

#authorObject



28
29
30
# File 'lib/monograph/book_template_context.rb', line 28

def author
  @book.config['author']
end

#contentObject



13
14
15
# File 'lib/monograph/book_template_context.rb', line 13

def content
  @content ||= @book.template_file(@template)
end

#next_pageObject



36
37
38
39
40
41
42
43
# File 'lib/monograph/book_template_context.rb', line 36

def next_page
  case @template
  when 'index.html'
    self.class.new(@book, 'contents.html')
  when 'contents.html'
    @book.chapters.first
  end
end

#page_titleObject



17
18
19
# File 'lib/monograph/book_template_context.rb', line 17

def page_title
  title
end


32
33
34
# File 'lib/monograph/book_template_context.rb', line 32

def permalink
  @template.gsub(/\.html\z/, '')
end

#previous_pageObject



45
46
47
48
49
50
# File 'lib/monograph/book_template_context.rb', line 45

def previous_page
  case @template
  when 'contents.html'
    self.class.new(@book, 'index.html')
  end
end

#titleObject



21
22
23
24
25
26
# File 'lib/monograph/book_template_context.rb', line 21

def title
  case @template
  when 'index.html' then @book.title
  when 'contents.html' then 'Contents'
  end
end