rails-exporter 0.0.10 → 0.0.11

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
2
  SHA1:
3
- metadata.gz: d0f950a9074e7a06cd6e77a646d341e97bf06ee1
4
- data.tar.gz: 33c196aff9aded0e6812896056be1fb03eafa4b2
3
+ metadata.gz: 1d1230f2b09a65e5db6ad197f70c45eb8cd2f3ca
4
+ data.tar.gz: a09035502c85a8ba441d78fa7cd079cddbd4ea3c
5
5
  SHA512:
6
- metadata.gz: 43eada81f947314141d5c7b64d3758e1678a06a1cbe21ee4469ffad363583f152cb71190f4ef4684448c828acbb5e994bbe1b3cdbd8e49e9970edfc91444c47a
7
- data.tar.gz: 97786c7f1b0a9950a2247154a462eb64b4652c05e6839d4fef4496544c1dd25d1403ae8e907f4648fdf49b82207833d8093deba7a9d0a3d860edc9f4414ea5aa
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
@@ -1,6 +1,9 @@
1
1
  en:
2
2
  exporters:
3
3
  spreadsheet_name: 'Spreadsheet'
4
+ time_format: "%I:%M %P"
5
+ date_format: "%m/%d/%Y"
6
+ datetime_format: "%m/%d/%Y, %I:%M %P"
4
7
  example:
5
8
  name: 'Name'
6
9
  another_example:
@@ -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
- (I18n.l(value, format: '%d/%m/%Y') rescue value).to_s
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
- (I18n.l(value, format: '%d/%m/%Y %H:%i:%s') rescue value).to_s
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
 
@@ -1,3 +1,3 @@
1
1
  module RailsExporter
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
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.10
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-02-23 00:00:00.000000000 Z
11
+ date: 2017-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails