Wednesday, August 5, 2009

ODF-REPORT

Gem for generating .odt files by making strings substitution in a previously created .odt file.

gem install sandrods-odf-report --source=http://gems.github.com

Usage:

Step 1 - the template

First of all, you need to create a .odt file to serve as a template

Templates are normal .odt files with placeholders for Substitutions

There are two kinds of substitutions available: fields and tables

Fields placeholders

It’s just an upcase sentence, surrounded by brackets. It will be replaced for wathever value you supply.

In the folowing example:

report = ODFReport.new("Users/john/my_template.odt") do |r|

r.add_field :user_name, @user.name
r.add_field :address, "My new address"

end

All occurences of [USER_NAME] found in the file will be replaced by the value of @user.name whereas all [ADDRESS] ’es will contains My new address

It’s as simple as that.

http://github.com/sandrods/odf-report/tree/master

No comments: