Class: Ruport::Formatter::HTML
- Inherits:
-
Ruport::Formatter
- Object
- Ruport::Formatter
- Ruport::Formatter::HTML
- Defined in:
- lib/ruport/formatter/html.rb
Overview
This class produces HTML output for Ruport’s Row, Table, Group, and Grouping controllers. 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)
Instance Attribute Summary
Attributes inherited from Ruport::Formatter
Instance Method Summary collapse
-
#apply_template ⇒ Object
Hook for setting available options using a template.
-
#build_group_body ⇒ Object
Creates the group body.
-
#build_group_header ⇒ Object
Renders the header for a group using the group name.
-
#build_grouping_body ⇒ Object
Generates the body for a grouping.
-
#build_row(data = self.data) ⇒ Object
Renders individual rows for the table.
-
#build_table_body ⇒ Object
Uses the Row controller to build up the table body.
-
#build_table_footer ⇒ Object
Simply closes the table tag.
-
#build_table_header ⇒ Object
Generates table headers based on the column names of your Data::Table.
-
#html_table ⇒ Object
Generates <table> tags enclosing the yielded content.
-
#textile(s) ⇒ Object
Uses RedCloth to turn a string containing textile markup into HTML.
Methods inherited from Ruport::Formatter
build, #clear_output, #erb, formats, #method_missing, #output, renders, save_as_binary_file, #save_output, #template
Methods included from RenderingTools
#render_group, #render_grouping, #render_inline_grouping, #render_row, #render_table
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Ruport::Formatter
Instance Method Details
#apply_template ⇒ Object
Hook for setting available options using a template. See the template documentation for the available options and their format.
33 34 35 36 |
# File 'lib/ruport/formatter/html.rb', line 33 def apply_template apply_table_format_template(template.table) apply_grouping_format_template(template.grouping) end |
#build_group_body ⇒ Object
Creates the group body. Since group data is a table, just uses the Table controller.
76 77 78 |
# File 'lib/ruport/formatter/html.rb', line 76 def build_group_body render_table data, .to_hash end |
#build_group_header ⇒ Object
Renders the header for a group using the group name.
69 70 71 |
# File 'lib/ruport/formatter/html.rb', line 69 def build_group_header output << "\t<p>#{data.name}</p>\n" end |
#build_grouping_body ⇒ Object
Generates the body for a grouping. Iterates through the groups and renders them using the group controller.
83 84 85 86 87 88 89 90 |
# File 'lib/ruport/formatter/html.rb', line 83 def build_grouping_body case .style when :inline render_inline_grouping() when :justified render_justified_grouping end end |
#build_row(data = self.data) ⇒ Object
Renders individual rows for the table.
60 61 62 63 64 65 |
# File 'lib/ruport/formatter/html.rb', line 60 def build_row(data = self.data) 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 ⇒ Object
Uses the Row controller to build up the table body. Replaces nil and empty strings with “ ”
48 49 50 51 52 |
# File 'lib/ruport/formatter/html.rb', line 48 def build_table_body data.each do |row| build_row(row.map { |e| e.to_s.empty? ? " " : e }) end end |
#build_table_footer ⇒ Object
Simply closes the table tag.
55 56 57 |
# File 'lib/ruport/formatter/html.rb', line 55 def output << "\t</table>\n" end |
#build_table_header ⇒ Object
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.
42 43 44 |
# File 'lib/ruport/formatter/html.rb', line 42 def build_table_header output << build_header(.show_table_headers ? data.column_names : nil) end |
#html_table ⇒ Object
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"
99 100 101 |
# File 'lib/ruport/formatter/html.rb', line 99 def html_table "<table>\n" << yield << "</table>\n" end |
#textile(s) ⇒ Object
Uses RedCloth to turn a string containing textile markup into HTML.
Example:
textile "*bar*" #=> "<p><strong>foo</strong></p>"
109 110 111 112 113 114 |
# File 'lib/ruport/formatter/html.rb', line 109 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 |