Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cbuilder

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cbuilder

  • 0.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

cbuilder

Build Status

Cbuilder is an ultralight (< 100 LOC) CSV builder/template handler inspired by dhh's excellent Jbuilder. The goal is a simple DSL for creating CSV files that's better than creating massive custom arrays.

If you're doing any more than 4-5 columns, generating CSV files can be a real pain. God forbid you're not simply outputting the attributes of a simple array, and need helpers or other niceties.

You don't need to re-invent the wheel with CSV. Cbuilder weighs in at less than 100 LOC.

Have you ever found yourself doing this?

  Customer Name,Products Purchased, Product Names
  <% @orders.each do |order|%>
  <%= order.customer.name %>,<%= products_count(order) %>,<%= product_names(order.products) %>,...
  <% end %>

What if you could do this instead?

  Cbuilder.encode do |csv|
    csv.set_collection!(@orders) do |order|
      csv.col 'Customer Name',        order.customer.name
      csv.col 'Products Purchased',   products_count(order)
      csv.col 'Product Names',        product_names(order.products)
    end
  end

Installation

Add this line to your application's Gemfile:

gem 'cbuilder'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cbuilder

Usage

Just drop into your Rails Gemfile and start adding templates with *.csv.cbuilder.

If you'd like the CSV to be downloaded as an attachment, add the following to your controller action:

  response.headers["Content-Disposition"] = 'attachment; filename="my_spreadsheet.csv'

TODO

  • Test Ruby 1.8 support
  • Test use as a partial

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Credits

http://i.imgur.com/Jd7pg.jpg

Cbuilder was built by Craft Coffee

FAQs

Package last updated on 14 Oct 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc