# frozen_string_literal: true
require 'cgi'
module DocParser
# The XLSXOutput class generates an HTML file containing a table
# @see Output
class HTMLOutput < Output
# @!visibility private
HTMLHEADER = <<~EOS
HTML output "#FILENAME#"
EOS
# @!visibility private
HTMLFOOTER = <<~EOS
#COUNT# rows
EOS
def open_file
@file << HTMLHEADER.gsub('#FILENAME#', @filename)
end
def header
return if @header.nil? || @header.empty?
@file << ''
@file << @header.map { |f| '' + f + ' | ' }.join
@file << "
\n\n"
@tbody = true
end
def write_row(row)
unless @tbody
@file << "\n"
@tbody = true
end
@file << ''
@file << row.map { |f| '' + CGI.escapeHTML(f.to_s) + ' | ' }.join
@file << "
\n"
end
def footer
@file << HTMLFOOTER.gsub('#COUNT#', @rowcount.to_s)
end
end
end