useful_renderers 0.0.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 052525cae9cdad31791505f22efa0f7691bdb478
4
- data.tar.gz: f09e2434dfd4479b8fa5a4ac5235444d3bfe32e3
2
+ SHA256:
3
+ metadata.gz: bf5f74912ea017f010e6bee5399c8f518681cd17d8418d74c84eef861d34b390
4
+ data.tar.gz: 06d2801f99a0e34c4d3104cbae3cb75e8ae2a26bcf7028a73b27060ba55a1436
5
5
  SHA512:
6
- metadata.gz: 063914d17ef64632809b6dbb112b815dd9c778414e2e6c47e3ca31f6b2444599b9ddc10c0d11470a2d36e388bfb01ccffbe87655f66b84b7fa84afc3fd7adfec
7
- data.tar.gz: 7769766bc1df9221900ed860b30dfbfda07981b8c57e7b162fc515a1d0dea87ec8c6bc5663a29a7586f964ecc187ffb9daa8c587c645806eede178fb90439ee7
6
+ metadata.gz: c02d2b98c06246bd75cf71568426cf02d7e9b7e6d664bad4175963a5fd519026b42812cd93b916f69c2e9462382ac8dc254b81672c6cf03d94e6edb4dedb04b2
7
+ data.tar.gz: 161b7daf08ff1cdc47dd99b566deed06faeec2c4e3534acac0810f18098a50cb1076a01f6c5498c43c99adb6a6aeadab1998f3f7bc7276d936d3d5657bbeedb4
data/.gitignore CHANGED
@@ -1,7 +1,7 @@
1
1
  .DS_Store
2
2
  /.bundle/
3
3
  /.yardoc
4
- /Gemfile.lock
4
+ Gemfile.lock
5
5
  /_yardoc/
6
6
  /coverage/
7
7
  /doc/
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # UsefulRenderers
2
2
 
