Code Monkey home page Code Monkey logo

csv_builder's Introduction

= 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.

== 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.

csv_builder's People

Contributors

mocoso avatar defv avatar vidmantas avatar

Watchers

Geoffrey Ducharme avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.