Class: Tabledata::Presenters::HTML

Inherits:
Tabledata::Presenter show all
Defined in:
lib/tabledata/presenters/html.rb

Instance Attribute Summary

Attributes inherited from Tabledata::Presenter

#options, #table, #tables

Instance Method Summary collapse

Methods inherited from Tabledata::Presenter

add_presenter!, #initialize, #multiple_tables?, present, presenter_exists?, replace_presenter!, #single_table?, #write

Constructor Details

This class inherits a constructor from Tabledata::Presenter

Instance Method Details

#html_footObject


20
21
22
23
24
25
# File 'lib/tabledata/presenters/html.rb', line 20

def html_foot
  "</body>\n</html>\n"
end

#html_headObject


9
10
11
12
13
14
15
16
17
18
# File 'lib/tabledata/presenters/html.rb', line 9

def html_head
  "<!DOCTYPE html>\n<html>\n<head>\n<meta charset='utf-8'>\n</head>\n<body>\n"
end

#html_table_headerObject


27
28
29
30
31
32
33
34
35
36
# File 'lib/tabledata/presenters/html.rb', line 27

def html_table_header
  if @table.headers?
    "    <table>\n" +
    "      <thead>\n        <tr>\n"+
      @table.headers.map { |cell|"          <th>#{CGI.escapeHTML(cell)}</th>" }.join("\n")+
      "\n        </tr>\n      </thead>\n"
  else
    "    <table>\n"
  end
end

#string(options = nil) ⇒ Object


52
53
54
# File 'lib/tabledata/presenters/html.rb', line 52

def string(options=nil)
  table_html
end

#table_html(table) ⇒ Object


42
43
44
45
46
47
48
49
50
# File 'lib/tabledata/presenters/html.rb', line 42

def table_html(table)
  html_table_header+
    "      <tbody>\n"+
    table.body.map { |row|
      "        <tr>\n"+row.map { |cell| "          <td>#{CGI.escapeHTML(cell)}</td>" }.join("\n")+"\n        </tr>\n"
    }.join("")+
    "      </tbody>\n"+
    "    </table>\n"
end

#tables_htmlObject


38
39
40
# File 'lib/tabledata/presenters/html.rb', line 38

def tables_html
  html_head+tables.map { |table| table_html(table) }.join('')+html_foot
end