acts_as_xlsx 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,9 +7,9 @@ Acts as xlsx: Office Open XML Spreadsheet Generation plugin for active record
7
7
  **Author**: Randy Morgan
8
8
  **Copyright**: 2011
9
9
  **License**: MIT License
10
- **Latest Version**: 1.0.1
10
+ **Latest Version**: 1.0.2
11
11
  **Ruby Version**: 1.8.7 - 1.9.3
12
- **Release Date**: December 1st 2011
12
+ **Release Date**: December 3rd 2011
13
13
 
14
14
  Synopsis
15
15
  --------
@@ -45,7 +45,11 @@ Usage
45
45
 
46
46
  ###Examples
47
47
 
48
- A trivial rails example
48
+ A trivial rails example. In a production environment you will want to you stuff like x_sendfile and Tempfile
49
+ http://www.therailsway.com/2009/2/22/file-downloads-done-right
50
+
51
+ for nginx
52
+ http://andrewtimberlake.com/blog/how-to-protect-downloads-but-still-have-nginx-serve-the-files
49
53
 
50
54
  #Add the gem to your Gemfile and bundle install
51
55
  gem 'acts_as_xlsx'
@@ -65,10 +69,27 @@ A trivial rails example
65
69
  end
66
70
  end
67
71
 
68
- Specify columns and methods and i18n chain
69
- p = Post.to_xlsx :columns => [:name, :title, :ranking], :i18n => 'activerecord.attributes'
72
+ # dont forget to add posts/xslx to your routes!
73
+
74
+ In addition to dumping the entire table, it is also possible to specify the columns and method chains to execute in genrating your report.
75
+ # GET posts/xslx
76
+ def xlsx
77
+ p = Post.to_xlsx :columns => [:name, :title, :ranking, :'comments.last.content', :'comments.last.author.name']
78
+ p.serialize('public/downloads/posts.xlsx')
79
+ send_file 'public/downloads/posts.xlsx', :type=>"application/xlsx"
80
+ end
81
+
82
+ If your application uses i18n, you can specify the prefix for column labels as well
70
83
 
84
+ # GET posts/xslx
85
+ def xlsx
86
+ p = Post.to_xlsx :i18n => 'activerecord.attributes'
87
+ p.serialize('public/downloads/posts.xlsx')
88
+ send_file 'public/downloads/posts.xlsx', :type=>"application/xlsx"
89
+ end
90
+
71
91
  For examples on how to use axlsx for custom styles, charts, images and more see:
