Ruport::Formatter::HTML

This class produces HTML output for Ruport's Row, Table, Group, and Grouping renderers. It can be subclassed, as it has some helper methods that might be useful for custom output.

Rendering Options

:show_table_headers True by default

:show_group_headers True by default

:style Used for grouping (:inline, :justified)

Public Instance Methods

apply_template() click to toggle source

Hook for setting available options using a template. See the template documentation for the available options and their format.

# File lib/ruport/formatter/html.rb, line 35
def apply_template
  apply_table_format_template(template.table_format)
  apply_grouping_format_template(template.grouping_format)
end
build_group_body() click to toggle source

Creates the group body. Since group data is a table, just uses the Table renderer.

# File lib/ruport/formatter/html.rb, line 84
def build_group_body
  render_table data, options.to_hash
end
build_group_header() click to toggle source

Renders the header for a group using the group name.

# File lib/ruport/formatter/html.rb, line 77
def build_group_header
  output << "\t<p>#{data.name}</p>\n"
end
build_grouping_body() click to toggle source

Generates the body for a grouping. Iterates through the groups and renders them using the group renderer.

# File lib/ruport/formatter/html.rb, line 91
def build_grouping_body
  case style
  when :inline
    render_inline_grouping(options)
  when :justified
    render_justified_grouping
  end
end
build_row() click to toggle source

Renders individual rows for the table.

# File lib/ruport/formatter/html.rb, line 68
def build_row
  output <<
    "\t\t<tr>\n\t\t\t<td>" +
    data.to_a.join("</td>\n\t\t\t<td>") +
    "</td>\n\t\t</tr>\n"
end
build_table_body() click to toggle source

Uses the Row renderer to build up the table body. Replaces nil and empty strings with "&nbsp;"

# File lib/ruport/formatter/html.rb, line 55
def build_table_body
  render_data_by_row do |rend|
    r = rend.data
    rend.data = r.map { |e| e.to_s.empty? ? "&nbsp;" : e }
  end
end
build_table_header() click to toggle source

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.

# File lib/ruport/formatter/html.rb, line 44
def build_table_header
  output << "\t<table>\n"
  unless data.column_names.empty? || !show_table_headers
    output << "\t\t<tr>\n\t\t\t<th>" + 
      data.column_names.join("</th>\n\t\t\t<th>") + 
      "</th>\n\t\t</tr>\n"
  end
end
html_table() click to toggle source

Generates <table> tags enclosing the yielded content.

Example:

output << html_table { "<tr><td>1</td><td>2</td></tr>\n" }
#=> "<table>\n<tr><td>1</td><td>2</td></tr>\n</table>\n"
# File lib/ruport/formatter/html.rb, line 107
def html_table
  "<table>\n" << yield << "</table>\n"
end
textile(s) click to toggle source

Uses RedCloth to turn a string containing textile markup into HTML.

Example:

textile "*bar*" #=> "<p><strong>foo</strong></p>"
# File lib/ruport/formatter/html.rb, line 117
def textile(s)   
  require "redcloth"
  RedCloth.new(s).to_html   
rescue LoadError
  raise RuntimeError, "You need RedCloth!\n gem install RedCloth -v 3.0.3"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.