class TableData::Presenters::HTML

Public Instance Methods

html_foot() click to toggle source
# File lib/tabledata/presenters/html.rb, line 21
      def html_foot
        <<-EOHTML

      </tbody>
    </table>
  </body>
</html>
        EOHTML
      end
html_head() click to toggle source
# File lib/tabledata/presenters/html.rb, line 9
      def html_head
        <<-EOHTML
<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
  </head>
  <body>
    <table>
        EOHTML
      end
html_table_header() click to toggle source
# File lib/tabledata/presenters/html.rb, line 31
def html_table_header
  if @table.headers?
    "      <thead>\n        <tr>\n"+
      @table.headers.map { |cell|"          <th>#{CGI.escapeHTML(cell)}</th>" }.join("\n")+
      "\n        </tr>\n      </thead>\n"
  else
    ''
  end
end
string(options=nil) click to toggle source
# File lib/tabledata/presenters/html.rb, line 41
def string(options=nil)
  html_head+
    html_table_header+
    "      </body>\n"+
    @table.body.map { |row|
      "        <tr>\n"+row.map { |cell| "          <td>#{CGI.escapeHTML(cell)}</td>" }.join("\n")+"\n        </tr>"
    }.join("\n")+
    html_foot
end
write(path, options=nil) click to toggle source
# File lib/tabledata/presenters/html.rb, line 51
def write(path, options=nil)
  File.write(path, string, encoding: 'utf-8')
end