Class: Formatter::HTML

Inherits:
Formatter
  • Object
show all
Defined in:
app/formatters/html_formatter.rb

Instance Method Summary collapse

Instance Method Details

#build_group_headerObject

Renders the header for a group using the group name.



39
40
41
# File 'app/formatters/html_formatter.rb', line 39

def build_group_header
  output << "\t<p>#{safe(data.name)}</p>\n"
end

#build_row(data = self.data) ⇒ Object

Renders individual rows for the table.



30
31
32
33
34
35
# File 'app/formatters/html_formatter.rb', line 30

def build_row(data = self.data)
  output <<
    "\t\t<tr>\n\t\t\t<td>" +
    safe_join(data.to_a, "</td>\n\t\t\t<td>") +
    "</td>\n\t\t</tr>\n"
end

#build_table_headerObject

Generates table headers based on the column names of your Data::Table.

This method does not do anything if options.show_table_headers is false or the Data::Table has no column names.



20
21
22
23
24
25
26
27
# File 'app/formatters/html_formatter.rb', line 20

def build_table_header
  output << "\t<table>\n"
  unless data.column_names.empty? || !options.show_table_headers
    output << "\t\t<tr>\n\t\t\t<th>" + 
      safe_join(data.column_names, "</th>\n\t\t\t<th>") + 
      "</th>\n\t\t</tr>\n"
  end
end

#safe(val) ⇒ Object



6
7
8
9
# File 'app/formatters/html_formatter.rb', line 6

def safe(val)
  out = ERB::Util.html_escape(val.to_s)
  out.gsub("&amp;nbsp;", "&nbsp;")
end

#safe_join(array, sep) ⇒ Object



11
12
13
14
# File 'app/formatters/html_formatter.rb', line 11

def safe_join(array, sep)
  safe_array = array.collect{ |a| safe(a) }
  safe_array.join(sep)
end