Sha256: e27710540f147aeef9d1e08d81e10ba19461616bf6b251c1038f93de049eaaf6

Contents?: true

Size: 1.63 KB

Versions: 4

Compression:

Stored size: 1.63 KB

Contents

require 'cgi'
module DocParser
  # The XLSXOutput class generates an HTML file containing a table
  # @see Output
  class HTMLOutput < Output
    # @!visibility private
    HTMLHEADER = <<-EOS
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>HTML output "#FILENAME#"</title>
<style type="text/css">
body {
  font-family:"Helvetica Neue", Helvetica, Sans-Serif;
  font-size:12px;
}
table {
border:1px solid #69c;
border-collapse:collapse;
font-size:12px;
text-align:left;
width:480px;
}
th {
border-bottom:1px dashed #69c;
color:#039;
font-size:14px;
font-weight:normal;
padding:12px 17px;
}
td {
color:#669;
padding:7px 17px;
white-space: pre;
}
tbody tr:hover td {
background:#d0dafd;
color:#339;
}
tbody tr:nth-child(even) {
  background:#e0eaff;
}
</style>
</head>
<body>
<table>
EOS
    # @!visibility private
    HTMLFOOTER = <<-EOS
</tbody>
</table>
<p>#COUNT# rows</p>
</body>
</html>
EOS
    def open_file
      @file << HTMLHEADER.gsub('#FILENAME#', @filename)
    end

    def header
      return if @header.nil? || @header.empty?
      @file << '<thead><tr>'
      @file << @header.map { |f| '<th>' + f + '</th>' }.join
      @file << "</tr></thead>\n<tbody>\n"
      @tbody = true
    end

    def write_row(row)
      unless @tbody
        @file << "<tbody>\n"
        @tbody = true
      end
      @file << '<tr>'
      @file << row.map { |f| '<td>' + CGI.escapeHTML(f.to_s) + '</td>' }.join
      @file << "</tr>\n"
    end

    def footer
      @file << HTMLFOOTER.gsub('#COUNT#', @rowcount.to_s)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
docparser-0.1.3 lib/docparser/output/html_output.rb
docparser-0.1.2 lib/docparser/output/html_output.rb
docparser-0.1.1 lib/docparser/output/html_output.rb
docparser-0.1.0 lib/docparser/output/html_output.rb