Class: Vedeu::Renderers::HTML
- Inherits:
-
Object
- Object
- Vedeu::Renderers::HTML
- Defined in:
- lib/vedeu/output/renderers/html.rb
Overview
Renders a VirtualBuffer or Output as a HTML table.
Instance Attribute Summary collapse
- #output ⇒ Array<Array<Vedeu::Char>> readonly protected
Class Method Summary collapse
Instance Method Summary collapse
- #file_path ⇒ String private
- #html_body ⇒ String
-
#initialize(output) ⇒ Vedeu::Renderers::HTML
constructor
Returns a new instance of Vedeu::Renderers::HTML.
- #render ⇒ String
- #template ⇒ String private
-
#timestamp ⇒ Object
private
return [Fixnum].
-
#to_file(path = file_path) ⇒ String
Writes the parsed template to a file (at the given path) and returns the contents.
Constructor Details
#initialize(output) ⇒ Vedeu::Renderers::HTML
Returns a new instance of Vedeu::Renderers::HTML.
25 26 27 |
# File 'lib/vedeu/output/renderers/html.rb', line 25 def initialize(output) @output = output end |
Instance Attribute Details
#output ⇒ Array<Array<Vedeu::Char>> (readonly, protected)
67 68 69 |
# File 'lib/vedeu/output/renderers/html.rb', line 67 def output @output end |
Class Method Details
.render(output) ⇒ 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
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_path ⇒ String (private)
77 78 79 |
# File 'lib/vedeu/output/renderers/html.rb', line 77 def file_path "/tmp/vedeu_html_#{}.html" end |
#html_body ⇒ 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 |
#render ⇒ String
30 31 32 |
# File 'lib/vedeu/output/renderers/html.rb', line 30 def render Vedeu::Template.parse(self, template) end |
#template ⇒ String (private)
72 73 74 |
# File 'lib/vedeu/output/renderers/html.rb', line 72 def template ::File.dirname(__FILE__) + '/../templates/html_renderer.vedeu' end |
#timestamp ⇒ Object (private)
return [Fixnum]
82 83 84 |
# File 'lib/vedeu/output/renderers/html.rb', line 82 def @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.
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 |