README.md in csb-0.4.0 vs README.md in csb-0.5.0
- old
+ new
@@ -3,10 +3,17 @@
# Csb
A simple and streaming support CSV template engine for Ruby on Rails.
+## Features
+
+- Support for streaming downloads
+- Output in UTF-8 with BOM
+- Readable code
+- High testability
+
## Usage
### Template handler
In app/controllers/reports_controller.rb:
@@ -19,13 +26,17 @@
In app/views/reports/index.csv.csb:
```ruby
csv.items = @reports
+
# When there are many records
# csv.items = @reports.find_each
+# When there are many records with decorator
+# csv.items = @reports.find_each.lazy.map(&:decorate)
+
# csv.filename = "reports_#{Time.current.to_i}.csv"
# csv.streaming = false
csv.cols.add('Update date') { |r| l(r.updated_at.to_date) }
csv.cols.add('Categories') { |r| r.categories.pluck(:name).join(' ') }
@@ -66,11 +77,11 @@
csv.items = @articles
csv.cols = Article.csb_cols
# Your Model
def self.csb_cols
- Csb.cols.new do |cols|
+ Csb::Cols.new do |cols|
cols.add('Update date') { |r| I18n.l(r.updated_at.to_date) }
cols.add('Categories') { |r| r.categories.pluck(:name).join(' ') }
cols.add('Title', :title)
end
end
@@ -80,9 +91,15 @@
expect(Article.csb_cols.col_pairs(article)).to eq [
['Update date', '2020-01-01'],
['Categories', 'test rspec'],
['Title', 'Testing'],
+]
+
+expect(Article.csb_cols.as_table(articles)).to eq [
+ ['Update date', 'Categories', 'Title'],
+ ['2020-01-01', 'test rspec', 'Testing'],
+ ['2020-02-01', 'rails gem', 'Rails 6.2'],
]
```
## Installation