Sha256: 902449d095caf8685441f802933d728aa2d45cd9e1c0708ddf4dcc64d73f8371
Contents?: true
Size: 1.73 KB
Versions: 2
Compression:
Stored size: 1.73 KB
Contents
module Vedeu # Renders a {Vedeu::VirtualBuffer} or {Vedeu::Output} as a HTML table. # class HTMLRenderer # @param output [Array<Array<Vedeu::Char>>] # @return [String] def self.render(output) new(output).to_file end # @param output [Array<Array<Vedeu::Char>>] # @param path [String] # @return [String] def self.to_file(output, path = nil) new(output).to_file(path) end # Returns a new instance of Vedeu::HTMLRenderer. # # @param output [Array<Array<Vedeu::Char>>] # @return [Vedeu::HTMLRenderer] def initialize(output) @output = output end # @return [String] def render Vedeu::Template.parse(self, template) end # Writes the parsed template to a file (at the given path) and returns the # contents. # # @param path [String] # @return [String] def to_file(path = file_path) content = render File.open(path, 'w', 0644) { |file| file.write(content) } content end # @return [String] 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 private # @!attribute [r] output # @return [Array<Array<Vedeu::Char>>] attr_reader :output # @return [String] def template File.dirname(__FILE__) + '/../templates/html_renderer.vedeu' end # @return [String] def file_path "/tmp/vedeu_html_#{timestamp}.html" end # return [Fixnum] def timestamp @timestamp ||= Time.now.to_i end end # HTMLRenderer end # Vedeu
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.4.15 | lib/vedeu/output/renderers/html_renderer.rb |
vedeu-0.4.14 | lib/vedeu/output/renderers/html_renderer.rb |