Class: PostRunner::View
- Inherits:
-
Object
- Object
- PostRunner::View
- Defined in:
- lib/postrunner/View.rb
Overview
Base class for all generated HTML pages.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Instance Method Summary collapse
-
#body ⇒ Object
Create the body section of the HTML document.
-
#initialize(title, views, pages) ⇒ View
constructor
Create a new View object.
-
#to_html ⇒ Object
Convert the View into an HTML document.
-
#write(file_name) ⇒ Object
Write the HTML document to a file.
Constructor Details
#initialize(title, views, pages) ⇒ View
Create a new View object.
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
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
22 23 24 |
# File 'lib/postrunner/View.rb', line 22 def doc @doc end |
Instance Method Details
#body ⇒ Object
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_html ⇒ Object
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
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 |