rails-exporter 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/config/locales/exporters.en.yml +3 -0
- data/lib/rails_exporter/exporter.rb +9 -4
- data/lib/rails_exporter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d1230f2b09a65e5db6ad197f70c45eb8cd2f3ca
|
4
|
+
data.tar.gz: a09035502c85a8ba441d78fa7cd079cddbd4ea3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b09006248b1ec00a72a9b70d77230d41fc7940d08ac6c941e58b54b1b27b22367dc7d4ee01452145c752c08ea7922cdb09aae4cd9acac0b3f55cba410d7f6f46
|
7
|
+
data.tar.gz: 7ac22910f3524f86f628caf26fecc4929963d33e4ef4e36f9387928f2238a3cb3049733135c327dca2d2ecee0391ffe7a3897de1792dfaf0106142fa2ee41666
|
data/README.md
CHANGED
@@ -33,6 +33,7 @@ class ExampleExporter < RailsExporter::Base
|
|
33
33
|
column :email
|
34
34
|
column :price => :currency
|
35
35
|
column :is_admin => :boolean
|
36
|
+
column :any_time => :time
|
36
37
|
column :birthday => :date
|
37
38
|
column :created_at => :datetime
|
38
39
|
column(:account) {|record| record.account.name}
|
@@ -60,6 +61,19 @@ You can call `export_to` from **Array** or **ActiveRecord::Relation** objects:
|
|
60
61
|
records.export_to(:xml) # or MyModelExporter.export_to_xml(records)
|
61
62
|
```
|
62
63
|
|
64
|
+
### Avaliable Types
|
65
|
+
|
66
|
+
You can call `RailsExporter::Base.file_types` to list all supported file types:
|
67
|
+
```ruby
|
68
|
+
RailsExporter::Base.file_types.each do |type|
|
69
|
+
puts type
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
### I18n Configuration
|
74
|
+
|
75
|
+
Modify you `config/locales/exporters.en.yml`
|
76
|
+
|
63
77
|
### Controller Example
|
64
78
|
|
65
79
|
```erb
|
@@ -76,6 +90,7 @@ class UsersController < ApplicationController
|
|
76
90
|
end
|
77
91
|
end
|
78
92
|
```
|
93
|
+
### MimeTypes
|
79
94
|
|
80
95
|
Declare XLS as a new mimetype in `config/initializers/mime_types`:
|
81
96
|
```erb
|
@@ -84,7 +84,7 @@ module RailsExporter
|
|
84
84
|
#ROWS
|
85
85
|
records.each_with_index do |record, row_index|
|
86
86
|
values = get_values(record, context)
|
87
|
-
values.each_with_index{|value, col_index| worksheet.add_cell(row_index+1, col_index, value)
|
87
|
+
values.each_with_index {|value, col_index| worksheet.add_cell(row_index+1, col_index, value)}
|
88
88
|
end
|
89
89
|
#RETURN STRING
|
90
90
|
workbook.stream.string.force_encoding('binary')
|
@@ -116,12 +116,17 @@ module RailsExporter
|
|
116
116
|
ActionController::Base.helpers.number_to_currency(value)
|
117
117
|
elsif type==:boolean
|
118
118
|
(value==true or value=='true' or value=='1') ? 'S' : 'N'
|
119
|
+
elsif type==:time
|
120
|
+
locale_format = I18n.t(:time_format, default: ['%H:%M:%S'], scope: [:exporters])
|
121
|
+
(I18n.l(value, format: locale_format) rescue value).to_s
|
119
122
|
elsif type==:date
|
120
|
-
|
123
|
+
locale_format = I18n.t(:date_format, default: ['%d/%m/%Y'], scope: [:exporters])
|
124
|
+
(I18n.l(value, format: locale_format) rescue value).to_s
|
121
125
|
elsif type==:datetime
|
122
|
-
|
126
|
+
locale_format = I18n.t(:datetime_format, default: ['%d/%m/%Y %H:%M:%S'], scope: [:exporters])
|
127
|
+
(I18n.l(value, format: locale_format) rescue value).to_s
|
123
128
|
else
|
124
|
-
(I18n.l(value) rescue value)
|
129
|
+
(I18n.l(value) rescue value).to_s
|
125
130
|
end
|
126
131
|
end
|
127
132
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-exporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Porto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|