92
+
72
93
  [http://rubygems.org/gems/axlsx] (https://rubygems.org/gems/axlsx)
73
94
 
74
95
  ###Documentation
@@ -85,6 +106,9 @@ This gem has 100% coverage using Test::Unit
85
106
 
86
107
  Changelog
87
108
  ---------
109
+ - **December.3.11**: 1.0.2 release
110
+ Added support for chained method columns like :'model.association.attribute'
111
+
88
112
  - **October.30.11**: 1.0.1 release
89
113
  - Patch for inclusion error
90
114
 
data/acts_as_xlsx.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rake'
2
- acts_as_xlsx_version = "1.0.1"
2
+ acts_as_xlsx_version = "1.0.2"
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'acts_as_xlsx'
5
5
  s.version = acts_as_xlsx_version
@@ -26,11 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.add_runtime_dependency 'axlsx', '>= 1.0.10'
27
27
  s.add_runtime_dependency 'activerecord', '>= 2.3.9'
28
28
  s.add_runtime_dependency 'i18n', '>=0.6.0'
29
-
30
- # required for yard documentation generation
31
- s.add_runtime_dependency 'yard'
32
- s.add_runtime_dependency 'rdiscount'
33
-
29
+
34
30
  # required for running tests
35
31
  s.add_development_dependency 'sqlite3'
36
32
  s.add_development_dependency 'rake', '>= 0.9.2'
data/doc/Axlsx.html CHANGED
@@ -116,7 +116,7 @@ Adding to the Axlsx module
116
116
  </div>
117
117
 
118
118
  <div id="footer">
119
- Generated on Thu Dec 1 01:04:19 2011 by
119
+ Generated on Sat Dec 3 11:39:31 2011 by
120
120
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
121
121
  0.7.3 (ruby-1.8.7).
122
122
  </div>
data/doc/Axlsx/Ar.html CHANGED
@@ -172,12 +172,12 @@ support to both AR classes and instances
172
172
  <pre class="lines">
173
173
 
174
174
 
175
- 14
176
175
  15
177
- 16</pre>
176
+ 16
177
+ 17</pre>
178
178
  </td>
179
179
  <td>
180
- <pre class="code"><span class="info file"># File 'lib/acts_as_xlsx.rb', line 14</span>
180
+ <pre class="code"><span class="info file"># File 'lib/acts_as_xlsx.rb', line 15</span>
181
181
 
182
182
  <span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='included identifier id'>included</span><span class='lparen token'>(</span><span class='base identifier id'>base</span><span class='rparen token'>)</span> <span class='comment val'># :nodoc:</span>
183
183
  <span class='base identifier id'>base</span><span class='dot token'>.</span><span class='send identifier id'>send</span> <span class='symbol val'>:extend</span><span class='comma token'>,</span> <span class='ClassMethods constant id'>ClassMethods</span>
@@ -193,7 +193,7 @@ support to both AR classes and instances
193
193
  </div>
194
194
 
195
195
  <div id="footer">
196
- Generated on Thu Dec 1 01:04:19 2011 by
196
+ Generated on Sat Dec 3 11:39:31 2011 by
197
197
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
198
198
  0.7.3 (ruby-1.8.7).
199
199
  </div>
@@ -231,15 +231,15 @@ will be used to determine the labels for columns.
231
231
  <pre class="lines">
232
232
 
233
233
 
234
- 27
235
234
  28
236
235
  29
237
236
  30
238
237
  31
239
- 32</pre>
238
+ 32
239
+ 33</pre>
240
240
  </td>
241
241
  <td>
242
- <pre class="code"><span class="info file"># File 'lib/acts_as_xlsx.rb', line 27</span>
242
+ <pre class="code"><span class="info file"># File 'lib/acts_as_xlsx.rb', line 28</span>
243
243
 
244
244
  <span class='def def kw'>def</span> <span class='acts_as_xlsx identifier id'>acts_as_xlsx</span><span class='lparen token'>(</span><span class='options identifier id'>options</span><span class='assign token'>=</span><span class='lbrace token'>{</span><span class='rbrace token'>}</span><span class='rparen token'>)</span>
245
245
  <span class='cattr_accessor identifier id'>cattr_accessor</span> <span class='symbol val'>:xlsx_i18n</span><span class='comma token'>,</span> <span class='symbol val'>:xlsx_columns</span>
@@ -258,7 +258,7 @@ will be used to determine the labels for columns.
258
258
  </div>
259
259
 
260
260
  <div id="footer">
261
- Generated on Thu Dec 1 01:04:19 2011 by
261
+ Generated on Sat Dec 3 11:39:31 2011 by
262
262
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
263
263
  0.7.3 (ruby-1.8.7).
264
264
  </div>
@@ -266,7 +266,6 @@ The path to i18n attributes. (usually activerecord.attributes)
266
266
  <pre class="lines">
267
267
 
268
268
 
269
- 46
270
269
  47
271
270
  48
272
271
  49
@@ -299,10 +298,18 @@ The path to i18n attributes. (usually activerecord.attributes)
299
298
  76
300
299
  77
301
300
  78
302
- 79</pre>
301
+ 79
302
+ 80
303
+ 81
304
+ 82
305
+ 83
306
+ 84
307
+ 85
308
+ 86
309
+ 87</pre>
303
310
  </td>
304
311
  <td>
305
- <pre class="code"><span class="info file"># File 'lib/acts_as_xlsx.rb', line 46</span>
312
+ <pre class="code"><span class="info file"># File 'lib/acts_as_xlsx.rb', line 47</span>
306
313
 
307
314
  <span class='def def kw'>def</span> <span class='to_xlsx identifier id'>to_xlsx</span><span class='lparen token'>(</span><span class='options identifier id'>options</span> <span class='assign token'>=</span> <span class='lbrace token'>{</span><span class='rbrace token'>}</span><span class='rparen token'>)</span>
308
315
 
@@ -333,7 +340,14 @@ The path to i18n attributes. (usually activerecord.attributes)
333
340
  <span class='sheet identifier id'>sheet</span><span class='dot token'>.</span><span class='add_row identifier id'>add_row</span> <span class='col_labels identifier id'>col_labels</span><span class='comma token'>,</span> <span class='symbol val'>:style=</span><span class='gt op'>&gt;</span><span class='header_style identifier id'>header_style</span>
334
341
 
335
342
  <span class='data identifier id'>data</span><span class='dot token'>.</span><span class='each identifier id'>each</span> <span class='do do kw'>do</span> <span class='bitor op'>|</span><span class='r identifier id'>r</span><span class='bitor op'>|</span>
336
- <span class='sheet identifier id'>sheet</span><span class='dot token'>.</span><span class='add_row identifier id'>add_row</span> <span class='columns identifier id'>columns</span><span class='dot token'>.</span><span class='map identifier id'>map</span> <span class='lbrace token'>{</span> <span class='bitor op'>|</span><span class='c identifier id'>c</span><span class='bitor op'>|</span> <span class='r identifier id'>r</span><span class='dot token'>.</span><span class='send identifier id'>send</span><span class='lparen token'>(</span><span class='c identifier id'>c</span><span class='rparen token'>)</span> <span class='rbrace token'>}</span><span class='comma token'>,</span> <span class='symbol val'>:style=</span><span class='gt op'>&gt;</span><span class='row_style identifier id'>row_style</span><span class='comma token'>,</span> <span class='symbol val'>:types=</span><span class='gt op'>&gt;</span><span class='types identifier id'>types</span>
343
+ <span class='row_data identifier id'>row_data</span> <span class='assign token'>=</span> <span class='columns identifier id'>columns</span><span class='dot token'>.</span><span class='map identifier id'>map</span> <span class='do do kw'>do</span> <span class='bitor op'>|</span><span class='c identifier id'>c</span><span class='bitor op'>|</span>
344
+ <span class='if if kw'>if</span> <span class='c identifier id'>c</span><span class='dot token'>.</span><span class='to_s identifier id'>to_s</span> <span class='match op'>=~</span> <span class='regexp val'>/\./</span>
345
+ <span class='v identifier id'>v</span> <span class='assign token'>=</span> <span class='r identifier id'>r</span><span class='semicolon token'>;</span> <span class='c identifier id'>c</span><span class='dot token'>.</span><span class='to_s identifier id'>to_s</span><span class='dot token'>.</span><span class='split identifier id'>split</span><span class='lparen token'>(</span><span class='string val'>'.'</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='each identifier id'>each</span> <span class='lbrace token'>{</span> <span class='bitor op'>|</span><span class='method identifier id'>method</span><span class='bitor op'>|</span> <span class='v identifier id'>v</span> <span class='assign token'>=</span> <span class='v identifier id'>v</span><span class='dot token'>.</span><span class='send identifier id'>send</span><span class='lparen token'>(</span><span class='method identifier id'>method</span><span class='rparen token'>)</span> <span class='rbrace token'>}</span><span class='semicolon token'>;</span> <span class='v identifier id'>v</span>
346
+ <span class='else else kw'>else</span>
347
+ <span class='r identifier id'>r</span><span class='dot token'>.</span><span class='send identifier id'>send</span><span class='lparen token'>(</span><span class='c identifier id'>c</span><span class='rparen token'>)</span>
348
+ <span class='end end kw'>end</span>
349
+ <span class='end end kw'>end</span>
350
+ <span class='sheet identifier id'>sheet</span><span class='dot token'>.</span><span class='add_row identifier id'>add_row</span> <span class='row_data identifier id'>row_data</span><span class='comma token'>,</span> <span class='symbol val'>:style=</span><span class='gt op'>&gt;</span><span class='row_style identifier id'>row_style</span><span class='comma token'>,</span> <span class='symbol val'>:types=</span><span class='gt op'>&gt;</span><span class='types identifier id'>types</span>
337
351
  <span class='end end kw'>end</span>
338
352
  <span class='end end kw'>end</span>
339
353
  <span class='p identifier id'>p</span>
@@ -349,7 +363,7 @@ The path to i18n attributes. (usually activerecord.attributes)
349
363
  </div>
350
364
 
351
365
  <div id="footer">
352
- Generated on Thu Dec 1 01:04:20 2011 by
366
+ Generated on Sat Dec 3 11:39:32 2011 by
353
367
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
354
368
  0.7.3 (ruby-1.8.7).
355
369
  </div>
data/doc/_index.html CHANGED
@@ -137,7 +137,7 @@
137
137
  </div>
138
138
 
139
139
  <div id="footer">
140
- Generated on Thu Dec 1 01:04:19 2011 by
140
+ Generated on Sat Dec 3 11:39:31 2011 by
141
141
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
142
142
  0.7.3 (ruby-1.8.7).
143
143
  </div>
@@ -82,7 +82,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
82
82
  </div></div>
83
83
 
84
84
  <div id="footer">
85
- Generated on Thu Dec 1 01:04:19 2011 by
85
+ Generated on Sat Dec 3 11:39:31 2011 by
86
86
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
87
87
  0.7.3 (ruby-1.8.7).
88
88
  </div>
data/doc/file.README.html CHANGED
@@ -63,9 +63,9 @@
63
63
  <strong>Author</strong>: Randy Morgan <br/>
64
64
  <strong>Copyright</strong>: 2011 <br/>
65
65
  <strong>License</strong>: MIT License <br/>
66
- <strong>Latest Version</strong>: 1.0.1 <br/>
66
+ <strong>Latest Version</strong>: 1.0.2 <br/>
67
67
  <strong>Ruby Version</strong>: 1.8.7 - 1.9.3<br/>
68
- <strong>Release Date</strong>: December 1st 2011</p>
68
+ <strong>Release Date</strong>: December 3rd 2011</p>
69
69
 
70
70
  <h2>Synopsis</h2>
71
71
 
@@ -98,7 +98,11 @@
98
98
 
99
99
  <h3>Examples</h3>
100
100
 
101
- <p>A trivial rails example</p>
101
+ <p>A trivial rails example. In a production environment you will want to you stuff like x_sendfile and Tempfile<br/>
102
+ <a href="http://www.therailsway.com/2009/2/22/file-downloads-done-right">http://www.therailsway.com/2009/2/22/file-downloads-done-right</a></p>
103
+
104
+ <p>for nginx<br/>
105
+ <a href="http://andrewtimberlake.com/blog/how-to-protect-downloads-but-still-have-nginx-serve-the-files">http://andrewtimberlake.com/blog/how-to-protect-downloads-but-still-have-nginx-serve-the-files</a></p>
102
106
 
103
107
  <pre class="code"> <span class='comment val'>#Add the gem to your Gemfile and bundle install</span>
104
108
  <span class='gem identifier id'>gem</span> <span class='string val'>'acts_as_xlsx'</span>
@@ -117,11 +121,28 @@
117
121
  <span class='send_file identifier id'>send_file</span> <span class='string val'>'public/downloads/posts.xlsx'</span><span class='comma token'>,</span> <span class='symbol val'>:type=</span><span class='gt op'>&gt;</span><span class='string val'>&quot;application/xlsx&quot;</span>
118
122
  <span class='end end kw'>end</span>
119
123
  <span class='end end kw'>end</span>
124
+
125
+ <span class='comment val'># dont forget to add posts/xslx to your routes!</span>
120
126
  </pre>
121
127
 
122
- <p>Specify columns and methods and i18n chain</p>
128
+ <p>In addition to dumping the entire table, it is also possible to specify the columns and method chains to execute in genrating your report.</p>
123
129
 
124
- <pre class="code"><span class='p identifier id'>p</span> <span class='assign token'>=</span> <span class='Post constant id'>Post</span><span class='dot token'>.</span><span class='to_xlsx identifier id'>to_xlsx</span> <span class='symbol val'>:columns</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='lbrack token'>[</span><span class='symbol val'>:name</span><span class='comma token'>,</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:ranking</span><span class='rbrack token'>]</span><span class='comma token'>,</span> <span class='symbol val'>:i18n</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>'activerecord.attributes'</span>
130
+ <pre class="code"> <span class='comment val'># GET posts/xslx</span>
131
+ <span class='def def kw'>def</span> <span class='xlsx identifier id'>xlsx</span>
132
+ <span class='p identifier id'>p</span> <span class='assign token'>=</span> <span class='Post constant id'>Post</span><span class='dot token'>.</span><span class='to_xlsx identifier id'>to_xlsx</span> <span class='symbol val'>:columns</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='lbrack token'>[</span><span class='symbol val'>:name</span><span class='comma token'>,</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:ranking</span><span class='comma token'>,</span> <span class='symbol val'>:'comments.last.content'</span><span class='comma token'>,</span> <span class='symbol val'>:'comments.last.author.name'</span><span class='rbrack token'>]</span>
133
+ <span class='p identifier id'>p</span><span class='dot token'>.</span><span class='serialize identifier id'>serialize</span><span class='lparen token'>(</span><span class='string val'>'public/downloads/posts.xlsx'</span><span class='rparen token'>)</span>
134
+ <span class='send_file identifier id'>send_file</span> <span class='string val'>'public/downloads/posts.xlsx'</span><span class='comma token'>,</span> <span class='symbol val'>:type=</span><span class='gt op'>&gt;</span><span class='string val'>&quot;application/xlsx&quot;</span>
135
+ <span class='end end kw'>end</span>
136
+ </pre>
137
+
138
+ <p>If your application uses i18n, you can specify the prefix for column labels as well</p>
139
+
140
+ <pre class="code"> <span class='comment val'># GET posts/xslx</span>
141
+ <span class='def def kw'>def</span> <span class='xlsx identifier id'>xlsx</span>
142
+ <span class='p identifier id'>p</span> <span class='assign token'>=</span> <span class='Post constant id'>Post</span><span class='dot token'>.</span><span class='to_xlsx identifier id'>to_xlsx</span> <span class='symbol val'>:i18n</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>'activerecord.attributes'</span>
143
+ <span class='p identifier id'>p</span><span class='dot token'>.</span><span class='serialize identifier id'>serialize</span><span class='lparen token'>(</span><span class='string val'>'public/downloads/posts.xlsx'</span><span class='rparen token'>)</span>
144
+ <span class='send_file identifier id'>send_file</span> <span class='string val'>'public/downloads/posts.xlsx'</span><span class='comma token'>,</span> <span class='symbol val'>:type=</span><span class='gt op'>&gt;</span><span class='string val'>&quot;application/xlsx&quot;</span>
145
+ <span class='end end kw'>end</span>
125
146
  </pre>
126
147
 
127
148
  <p>For examples on how to use axlsx for custom styles, charts, images and more see:</p>
@@ -144,6 +165,8 @@
144
165
  <h2>Changelog</h2>
145
166
 
146
167
  <ul>
168
+ <li><p><strong>December.3.11</strong>: 1.0.2 release
169
+ Added support for chained method columns like :'model.association.attribute'</p></li>
147
170
  <li><p><strong>October.30.11</strong>: 1.0.1 release</p>
148
171
 
149
172
  <ul>
@@ -174,7 +197,7 @@ licensed under the MIT license. Please see the <a href="file.LICENSE.html" title
174
197
  </div></div>
175
198
 
176
199
  <div id="footer">
177
- Generated on Thu Dec 1 01:04:19 2011 by
200
+ Generated on Sat Dec 3 11:39:31 2011 by
178
201
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
179
202
  0.7.3 (ruby-1.8.7).
180
203
  </div>
data/doc/index.html CHANGED
@@ -63,9 +63,9 @@
63
63
  <strong>Author</strong>: Randy Morgan <br/>
64
64
  <strong>Copyright</strong>: 2011 <br/>
65
65
  <strong>License</strong>: MIT License <br/>
66
- <strong>Latest Version</strong>: 1.0.1 <br/>
66
+ <strong>Latest Version</strong>: 1.0.2 <br/>
67
67
  <strong>Ruby Version</strong>: 1.8.7 - 1.9.3<br/>
68
- <strong>Release Date</strong>: December 1st 2011</p>
68
+ <strong>Release Date</strong>: December 3rd 2011</p>
69
69
 
70
70
  <h2>Synopsis</h2>
71
71
 
@@ -98,7 +98,11 @@
98
98
 
99
99
  <h3>Examples</h3>
100
100
 
101
- <p>A trivial rails example</p>
101
+ <p>A trivial rails example. In a production environment you will want to you stuff like x_sendfile and Tempfile<br/>
102
+ <a href="http://www.therailsway.com/2009/2/22/file-downloads-done-right">http://www.therailsway.com/2009/2/22/file-downloads-done-right</a></p>
103
+
104
+ <p>for nginx<br/>
105
+ <a href="http://andrewtimberlake.com/blog/how-to-protect-downloads-but-still-have-nginx-serve-the-files">http://andrewtimberlake.com/blog/how-to-protect-downloads-but-still-have-nginx-serve-the-files</a></p>
102
106
 
103
107
  <pre class="code"> <span class='comment val'>#Add the gem to your Gemfile and bundle install</span>
104
108
  <span class='gem identifier id'>gem</span> <span class='string val'>'acts_as_xlsx'</span>
@@ -117,11 +121,28 @@
117
121
  <span class='send_file identifier id'>send_file</span> <span class='string val'>'public/downloads/posts.xlsx'</span><span class='comma token'>,</span> <span class='symbol val'>:type=</span><span class='gt op'>&gt;</span><span class='string val'>&quot;application/xlsx&quot;</span>
118
122
  <span class='end end kw'>end</span>
119
123
  <span class='end end kw'>end</span>
124
+
125
+ <span class='comment val'># dont forget to add posts/xslx to your routes!</span>
120
126
  </pre>
121
127
 
122
- <p>Specify columns and methods and i18n chain</p>
128
+ <p>In addition to dumping the entire table, it is also possible to specify the columns and method chains to execute in genrating your report.</p>
123
129
 
124
- <pre class="code"><span class='p identifier id'>p</span> <span class='assign token'>=</span> <span class='Post constant id'>Post</span><span class='dot token'>.</span><span class='to_xlsx identifier id'>to_xlsx</span> <span class='symbol val'>:columns</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='lbrack token'>[</span><span class='symbol val'>:name</span><span class='comma token'>,</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:ranking</span><span class='rbrack token'>]</span><span class='comma token'>,</span> <span class='symbol val'>:i18n</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>'activerecord.attributes'</span>
130
+ <pre class="code"> <span class='comment val'># GET posts/xslx</span>
131
+ <span class='def def kw'>def</span> <span class='xlsx identifier id'>xlsx</span>
132
+ <span class='p identifier id'>p</span> <span class='assign token'>=</span> <span class='Post constant id'>Post</span><span class='dot token'>.</span><span class='to_xlsx identifier id'>to_xlsx</span> <span class='symbol val'>:columns</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='lbrack token'>[</span><span class='symbol val'>:name</span><span class='comma token'>,</span> <span class='symbol val'>:title</span><span class='comma token'>,</span> <span class='symbol val'>:ranking</span><span class='comma token'>,</span> <span class='symbol val'>:'comments.last.content'</span><span class='comma token'>,</span> <span class='symbol val'>:'comments.last.author.name'</span><span class='rbrack token'>]</span>
133
+ <span class='p identifier id'>p</span><span class='dot token'>.</span><span class='serialize identifier id'>serialize</span><span class='lparen token'>(</span><span class='string val'>'public/downloads/posts.xlsx'</span><span class='rparen token'>)</span>
134
+ <span class='send_file identifier id'>send_file</span> <span class='string val'>'public/downloads/posts.xlsx'</span><span class='comma token'>,</span> <span class='symbol val'>:type=</span><span class='gt op'>&gt;</span><span class='string val'>&quot;application/xlsx&quot;</span>
135
+ <span class='end end kw'>end</span>
136
+ </pre>
137
+
138
+ <p>If your application uses i18n, you can specify the prefix for column labels as well</p>
139
+
140
+ <pre class="code"> <span class='comment val'># GET posts/xslx</span>
141
+ <span class='def def kw'>def</span> <span class='xlsx identifier id'>xlsx</span>
142
+ <span class='p identifier id'>p</span> <span class='assign token'>=</span> <span class='Post constant id'>Post</span><span class='dot token'>.</span><span class='to_xlsx identifier id'>to_xlsx</span> <span class='symbol val'>:i18n</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>'activerecord.attributes'</span>
143
+ <span class='p identifier id'>p</span><span class='dot token'>.</span><span class='serialize identifier id'>serialize</span><span class='lparen token'>(</span><span class='string val'>'public/downloads/posts.xlsx'</span><span class='rparen token'>)</span>
144
+ <span class='send_file identifier id'>send_file</span> <span class='string val'>'public/downloads/posts.xlsx'</span><span class='comma token'>,</span> <span class='symbol val'>:type=</span><span class='gt op'>&gt;</span><span class='string val'>&quot;application/xlsx&quot;</span>
145
+ <span class='end end kw'>end</span>
125
146
  </pre>
126
147
 
127
148
  <p>For examples on how to use axlsx for custom styles, charts, images and more see:</p>
@@ -144,6 +165,8 @@
144
165
  <h2>Changelog</h2>
145
166
 
146
167
  <ul>
168
+ <li><p><strong>December.3.11</strong>: 1.0.2 release
169
+ Added support for chained method columns like :'model.association.attribute'</p></li>
147
170
  <li><p><strong>October.30.11</strong>: 1.0.1 release</p>
148
171
 
149
172
  <ul>
@@ -174,7 +197,7 @@ licensed under the MIT license. Please see the <a href="file.LICENSE.html" title
174
197
  </div></div>
175
198
 
176
199
  <div id="footer">
177
- Generated on Thu Dec 1 01:04:19 2011 by
200
+ Generated on Sat Dec 3 11:39:31 2011 by
178
201
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
179
202
  0.7.3 (ruby-1.8.7).
180
203
  </div>
@@ -94,7 +94,7 @@
94
94
  </div>
95
95
 
96
96
  <div id="footer">
97
- Generated on Thu Dec 1 01:04:20 2011 by
97
+ Generated on Sat Dec 3 11:39:32 2011 by
98
98
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
99
99
  0.7.3 (ruby-1.8.7).
100
100
  </div>
data/lib/acts_as_xlsx.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # Axlsx is a gem or generating excel spreadsheets with charts, images and many other features.
2
3
  #
3
4
  # acts_as_xlsx provides integration into active_record for Axlsx.
@@ -72,7 +73,14 @@ module Axlsx
72
73
  sheet.add_row col_labels, :style=>header_style
73
74
 
74
75
  data.each do |r|
75
- sheet.add_row columns.map { |c| r.send(c) }, :style=>row_style, :types=>types
76
+ row_data = columns.map do |c|
77
+ if c.to_s =~ /\./
78
+ v = r; c.to_s.split('.').each { |method| v = v.send(method) }; v
79
+ else
80
+ r.send(c)
81
+ end
82
+ end
83
+ sheet.add_row row_data, :style=>row_style, :types=>types
76
84
  end
77
85
  end
78
86
  p
Binary file
@@ -44,6 +44,13 @@ class TestToXlsx < Test::Unit::TestCase
44
44
  assert_equal("Name", sheet.rows.first.cells.first.value)
45
45
  assert_equal(Post.last.ranking, sheet.rows.last.cells.last.value)
46
46
  end
47
+
48
+ def test_chained_method
49
+ p = Post.to_xlsx :columns=>[:name, :votes, :content, :ranking, :'comments.last.content', :'comments.first.author.name']
50
+ sheet = p.workbook.worksheets.first
51
+ assert_equal("Name", sheet.rows.first.cells.first.value)
52
+ assert_equal(Post.last.comments.last.author.name, sheet.rows.last.cells.last.value)
53
+ end
47
54
  end
48
55
 
49
56
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_xlsx
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Randy Morgan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-01 00:00:00 Z
18
+ date: 2011-12-03 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: axlsx
@@ -65,38 +65,10 @@ dependencies:
65
65
  version: 0.6.0
66
66
  type: :runtime
67
67
  version_requirements: *id003
68
- - !ruby/object:Gem::Dependency
69
- name: yard
70
- prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
78
- - 0
79
- version: "0"
80
- type: :runtime
81
- version_requirements: *id004
82
- - !ruby/object:Gem::Dependency
83
- name: rdiscount
84
- prerelease: false
85
- requirement: &id005 !ruby/object:Gem::Requirement
86
- none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
94
- type: :runtime
95
- version_requirements: *id005
96
68
  - !ruby/object:Gem::Dependency
97
69
  name: sqlite3
98
70
  prerelease: false
99
- requirement: &id006 !ruby/object:Gem::Requirement
71
+ requirement: &id004 !ruby/object:Gem::Requirement
100
72
  none: false
101
73
  requirements:
102
74
  - - ">="
@@ -106,11 +78,11 @@ dependencies:
106
78
  - 0
107
79
  version: "0"
108
80
  type: :development
109
- version_requirements: *id006
81
+ version_requirements: *id004
110
82
  - !ruby/object:Gem::Dependency
111
83
  name: rake
112
84
  prerelease: false
113
- requirement: &id007 !ruby/object:Gem::Requirement
85
+ requirement: &id005 !ruby/object:Gem::Requirement
114
86
  none: false
115
87
  requirements:
116
88
  - - ">="
@@ -122,7 +94,7 @@ dependencies:
122
94
  - 2
123
95
  version: 0.9.2
124
96
  type: :development
125
- version_requirements: *id007
97
+ version_requirements: *id005
126
98
  description: " acts_as_xlsx lets you turn any ActiveRecord::Base inheriting class into an excel spreadsheet.\n"
127
99
  email: digital.ipseity@gmail.com
128
100
  executables: []
@@ -142,7 +114,6 @@ files:
142
114
  - lib/acts_as_xlsx.rb
143
115
  - doc/_index.html
144
116
  - doc/Axlsx/Ar/ClassMethods.html
145
- - doc/Axlsx/Ar/InstanceMethods.html
146
117
  - doc/Axlsx/Ar/SingletonMethods.html
147
118
  - doc/Axlsx/Ar.html
148
119
  - doc/Axlsx.html
@@ -1,188 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
- <title>
7
- Module: Axlsx::Ar::InstanceMethods
8
-
9
- &mdash; Acts As Xlsx (Axlsx)
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="../../css/style.css" type="text/css" media="screen" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="../../css/common.css" type="text/css" media="screen" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- relpath = '../..';
19
- if (relpath != '') relpath += '/';
20
- </script>
21
-
22
- <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
23
-
24
- <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
25
-
26
-
27
- </head>
28
- <body>
29
- <script type="text/javascript" charset="utf-8">
30
- if (window.top.frames.main) document.body.className = 'frames';
31
- </script>
32
-
33
- <div id="header">
34
- <div id="menu">
35
-
36
- <a href="../../_index.html">Index (I)</a> &raquo;
37
- <span class='title'><span class='object_link'><a href="../../Axlsx.html" title="Axlsx (module)">Axlsx</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Ar.html" title="Axlsx::Ar (module)">Ar</a></span></span>
38
- &raquo;
39
- <span class="title">InstanceMethods</span>
40
-
41
-
42
- <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
43
- </div>
44
-
45
- <div id="search">
46
-
47
- <a id="class_list_link" href="#">Class List</a>
48
-
49
- <a id="method_list_link" href="#">Method List</a>
50
-
51
- <a id="file_list_link" href="#">File List</a>
52
-
53
- </div>
54
- <div class="clear"></div>
55
- </div>
56
-
57
- <iframe id="search_frame"></iframe>
58
-
59
- <div id="content"><h1>Module: Axlsx::Ar::InstanceMethods
60
-
61
-
62
-
63
- </h1>
64
-
65
- <dl class="box">
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
- <dt class="r1 last">Defined in:</dt>
75
- <dd class="r1 last">lib/axlsx/acts_as_xlsx.rb</dd>
76
-
77
- </dl>
78
- <div class="clear"></div>
79
-
80
- <h2>Overview</h2><div class="docstring">
81
- <div class="discussion">
82
-
83
- <p>Defines the instance methods we add to ActiveRecord::Base</p>
84
-
85
-
86
- </div>
87
- </div>
88
- <div class="tags">
89
-
90
-
91
- </div>
92
-
93
-
94
-
95
-
96
-
97
- <h2>
98
- Instance Method Summary
99
- <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
100
- </h2>
101
-
102
- <ul class="summary">
103
-
104
- <li class="public ">
105
- <span class="summary_signature">
106
-
107
- <a href="#to_xlsx-instance_method" title="#to_xlsx (instance method)">- (Object) <strong>to_xlsx</strong>(options = {}) </a>
108
-
109
-
110
-
111
- </span>
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
- <span class="summary_desc"><div class='inline'>
121
- <p>Allows a single instance to be exported All active record find options are
122
- allowed.</p>
123
- </div></span>
124
-
125
- </li>
126
-
127
-
128
- </ul>
129
-
130
-
131
-
132
-
133
- <div id="instance_method_details" class="method_details_list">
134
- <h2>Instance Method Details</h2>
135
-
136
-
137
- <div class="method_details first">
138
- <p class="signature first" id="to_xlsx-instance_method">
139
-
140
- - (<tt>Object</tt>) <strong>to_xlsx</strong>(options = {})
141
-
142
-
143
-
144
- </p><div class="docstring">
145
- <div class="discussion">
146
-
147
- <p>Allows a single instance to be exported All active record find options are
148
- allowed</p>
149
-
150
-
151
- </div>
152
- </div>
153
- <div class="tags">
154
-
155
-
156
- </div><table class="source_code">
157
- <tr>
158
- <td>
159
- <pre class="lines">
160
-
161
-
162
- 88
163
- 89
164
- 90</pre>
165
- </td>
166
- <td>
167
- <pre class="code"><span class="info file"># File 'lib/axlsx/acts_as_xlsx.rb', line 88</span>
168
-
169
- <span class='kw'>def</span> <span class='id to_xlsx'>to_xlsx</span><span class='lparen'>(</span><span class='id options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
170
- <span class='kw'>self</span><span class='period'>.</span><span class='id class'>class</span><span class='period'>.</span><span class='id to_xlsx'>to_xlsx</span><span class='lparen'>(</span><span class='kw'>self</span><span class='period'>.</span><span class='id id'>id</span><span class='comma'>,</span> <span class='id options'>options</span><span class='rparen'>)</span>
171
- <span class='kw'>end</span></pre>
172
- </td>
173
- </tr>
174
- </table>
175
- </div>
176
-
177
- </div>
178
-
179
- </div>
180
-
181
- <div id="footer">
182
- Generated on Wed Nov 30 22:59:02 2011 by
183
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
184
- 0.7.3 (ruby-1.9.3).
185
- </div>
186
-
187
- </body>
188
- </html>