Class: Monograph::ChapterTemplateContext
- Inherits:
-
TemplateContext
- Object
- TemplateContext
- Monograph::ChapterTemplateContext
- 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
-
#chapter ⇒ Object
readonly
Returns the value of attribute chapter.
Instance Method Summary collapse
- #book ⇒ Object
- #content ⇒ Object
-
#initialize(chapter) ⇒ ChapterTemplateContext
constructor
A new instance of ChapterTemplateContext.
- #next_page ⇒ Object
- #page_title ⇒ Object
- #permalink ⇒ Object
- #previous_page ⇒ Object
Methods inherited from TemplateContext
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
#chapter ⇒ Object (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
#book ⇒ Object
11 12 13 |
# File 'lib/monograph/chapter_template_context.rb', line 11 def book @chapter.book end |
#content ⇒ Object
19 20 21 |
# File 'lib/monograph/chapter_template_context.rb', line 19 def content @chapter.html end |
#next_page ⇒ Object
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_title ⇒ Object
15 16 17 |
# File 'lib/monograph/chapter_template_context.rb', line 15 def page_title "#{chapter.title} - #{book.title}" end |
#permalink ⇒ Object
23 24 25 |
# File 'lib/monograph/chapter_template_context.rb', line 23 def permalink @chapter.permalink + ".html" end |
#previous_page ⇒ Object
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 |