csv_shaper 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 1.9.3
data/README.md CHANGED
@@ -4,6 +4,8 @@ Beautiful DSL for creating CSV output in Ruby & Rails.
4
4
 
5
5
  Creating CSV files in Ruby is painful! CSV Shaper makes life easier! It's ideal for converting database backed models with attrbiutes into CSV output. It can be used without Rails, but works great with ActiveRecord models and even comes with support for it's own template handling.
6
6
 
7
+ [![Build Status](https://secure.travis-ci.org/paulspringett/csv_shaper.png?branch=master)](http://travis-ci.org/paulspringett/csv_shaper)
8
+
7
9
  ### Example Usage
8
10
 
9
11
  ```ruby
@@ -50,11 +52,15 @@ csv_string = CsvShaper::Shaper.encode do |csv|
50
52
  end
51
53
  ```
52
54
 
53
- If you're using it in Rails 3.0+ you are already inside the block so you can just call the `csv` object.
55
+ ### Usage in Rails 3.0+
56
+
57
+ If you're using it in Rails 3.0+ you are already inside the `encode` block so you can just call the `csv` object directly.
54
58
 
55
59
  Create a Rails view, set the content-type to `csv` and the handler to `shaper`, like so
56
60
 
57
61
  index.csv.shaper
62
+
63
+ then just start defining your headers and rows as per the examples.
58
64
 
59
65
  ### Headers
60
66
 
@@ -142,4 +148,50 @@ csv.rows @users do |csv, user|
142
148
  end
143
149
  ```
144
150
 
151
+ ### Don't worry about missing cells
152
+
153
+ There's no need to pad missing cells with `nil`
154
+
155
+ This Ruby code will produce the CSV output below
156
+
157
+ ```ruby
158
+ csv.headers :name, :age, :gender
159
+
160
+ csv.row do |csv|
161
+ csv.cell :name, 'Paul'
162
+ # no age cell
163
+ csv.cell :gender, 'M'
164
+ end
165
+
166
+ csv.row do |csv|
167
+ csv.cell :name 'Joe'
168
+ csv.cell :age, 34
169
+ # no gender cell
170
+ end
171
+ ```
172
+
173
+ ```
174
+ Name,Age,Gender
175
+ Paul,,M
176
+ Joe,34,
177
+ ```
178
+
179
+ ### Further Rails integration
180
+
181
+ Customise the filename of the CSV download by defining a `@filename` instance variable in your controller action.
182
+
183
+ ```ruby
184
+ respond_to :html, :csv
185
+
186
+ def index
187
+ @users = User.all
188
+ @filename = "All users - #{Date.today.to_formatted_s(:db)}.csv"
189
+ end
190
+ ```
191
+
192
+ ##### Hat tips
193
+
194
+ * [Jbuilder](https://github.com/rails/jbuilder/) for inspiration for the DSL
195
+ * [CSV Builder](https://github.com/econsultancy/csv_builder) for headers and custom filenames
196
+
145
197
  Copyright (c) Paul Springett 2012
data/Rakefile CHANGED
@@ -3,3 +3,5 @@ require 'bundler/gem_tasks'
3
3
 
4
4
  require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new('spec')
6
+
7
+ task default: :spec
data/csv_shaper.gemspec CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |gem|
23
23
  gem.version = CsvShaper::VERSION
24
24
 
25
25
  gem.add_dependency 'activesupport', '>= 3.0.0'
26
-
27
26
  gem.add_development_dependency 'rspec'
27
+ gem.add_development_dependency 'rake'
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module CsvShaper
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/csv_shaper.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'blankslate'
2
1
  require 'active_support/ordered_hash'
3
2
  require 'active_support/inflector'
4
3
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_shaper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70296967507100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: 3.0.0
24
+ version_requirements: *70296967507100
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: rspec
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70296967506200 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,12 +32,18 @@ dependencies:
37
32
  version: '0'
38
33
  type: :development
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
35
+ version_requirements: *70296967506200
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70296967505200 !ruby/object:Gem::Requirement
41
39
  none: false
42
40
  requirements:
43
41
  - - ! '>='
44
42
  - !ruby/object:Gem::Version
45
43
  version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70296967505200
46
47
  description: ! "\n Creating CSV files in Ruby is painful! CSV Shaper makes life
47
48
  easier! It's\n ideal for converting database backed models with attrbiutes into
48
49
  CSV output.\n It can be used without Rails, but works great with ActiveRecord
@@ -54,6 +55,7 @@ extensions: []
54
55
  extra_rdoc_files: []
55
56
  files:
56
57
  - .gitignore
58
+ - .travis.yml
57
59
  - Gemfile
58
60
  - LICENSE
59
61
  - README.md
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  version: '0'
93
95
  requirements: []
94
96
  rubyforge_project:
95
- rubygems_version: 1.8.23
97
+ rubygems_version: 1.8.16
96
98
  signing_key:
97
99
  specification_version: 3
98
100
  summary: Beautiful DSL for creating CSV output in Ruby & Rails