Class: Vedeu::Renderers::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/output/renderers/html.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::Renderers::HTML

Returns a new instance of Vedeu::Renderers::HTML.

Parameters:



25
26
27
# File 'lib/vedeu/output/renderers/html.rb', line 25

def initialize(output)
  @output = output
end

Instance Attribute Details

#outputArray<Array<Vedeu::Char>> (readonly, protected)

Returns:



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

def output
  @output
end

Class Method Details

.render(output) ⇒ String

Parameters:

Returns:

  • (String)


10
11
12
# File 'lib/vedeu/output/renderers/html.rb', line 10

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

.to_file(output, path = nil) ⇒ String

Parameters:

  • output (Array<Array<Vedeu::Char>>)
  • path (String) (defaults to: nil)

Returns:

  • (String)


17
18
19
# File 'lib/vedeu/output/renderers/html.rb', line 17

def self.to_file(output, path = nil)
  new(output).to_file(path)
end

Instance Method Details

#file_pathString (private)

Returns:

  • (String)


77
78
79
# File 'lib/vedeu/output/renderers/html.rb', line 77

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

#html_bodyString

Returns:

  • (String)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vedeu/output/renderers/html.rb', line 48

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

#renderString

Returns:

  • (String)


30
31
32
# File 'lib/vedeu/output/renderers/html.rb', line 30

def render
  Vedeu::Template.parse(self, template)
end

#templateString (private)

Returns:

  • (String)


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

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

#timestampObject (private)

return [Fixnum]



82
83
84
# File 'lib/vedeu/output/renderers/html.rb', line 82

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)


39
40
41
42
43
44
45
# File 'lib/vedeu/output/renderers/html.rb', line 39

def to_file(path = file_path)
  content = render

  ::File.open(path, 'w') { |file| file.write(content) }

  content
end