3
- <!-- [![Build Status](https://travis-ci.org/beerlington/render_csv.png?branch=master)](https://travis-ci.org/beerlington/render_csv)
4
- [![Gem Version](https://badge.fury.io/rb/render_csv.png)](http://badge.fury.io/rb/render_csv)
5
- [![Code Climate](https://codeclimate.com/github/beerlington/render_csv.png)](https://codeclimate.com/github/beerlington/render_csv)
6
- [![Dependency Status](https://gemnasium.com/beerlington/render_csv.png)](https://gemnasium.com/beerlington/render_csv)
7
- -->
3
+ [![Gem Version](https://badge.fury.io/rb/useful_renderers.svg)](http://badge.fury.io/rb/useful_renderers)
4
+ [![Code Climate](https://codeclimate.com/github/blueberryapps/useful_renderers/badges/gpa.svg)](https://codeclimate.com/github/blueberryapps/useful_renderers)
5
+ [![Dependency Status](https://gemnasium.com/blueberryapps/useful_renderers.svg)](https://gemnasium.com/blueberryapps/useful_renderers)
6
+
8
7
  Rails renderers
9
8
 
10
9
  - CSV renderer for ActiveRecord collections
@@ -84,30 +83,24 @@ end
84
83
 
85
84
  ```ruby
86
85
  respond_to do |format|
87
- format.csv { render csv: @locations, only: [:address, :zip] }
86
+ format.csv { render csv: @locations, only: [:address, :zip, 'country.state'] }
88
87
  end
89
88
  ```
90
89
 
91
- ### Add methods as columns
92
-
93
- ```ruby
94
- respond_to do |format|
95
- format.csv { render csv: @locations, add_methods: [:method1, :method2] }
96
- end
97
- ```
90
+ ### Translate headers
98
91
 
99
- ### Add methods as columns and exclude columns
92
+ Using `Class.human_attribute_name(column_name)`
100
93
 
101
94
  ```ruby
102
95
  respond_to do |format|
103
- format.csv { render csv: @locations, except: [:id], add_methods: [:method1, :method2] }
96
+ format.csv { render csv: @locations, translate: true }
104
97
  end
105
98
  ```
106
99
 
107
100
 
108
101
  ## Contributing
109
102
 
110
- 1. Fork it ( https://github.com/[my-github-username]/useful_renderers/fork )
103
+ 1. Fork it ( https://github.com/blueberryapps/useful_renderers/fork )
111
104
  2. Create your feature branch (`git checkout -b my-new-feature`)
112
105
  3. Commit your changes (`git commit -am 'Add some feature'`)
113
106
  4. Push to the branch (`git push origin my-new-feature`)
@@ -11,14 +11,14 @@ module UsefulRenderers
11
11
  filename = options[:filename] || options[:template]
12
12
  csv.extend UsefulRenderers::CsvRenderable
13
13
  data = csv.respond_to?(:to_csv) ? csv.to_csv(options) : csv
14
- send_data data, type: Mime::CSV, disposition: "attachment; filename=#{filename}.csv"
14
+ send_data data, type: Mime[:csv], disposition: "attachment; filename=#{filename}.csv"
15
15
  end
16
16
 
17
- ActionController.add_renderer :zip do |csv, options|
17
+ ActionController.add_renderer :zip do |zip, options|
18
18
  filename = options[:filename] || options[:template]
19
- csv.extend UsefulRenderers::ZipRenderable
20
- data = csv.respond_to?(:to_zip) ? csv.to_csv(options) : csv
21
- send_data data, type: Mime::Zip, disposition: "attachment; filename=#{filename}.zip"
19
+ zip.extend UsefulRenderers::ZipRenderable
20
+ data = zip.respond_to?(:to_zip) ? zip.to_zip(options) : zip
21
+ send_data data, type: 'application/zip', disposition: "attachment; filename=#{filename}.zip"
22
22
  end
23
23
 
24
24
  end
@@ -5,25 +5,17 @@ module UsefulRenderers
5
5
 
6
6
  # Converts an array to CSV formatted string
7
7
  # Options include:
8
- # :only => [:col1, :col2] # Specify which columns to include
8
+ # :only => [:col1, :col2] # Specify which columns to include
9
9
  # :except => [:col1, :col2] # Specify which columns to exclude
10
- # :add_methods => [:method1, :method2] # Include addtional methods that aren't columns
10
+ # :translate => boolean # Translate headers
11
11
 
12
12
  def to_csv(options = {})
13
13
  klass = first.class
14
14
  return '' if empty?
15
15
  return join(',') unless klass.respond_to? :column_names
16
16
 
17
- columns = klass.column_names
18
- if options[:only]
19
- columns = []
20
- options[:only].each do |method|
21
- columns << method.to_s if first.respond_to?(method)
22
- end
23
- end
24
-
25
- columns -= options[:except].map(&:to_s) if options[:except]
26
- columns += options[:add_methods].map(&:to_s) if options[:add_methods]
17
+ columns = options[:only] ? options[:only].map(&:to_s) : klass.column_names
18
+ columns -= options[:except].map(&:to_s) if options[:except]
27
19
 
28
20
  headers = columns.dup
29
21
  headers.map!{|col| klass.human_attribute_name col } if options[:translate]
@@ -36,7 +28,9 @@ module UsefulRenderers
36
28
 
37
29
  CSV.generate(csv_options) do |row|
38
30
  self.each do |obj|
39
- row << columns.map { |c| obj.send(c) }
31
+ row << columns.map do |column|
32
+ column.to_s.split('.').inject(obj) { |o, m| o.try(m) }
33
+ end
40
34
  end
41
35
  end
42
36
  end
@@ -1,3 +1,3 @@
1
1
  module UsefulRenderers
2
- VERSION = "0.0.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'rails', '>= 3.0'
21
+ spec.add_dependency 'rails', '>= 5.0'
22
22
  spec.add_dependency 'rubyzip', '>= 1.0.0'
23
23
 
24
24
  spec.add_development_dependency 'rspec-rails', '>= 2.12'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: useful_renderers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondrej Bartas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-04 00:00:00.000000000 Z
11
+ date: 2020-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubyzip
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -139,7 +139,7 @@ homepage: ''
139
139
  licenses:
140
140
  - MIT
141
141
  metadata: {}
142
- post_install_message:
142
+ post_install_message:
143
143
  rdoc_options: []
144
144
  require_paths:
145
145
  - lib
@@ -154,9 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubyforge_project:
158
- rubygems_version: 2.2.2
159
- signing_key:
157
+ rubygems_version: 3.0.1
158
+ signing_key:
160
159
  specification_version: 4
161
160
  summary: Adds a custom CSV and ZIP renderer to Rails applications
162
161
  test_files: