Class Ruport::Renderer
In: lib/ruport/renderer.rb
Parent: Object

This class implements the core renderer for Ruport‘s formatting system. It is designed to implement the low level tools necessary to build report renderers for different kinds of tasks. See Renderer::Table for a tabular data renderer.

Methods

build   data   data=   finalize   formats   formatter   io=   method_missing   option   options   options   prepare   render   required_option   stage  

Included Modules

AutoRunner

Classes and Modules

Module Ruport::Renderer::Hooks
Class Ruport::Renderer::Options

Attributes

format  [RW]  The name of format being used.
formatter  [W]  The formatter object being used.

Public Class methods

Creates a new instance of the renderer and sets it to use the specified formatter (by name). If a block is given, the renderer instance is yielded.

Returns the renderer instance.

Registers a hook to look for in the Formatter object when the render() method is called.

Usage:

  class MyRenderer < Ruport::Renderer
     # other details omitted...
     finalize :apple
  end

  class MyFormatter < Ruport::Formatter
     renders :example, :for => MyRenderer

     # other details omitted...

     def finalize_apple
        # this method will be called when MyRenderer tries to render
        # the :example format
     end
  end

 If a formatter does not implement this hook, it is simply ignored.

Lists the formatters that are currently registered on a renderer, as a hash keyed by format name.

Example:

  >> Ruport::Renderer::Table.formats
  => {:html=>Ruport::Formatter::HTML,
  ?>  :csv=>Ruport::Formatter::CSV,
  ?>  :text=>Ruport::Formatter::Text,
  ?>  :pdf=>Ruport::Formatter::PDF}

Provides a shortcut to render() to allow render(:csv) to become render_csv

Defines attribute writers for the Renderer::Options object shared between Renderer and Formatter.

usage:

  class MyRenderer < Ruport::Renderer
     option :font_size, :font_style
     # other details omitted
  end

Allows you to set class-wide default options.

Example:

 options { |o| o.style = :justified }

Registers a hook to look for in the Formatter object when the render() method is called.

Usage:

  class MyRenderer < Ruport::Renderer
     # other details omitted...
     prepare :apple
  end

  class MyFormatter < Ruport::Formatter
     renders :example, :for => MyRenderer

     def prepare_apple
        # this method will be called when MyRenderer tries to render
        # the :example format
     end

     # other details omitted...
  end

 If a formatter does not implement this hook, it is simply ignored.

Builds up a renderer object, looks up the appropriate formatter, sets the data and options, and then does the following process:

  * If the renderer contains a module Helpers, mix it in to the instance.
  * If a block is given, yield the Renderer instance.
  * If a setup() method is defined on the Renderer, call it.
  * If the renderer has defined a run() method, call it. Otherwise,
    include Renderer::AutoRunner (you usually won't need a run() method).
  * Call _run_ if it exists (this is provided by default, by AutoRunner).
  * If the :file option is set to a file name, appends output to the file.
  * Return the results of formatter.output

Note that the only time you will need a run() method is if you can‘t do what you need to via a helpers module or via setup()

Please see the examples/ directory for custom renderer examples, because this is not nearly as complicated as it sounds in most cases.

Defines attribute writers for the Renderer::Options object shared between Renderer and Formatter. Will throw an error if the user does not provide values for these options upon rendering.

usage:

  class MyRenderer < Ruport::Renderer
     required_option :employee_name, :address
     # other details omitted
  end

Registers hooks to look for in the Formatter object when the render() method is called.

Usage:

  class MyRenderer < Ruport::Renderer
     # other details omitted...
     stage :apple,:banana
  end

  class MyFormatter < Ruport::Formatter
     renders :example, :for => MyRenderer

     def build_apple
        # this method will be called when MyRenderer tries to render
        # the :example format
     end

     def build_banana
        # this method will be called when MyRenderer tries to render
        # the :example format
     end

     # other details omitted...
  end

 If a formatter does not implement these hooks, they are simply ignored.

Public Instance methods

The data that has been passed to the active formatter.

Sets data attribute on the active formatter.

Returns the active formatter.

If a block is given, it is evaluated in the context of the formatter.

If an IO object is given, Formatter#output will use it instead of the default String. For Ruport‘s core renderers, we technically can use any object that supports the << method, but it‘s meant for IO objects such as File or STDOUT

Renderer::Options object which is shared with the current formatter.

[Validate]