Module | Ruport::Renderer::Hooks |
In: |
lib/ruport/renderer.rb
|
This module provides hooks into Ruport‘s formatting system. It is used to implement the as() method for all of Ruport‘s data structures, as well as the renders_with and renders_as_* helpers.
You can actually use this with any data structure, it will look for a renderable_data(format) method to pass to the renderer you specify, but if that is not defined, it will pass self.
Examples:
# Render Arrays with Ruport's Row Renderer class Array include Ruport::Renderer::Hooks renders_as_row end # >> [1,2,3].as(:csv) # => "1,2,3\n" # Render Hashes with Ruport's Row Renderer class Hash include Ruport::Renderer::Hooks renders_as_row attr_accessor :column_order def renderable_data(format) column_order.map { |c| self[c] } end end # >> a = { :a => 1, :b => 2, :c => 3 } # >> a.column_order = [:b,:a,:c] # >> a.as(:csv) # => "2,1,3\n"
Uses the Renderer specified by renders_with to generate formatted output. Passes the return value of the renderable_data(format) method if the method is defined, otherwise passes self as :data
The remaining options are converted to a Renderer::Options object and are accessible in both the renderer and formatter.
Example: table.as(:csv, :show_table_headers => false)