Class: PostRunner::View

Inherits:
Object
  • Object
show all
Defined in:
lib/postrunner/View.rb

Overview

Base class for all generated HTML pages.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, views, pages) ⇒ View

Create a new View object.

Parameters:

  • title (String)

    The title of the HTML page

  • views (ViewButtons)

    List of all cross referenced View objects

  • pages (PagingButtons)

    List of all pages of this View



28
29
30
31
32
33
34
35
36
# File 'lib/postrunner/View.rb', line 28

def initialize(title, views, pages)
  @doc = HTMLBuilder.new(title)
  @views = views
  @pages = pages

  @doc.unique(:view_style) {
    style
  }
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



22
23
24
# File 'lib/postrunner/View.rb', line 22

def doc
  @doc
end

Instance Method Details

#bodyObject

Create the body section of the HTML document.



39
40
41
42
43
44
45
# File 'lib/postrunner/View.rb', line 39

def body
  ViewTop.new(@views, @pages).to_html(@doc)
  yield if block_given?
  ViewBottom.new.to_html(@doc)

  self
end

#to_htmlObject

Convert the View into an HTML document.



48
49
50
# File 'lib/postrunner/View.rb', line 48

def to_html
  @doc.to_html
end

#write(file_name) ⇒ Object

Write the HTML document to a file

Parameters:

  • file_name (String)

    Name of the file to write



54
55
56
57
58
59
60
# File 'lib/postrunner/View.rb', line 54

def write(file_name)
  begin
    File.write(file_name, to_html)
  rescue IOError
    Log.fatal "Cannot write file '#{file_name}: #{$!}"
  end
end