spreadsheet_architect 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/spreadsheet_architect.rb +11 -10
- data/lib/spreadsheet_architect/action_controller_renderers.rb +12 -2
- data/lib/spreadsheet_architect/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 155a653969b09467dd11207dee1a4b4a208b316b
|
4
|
+
data.tar.gz: d7c94501ad36264f26e9285d21ebef0546e89067
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c801aa14de7c5f8c10b7c20aaecb59cb50fbf956ef7a59cccd8e04c3d9cc69ad1773254b296e90c96c786a1c8e387eb49586106a681416a9e7fa7b1941c7978f
|
7
|
+
data.tar.gz: 0732d0406412a5aec37a37c2558a3bce488fa66c5118d08893bdac9d5dac242d9142a7bb8f5112f16e071115702f05c818f96fedbaaa1deb37026477420daf38
|
data/README.md
CHANGED
@@ -107,7 +107,7 @@ end
|
|
107
107
|
|
108
108
|
**header_style** - *Hash* - Default: `{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`
|
109
109
|
|
110
|
-
**row_style** - Hash - Default: `{background_color:
|
110
|
+
**row_style** - Hash - Default: `{background_color: nil, color: "FFFFFF", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`
|
111
111
|
|
112
112
|
### to_ods
|
113
113
|
**sheet_name** - *String*
|
@@ -12,7 +12,7 @@ module SpreadsheetArchitect
|
|
12
12
|
|
13
13
|
module ClassMethods
|
14
14
|
def sa_str_humanize(str, capitalize = true)
|
15
|
-
str = str.sub(/\A_+/, '').
|
15
|
+
str = str.sub(/\A_+/, '').gsub(/[_\.]/,' ').sub(' rescue nil','')
|
16
16
|
if capitalize
|
17
17
|
str = str.gsub(/(\A|\ )\w/){|x| x.upcase}
|
18
18
|
end
|
@@ -21,8 +21,9 @@ module SpreadsheetArchitect
|
|
21
21
|
|
22
22
|
def sa_get_options(options={})
|
23
23
|
if self.ancestors.include?(ActiveRecord::Base) && !self.respond_to?(:spreadsheet_columns) && !options[:spreadsheet_columns]
|
24
|
-
|
25
|
-
|
24
|
+
the_column_names = (self.column_names - ["id","created_at","updated_at","deleted_at"])
|
25
|
+
headers = the_column_names.map{|x| sa_str_humanize(x)}
|
26
|
+
columns = the_column_names.map{|x| x.to_s}
|
26
27
|
elsif options[:spreadsheet_columns] || self.respond_to?(:spreadsheet_columns)
|
27
28
|
headers = []
|
28
29
|
columns = []
|
@@ -50,11 +51,9 @@ module SpreadsheetArchitect
|
|
50
51
|
header_style.merge!(options[:header_style])
|
51
52
|
elsif options[:header_style] == false
|
52
53
|
header_style = false
|
53
|
-
elsif options[:row_style]
|
54
|
-
header_style = options[:row_style]
|
55
54
|
end
|
56
55
|
|
57
|
-
row_style = {background_color:
|
56
|
+
row_style = {background_color: nil, color: "000000", align: :left, bold: false, font_name: 'Arial', font_size: 10, italic: false, underline: false}
|
58
57
|
if options[:row_style]
|
59
58
|
row_style.merge!(options[:row_style])
|
60
59
|
end
|
@@ -85,7 +84,7 @@ module SpreadsheetArchitect
|
|
85
84
|
col = col.instance_eval(x)
|
86
85
|
end
|
87
86
|
end
|
88
|
-
row_data.push col
|
87
|
+
row_data.push col.to_s
|
89
88
|
end
|
90
89
|
return row_data
|
91
90
|
end
|
@@ -109,7 +108,7 @@ module SpreadsheetArchitect
|
|
109
108
|
|
110
109
|
spreadsheet.office_style :header_style, family: :cell do
|
111
110
|
if options[:header_style]
|
112
|
-
unless opts[:
|
111
|
+
unless opts[:header_style] && opts[:header_style][:bold] == false #uses opts, temporary
|
113
112
|
property :text, 'font-weight': :bold
|
114
113
|
end
|
115
114
|
if options[:header_style][:align]
|
@@ -169,13 +168,14 @@ module SpreadsheetArchitect
|
|
169
168
|
header_style[:bg_color] = options[:header_style].delete(:background_color)
|
170
169
|
if header_style[:align]
|
171
170
|
header_style[:alignment] = {}
|
172
|
-
header_style[:alignment][:horizontal] = options[:header_style]
|
171
|
+
header_style[:alignment][:horizontal] = options[:header_style].delete(:align)
|
173
172
|
end
|
174
173
|
header_style[:b] = options[:header_style].delete(:bold)
|
175
174
|
header_style[:sz] = options[:header_style].delete(:font_size)
|
176
175
|
header_style[:i] = options[:header_style].delete(:italic)
|
177
176
|
header_style[:u] = options[:header_style].delete(:underline)
|
178
|
-
|
177
|
+
header_style.delete_if{|x| x.nil?}
|
178
|
+
|
179
179
|
row_style = {}
|
180
180
|
row_style[:fg_color] = options[:row_style].delete(:color)
|
181
181
|
row_style[:bg_color] = options[:row_style].delete(:background_color)
|
@@ -187,6 +187,7 @@ module SpreadsheetArchitect
|
|
187
187
|
row_style[:sz] = options[:row_style].delete(:font_size)
|
188
188
|
row_style[:i] = options[:row_style].delete(:italic)
|
189
189
|
row_style[:u] = options[:row_style].delete(:underline)
|
190
|
+
row_style.delete_if{|x| x.nil?}
|
190
191
|
|
191
192
|
package = Axlsx::Package.new
|
192
193
|
|
@@ -1,13 +1,23 @@
|
|
1
1
|
if defined? ActionController
|
2
2
|
ActionController::Renderers.add :xlsx do |data, options|
|
3
|
+
if data.is_a?(ActiveRecord::Relation)
|
4
|
+
options[:filename] = data.model.name.pluralize
|
5
|
+
data = data.to_xlsx
|
6
|
+
end
|
3
7
|
send_data data, type: :xlsx, disposition: :attachment, filename: "#{options[:filename] ? options[:filename].sub('.xlsx','') : 'data'}.xlsx"
|
4
8
|
end
|
5
9
|
ActionController::Renderers.add :ods do |data, options|
|
10
|
+
if data.is_a?(ActiveRecord::Relation)
|
11
|
+
options[:filename] = data.model.name.pluralize
|
12
|
+
data = data.to_ods
|
13
|
+
end
|
6
14
|
send_data data, type: :ods, disposition: :attachment, filename: "#{options[:filename] ? options[:filename].sub('.ods','') : 'data'}.ods"
|
7
15
|
end
|
8
16
|
ActionController::Renderers.add :csv do |data, options|
|
17
|
+
if data.is_a?(ActiveRecord::Relation)
|
18
|
+
options[:filename] = data.model.name.pluralize
|
19
|
+
data = data.to_csv
|
20
|
+
end
|
9
21
|
send_data data, type: :csv, disposition: :attachment, filename: "#{options[:filename] ? options[:filename].sub('.csv','') : 'data'}.csv"
|
10
22
|
end
|
11
|
-
|
12
|
-
|
13
23
|
end
|