Class | Ruport::Renderer |
In: |
lib/ruport/renderer.rb
|
Parent: | Object |
format | [RW] | The name of format being used. |
formatter | [W] | The formatter object being used. |
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}
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
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.
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.