Sha256: 34e32b9cbd49f26f34667ba468573825f9d658f0b23df1b3531f9c3dbfc3e5d7

Contents?: true

Size: 1.89 KB

Versions: 2

Compression:

Stored size: 1.89 KB

Contents

= CSV Builder

The CSV Builder Rails plugin provides a simple templating system for serving
dynamically generated CSV files from your application.


== Requirements

CSV Builder requires Rails v2.1.

It also depends upon the FasterCSV gem http://fastercsv.rubyforge.org,
which you can install with

  $ sudo gem install fastercsv

Encoding conversions are done with Iconv, so make sure you have it on your
development/production machine.

== Install

=== Install as gem (recommended)

Install as a gem:

  $ gem install csv_builder

Then add the gem dependency in your config:

  # config/environment.rb
  config.gem "csv_builder"


== Example

CSV template files are suffixed with '.csv.csvbuilder', for example
'index.csv.csvbuilder'

Add rows to your CSV file in the template by pushing arrays of columns into the
csv object.

   # First row
   csv << [ 'cell 1', 'cell 2' ]
   # Second row
   csv << [ 'another cell value', 'and another' ]
   # etc...

You can set the default filename for that a browser will use for 'save as' by
setting <tt>@filename</tt> instance variable in your controller's action method
e.g.

  @filename = 'report.csv'

You can set the input encoding and output encoding by setting
<tt>@input_encoding</tt> and <tt>@output_encoding</tt> instance variables.
These default to 'UTF-8' and 'LATIN1' respectively. e.g.

  @output_encoding = 'UTF-8'

You can set <tt>@csv_options</tt> instance variable to define options for
FasterCSV generator. For example:

  @csv_options = { :force_quotes => true, :col_sep => ';' }

You can also attach a csv file to mail sent out by your application by
including a snippet like the following in your mailer method

  attachment "text/csv" do |attachment|
    attachment.body = render(:file => 'example/index.csv.csvbuilder')
    attachment.filename = 'report.csv'
  end


Copyright (c) 2008 Econsultancy.com and 2009 Vidmantas Kabošis, released under
the MIT license.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
csv_builder-1.1.7 README.rdoc
csv_builder-0.1.6 README.rdoc