spreadsheet_architect 1.2.6 → 1.3.0

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: 6f9b780d8d8faee0db9db691acc6ac42e9e84dd0
4
- data.tar.gz: 2032d74569653b1f7cda5ec7b1d51ab7fdbcccc5
3
+ metadata.gz: c47812616a2147f2ebeb28ed3c273832623524a1
4
+ data.tar.gz: aff49fef3145d607e3f0bf744052c75436200488
5
5
  SHA512:
6
- metadata.gz: b95116195dbc983f0c71622f690071b706fd44405cf6a813fa7f3922cd06d63ed6d81ea50a85480417d9eac4fee3baf328f94e71a6b59cdacf8c1a9207010c74
7
- data.tar.gz: 65fadde69748e88ba5881b1c0d1a2da9a5883bacc925a62c58f3652aba24b1700b39d30372a38636b8fd58187a2ba233f00258ea653301298a9aae90a204beb1
6
+ metadata.gz: e00552e22011fa1d4b0b7b3d43a5d85a6d7d24656fd48898602c48ef93e5f0a3b2a65a1ebfb5f6c6a1caa38f6249168c78c4aa8a65a45f67a1cf583de732e019
7
+ data.tar.gz: 19e936f1628d565193dc383be1203ba641ab81b4ec5c3e144680f2a7a297a88356be8af5a299d54d4fdde0cd747ffb74b5a8ad676612cc6db389a67258dca9d3
data/README.md CHANGED
@@ -131,7 +131,6 @@ File.open('path/to/file.xlsx') do |f|
131
131
  end
132
132
  ```
133
133
 
134
-
135
134
  # Method Options
136
135
 
137
136
  ### to_xlsx, to_ods, to_csv
@@ -151,14 +150,47 @@ end
151
150
  ### to_ods
152
151
  **sheet_name** - *String*
153
152
 
154
- **header_style** - *Hash* - Default: {color: "000000", align: :center, font_size: 10, bold: true} - Note: Currently only supports these options
153
+ **header_style** - *Hash* - Default: `{color: "000000", align: :center, font_size: 10, bold: true}` - Note: Currently only supports these options
155
154
 
156
- **row_style** - *Hash* - Default: {color: "000000", align: :left, font_size: 10, bold: false} - Note: Currently only supports these options
155
+ **row_style** - *Hash* - Default: `{color: "000000", align: :left, font_size: 10, bold: false}` - Note: Currently only supports these options
157
156
 
158
157
  ### to_csv
159
158
  Only the generic options
160
159
 
161
160
 
161
+ # Change model default method options
162
+ ```ruby
163
+ class Post
164
+ include SpreadsheetArchitect
165
+
166
+ def spreadsheet_columns
167
+ [:name, :content]
168
+ end
169
+
170
+ SPREADSHEET_OPTIONS = {
171
+ headers: true,
172
+ header_style: {background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false},
173
+ row_style: {background_color: nil, color: "FFFFFF", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false},
174
+ sheet_name: self.name
175
+ }
176
+ end
177
+ ```
178
+
179
+ # Change project wide default method options
180
+ ```ruby
181
+ # config/initializers/spreadsheet_architect.rb
182
+
183
+ SpreadsheetArchitect.module_eval do
184
+ set_const('SPREADSHEET_OPTIONS, {
185
+ headers: true,
186
+ header_style: {background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false},
187
+ row_style: {background_color: nil, color: "FFFFFF", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false},
188
+ sheet_name: 'My Project Export'
189
+ })
190
+ end
191
+ ```
192
+
193
+
162
194
  # Credits
163
195
  Created by Weston Ganger - @westonganger
164
196
 
@@ -112,9 +112,15 @@ module SpreadsheetArchitect
112
112
  end
113
113
  end
114
114
 
115
- headers = (options[:headers] == false ? false : headers)
115
+ if options[:headers] == false || klass::SPREADSHEET_OPTIONS[:headers] == false
116
+ headers = false
117
+ end
116
118
 
117
- header_style = {background_color: "AAAAAA", color: "FFFFFF", align: :center, bold: false, font_name: 'Arial', font_size: 10, italic: false, underline: false}
119
+ if defined?(klass::SPREADSHEET_OPTIONS)
120
+ header_style = SpreadsheetArchitect::SPREADSHEET_OPTIONS[:header_style].merge(klass::SPREADSHEET_OPTIONS[:header_style] || {})
121
+ else
122
+ header_style = SpreadsheetArchitect::SPREADSHEET_OPTIONS[:header_style]
123
+ end
118
124
 
119
125
  if options[:header_style]
120
126
  header_style.merge!(options[:header_style])
@@ -122,12 +128,21 @@ module SpreadsheetArchitect
122
128
  header_style = false
123
129
  end
124
130
 
125
- row_style = {background_color: nil, color: "000000", align: :left, bold: false, font_name: 'Arial', font_size: 10, italic: false, underline: false}
131
+ if defined?(klass::SPREADSHEET_OPTIONS)
132
+ row_style = SpreadsheetArchitect::SPREADSHEET_OPTIONS[:row_style].merge(klass::SPREADSHEET_OPTIONS[:row_style] || {})
133
+ else
134
+ row_style = SpreadsheetArchitect::SPREADSHEET_OPTIONS[:row_style]
135
+ end
136
+
126
137
  if options[:row_style]
127
138
  row_style.merge!(options[:row_style])
128
139
  end
129
140
 
130
- sheet_name = options[:sheet_name] || klass.name
141
+ if defined?(klass::SPREADSHEET_OPTIONS)
142
+ sheet_name = options[:sheet_name] || klass::SPREADSHEET_OPTIONS[:sheet_name] || SpreadsheetArchitect::SPREADSHEET_OPTIONS[:sheet_name] || klass.name
143
+ else
144
+ sheet_name = options[:sheet_name] || SpreadsheetArchitect::SPREADSHEET_OPTIONS[:sheet_name] || klass.name
145
+ end
131
146
 
132
147
  return {headers: headers, header_style: header_style, row_style: row_style, types: types, sheet_name: sheet_name, data: data}
133
148
  end
@@ -254,4 +269,11 @@ module SpreadsheetArchitect
254
269
  return package.to_stream.read
255
270
  end
256
271
  end
272
+
273
+ SPREADSHEET_OPTIONS = {
274
+ headers: true,
275
+ #sheet_name: self.name,
276
+ header_style: {background_color: "AAAAAA", color: "FFFFFF", align: :center, bold: false, font_name: 'Arial', font_size: 10, italic: false, underline: false},
277
+ row_style: {background_color: nil, color: "000000", align: :left, bold: false, font_name: 'Arial', font_size: 10, italic: false, underline: false}
278
+ }
257
279
  end
@@ -1,3 +1,3 @@
1
1
  module SpreadsheetArchitect
2
- VERSION = "1.2.6"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet_architect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Ganger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-20 00:00:00.000000000 Z
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: axlsx