spreadsheet_architect 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be2d251d985ed779019709a19cd14047e8f26c18
4
- data.tar.gz: 5076391ee7d477af958ef6f9dd1cbc438695c57a
3
+ metadata.gz: 155a653969b09467dd11207dee1a4b4a208b316b
4
+ data.tar.gz: d7c94501ad36264f26e9285d21ebef0546e89067
5
5
  SHA512:
6
- metadata.gz: 87ea6396eb5bed677c7fce4bec9da8588620ecd247ea4bbb9fbf964908809803f27e7959527917a8a404b981f60c31d025b76ea92c16856e0f06f36e84f21790
7
- data.tar.gz: 3c5022fd0922a7c2fc2eeec0fbdce445b75ef9a8439b561d412b6c1564b9091de5f89f4d4db414e4243cbe83efb961c2baa881a93474a765884a55c09483306b
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: "FFFFFF", color: "FFFFFF", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`
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_+/, '').sub(/_id\z/, '').gsub(/[_\.]/,' ').sub(' rescue nil','')
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
- headers = self.column_names.map{|x| x.humanize}
25
- columns = self.column_names.map{|x| x.to_s}
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: "FFFFFF", color: "000000", align: :left, bold: false, font_name: 'Arial', font_size: 10, italic: false, underline: false}
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[:row_style] && opts[:row_style][:bold] == false #uses opts, temporary
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][:align]
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
@@ -1,3 +1,3 @@
1
1
  module SpreadsheetArchitect
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet_architect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Ganger