Class: HTMLLayout

Inherits:
Object show all
Includes:
ERB::Util
Defined in:
lib/review/htmllayout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, template) ⇒ HTMLLayout



7
8
9
10
11
12
13
14
15
# File 'lib/review/htmllayout.rb', line 7

def initialize(params, template)
  @body = params['body']
  @title = params['title']
  @toc = params['toc']
  @next = params['next']
  @prev = params['prev']
  @builder = params['builder']
  @template = template
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



16
17
18
# File 'lib/review/htmllayout.rb', line 16

def body
  @body
end

#titleObject (readonly)

Returns the value of attribute title.



16
17
18
# File 'lib/review/htmllayout.rb', line 16

def title
  @title
end

#tocObject (readonly)

Returns the value of attribute toc.



16
17
18
# File 'lib/review/htmllayout.rb', line 16

def toc
  @toc
end

Instance Method Details

#next_chapterObject



18
19
20
21
22
23
24
# File 'lib/review/htmllayout.rb', line 18

def next_chapter
  if @next.present?
    "<a href='#{h @next.id}.html'>#{h @builder.compile_inline @next.title}</a>"
  else
    ""
  end
end

#prev_chapterObject



26
27
28
29
30
31
32
# File 'lib/review/htmllayout.rb', line 26

def prev_chapter
  if @prev.present?
    "<a href='#{h @prev.id}.html'>#{h @builder.compile_inline @prev.title}</a>"
  else
    ""
  end
end

#resultObject



34
35
36
37
38
39
40
# File 'lib/review/htmllayout.rb', line 34

def result
  if File.exist?(@template)
    return ERB.new(IO.read(@template)).result(binding)
  else
    return @src
  end
end