Class: Vedeu::HTMLRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/output/html_renderer.rb

Overview

Renders a VirtualBuffer or Output as a HTML table.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Vedeu::HTMLRenderer

Parameters:



21
22
23
# File 'lib/vedeu/output/html_renderer.rb', line 21

def initialize(output)
  @output = output
end

Instance Attribute Details

#outputObject (readonly, private)

Returns the value of attribute output.



59
60
61
# File 'lib/vedeu/output/html_renderer.rb', line 59

def output
  @output
end

Class Method Details

.render(output) ⇒ String

Parameters:

Returns:

  • (String)


9
10
11
# File 'lib/vedeu/output/html_renderer.rb', line 9

def self.render(output)
  new(output).render
end

.to_file(output) ⇒ String

Parameters:

Returns:

  • (String)


15
16
17
# File 'lib/vedeu/output/html_renderer.rb', line 15

def self.to_file(output)
  new(output).to_file
end

Instance Method Details

#file_pathString (private)

Returns:

  • (String)


67
68
69
# File 'lib/vedeu/output/html_renderer.rb', line 67

def file_path
  "/tmp/vedeu_html_#{timestamp}.html"
end

#html_bodyString

Returns:

  • (String)


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vedeu/output/html_renderer.rb', line 44

def html_body
  out = ''
  Array(output).each do |line|
    out << "<tr>\n"
    line.each do |char|
      out << char.to_html
      out << "\n"
    end
    out << "</tr>\n"
  end
  out
end

#renderString

Returns:

  • (String)


26
27
28
# File 'lib/vedeu/output/html_renderer.rb', line 26

def render
  Template.parse(self, template)
end

#templateString (private)

Returns:

  • (String)


62
63
64
# File 'lib/vedeu/output/html_renderer.rb', line 62

def template
  File.dirname(__FILE__) + '/templates/html_renderer.vedeu'
end

#timestampObject (private)

return [Fixnum]



72
73
74
# File 'lib/vedeu/output/html_renderer.rb', line 72

def timestamp
  @timestamp ||= Time.now.to_i
end

#to_file(path = file_path) ⇒ String

Writes the parsed template to a file (at the given path) and returns the contents.

Parameters:

  • path (String) (defaults to: file_path)

Returns:

  • (String)


35
36
37
38
39
40
41
# File 'lib/vedeu/output/html_renderer.rb', line 35

def to_file(path = file_path)
  content = render

  File.open(path, "w", 0644) { |file| file.write(content) }

  content
end