acts_as_xlsx 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ --protected
2
+ --no-private
3
+ --main README.md
4
+ --title "acts_as_xlsx: a rails plug in for axlsx"
5
+ -
6
+ LICENSE
7
+ CHANGELOG.md
@@ -0,0 +1,17 @@
1
+ CHANGELOG
2
+ ---------
3
+
4
+ - **December.6.11**: 1.0.3 release
5
+ - Added Mime type definition for rails to support respond_to |format| style handling in controllers.
6
+
7
+ - **December.3.11**: 1.0.2 release
8
+ Added support for chained method columns like :'model.association.attribute'
9
+
10
+ - **October.30.11**: 1.0.1 release
11
+ - Patch for inclusion error
12
+
13
+ - **October.30.11**: 1.0.0 release
14
+ - First release
15
+
16
+ - **October.30.11**: 1.0.0a release
17
+ - First pre release
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.3
10
+ **Latest Version**: 1.0.4
11
11
  **Ruby Version**: 1.8.7 - 1.9.3
12
- **Release Date**: December 6th 2011
12
+ **Release Date**: December 8th 2011
13
13
 
14
14
  Synopsis
15
15
  --------
@@ -35,6 +35,8 @@ Feature List
35
35
 
36
36
  **8. Automatically registers xlsx Mime type for use in respond_to web-service support.
37
37
 
38
+ **9. Allows you to specify the Axlsx package to add your data to so you can create a single workbook with a sheet for each to_xlsx call.
39
+
38
40
  Installing
39
41
  ----------
40
42
 
@@ -47,52 +49,10 @@ Usage
47
49
 
48
50
  ###Examples
49
51
 
50
- Also see the writeups here:
51
- http://axlsx.blogspot.com/
52
-
53
- A trivial rails example. In a production environment you will want to you stuff like x_sendfile and Tempfile
54
- http://www.therailsway.com/2009/2/22/file-downloads-done-right
55
-
56
- for nginx
57
- http://andrewtimberlake.com/blog/how-to-protect-downloads-but-still-have-nginx-serve-the-files
58
-
59
- #Add the gem to your Gemfile and bundle install
60
- gem 'acts_as_xlsx'
61
-
62
- # app/models/post.rb
63
- class Post < ActiveRecord::Base
64
- acts_as_xlsx
65
- end
66
-
67
- # app/controllers/posts_controller.rb
68
- class PostsController < ApplicationController
69
- # GET posts/xlsx
70
- def xlsx
71
- p = Post.to_xlsx
72
- p.serialize('public/downloads/posts.xlsx')
73
- send_file 'public/downloads/posts.xlsx', :type=>"application/xlsx"
74
- end
75
- end
76
-
77
- # dont forget to add posts/xslx to your routes!
78
-
79
- In addition to dumping the entire table, it is also possible to specify the columns and method chains to execute in genrating your report.
80
- # GET posts/xslx
81
- def xlsx
82
- p = Post.to_xlsx :columns => [:name, :title, :ranking, :'comments.last.content', :'comments.last.author.name']
83
- p.serialize('public/downloads/posts.xlsx')
84
- send_file 'public/downloads/posts.xlsx', :type=>"application/xlsx"
85
- end
86
-
87
- If your application uses i18n, you can specify the prefix for column labels as well
88
-
89
- # GET posts/xslx
90
- def xlsx
91
- p = Post.to_xlsx :i18n => 'activerecord.attributes'
92
- p.serialize('public/downloads/posts.xlsx')
93
- send_file 'public/downloads/posts.xlsx', :type=>"application/xlsx"
94
- end
95
-
52
+ See the Guides here:
53
+
54
+ [http://axlsx.blogspot.com/] (http://axlsx.blogspot.com/)
55
+
96
56
  For examples on how to use axlsx for custom styles, charts, images and more see:
97
57
 
98
58
  [http://rubygems.org/gems/axlsx] (https://rubygems.org/gems/axlsx)
@@ -111,21 +71,11 @@ This gem has 100% coverage using Test::Unit
111
71
 
112
72
  Changelog
113
73
  ---------
114
- - **December.6.11**: 1.0.3 release
115
- - Added Mime type definition for rails to support respond_to |format| style handling in controllers.
74
+ - **December.7.11**: 1.0.4 release
75
+ - acts_as_xlsx now supports specifying the Axlsx package the export will be added to
76
+ - Support for custom named and I18n names for worksheets.
116
77
 
117
- - **December.3.11**: 1.0.2 release
118
- Added support for chained method columns like :'model.association.attribute'
119
78
 
120
- - **October.30.11**: 1.0.1 release
121
- - Patch for inclusion error
122
-
123
- - **October.30.11**: 1.0.0 release
124
- - First release
125
-
126
- - **October.30.11**: 1.0.0a release
127
- - First pre release
128
-
129
79
  Please see the {file:CHANGELOG.md} document for past release information.
130
80
 
131
81
 
@@ -43,6 +43,7 @@ module Axlsx
43
43
  # @option options [Array, Symbol] types an array of Axlsx types for each cell in data rows or a single type that will be applied to all types.
44
44
  # @option options [Integer, Array] style The style to pass to Worksheet#add_row
45
45
  # @option options [String] i18n The path to i18n attributes. (usually activerecord.attributes)
46
+ # @option options [Package] package An Axlsx::Package. When this is provided the output will be added to the package as a new sheet. # @option options [String] name This will be used to name the worksheet added to the package. If it is not provided the name of the table name will be humanized when i18n is not specified or the I18n.t for the table name.
46
47
  # @see Worksheet#add_row
47
48
  def to_xlsx(options = {})
48
49
 
@@ -53,16 +54,17 @@ module Axlsx
53
54
  i18n = options.delete(:i18n) || self.xlsx_i18n
54
55
  columns = options.delete(:columns) || self.xlsx_columns
55
56
 
56
- p = Package.new
57
+ p = options.delete(:package) || Package.new
57
58
  row_style = p.workbook.styles.add_style(row_style) unless row_style.nil?
58
59
  header_style = p.workbook.styles.add_style(header_style) unless header_style.nil?
59
-
60
+ i18n = self.xlsx_i18n == true ? 'activerecord.attributes' : i18n
61
+ sheet_name = options.delete(:name) || (i18n ? I18n.t("#{i18n}.#{table_name.underscore}") : table_name.humanize)
60
62
  data = [*find(:all, options)]
61
63
  data.compact!
62
64
  data.flatten!
63
65
 
64
66
  return p if data.empty?
65
- p.workbook.add_worksheet(:name=>table_name.humanize) do |sheet|
67
+ p.workbook.add_worksheet(:name=>sheet_name) do |sheet|
66
68
 
67
69
  col_labels = if i18n
68
70
  columns.map { |c| I18n.t("#{i18n}.#{self.name.underscore}.#{c}") }
@@ -1,6 +1,6 @@
1
1
  module Axlsx
2
2
  module Ar
3
3
  # The current version of the gem
4
- VERSION = "1.0.3"
4
+ VERSION = "1.0.4"
5
5
  end
6
6
  end
Binary file
@@ -19,6 +19,16 @@ class TestActsAsXlsx < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  class TestToXlsx < Test::Unit::TestCase
22
+ def test_to_xlsx_with_package
23
+ p = Post.to_xlsx
24
+ Post.to_xlsx :package=>p, :name=>'another posts'
25
+ assert_equal p.workbook.worksheets.size, 2
26
+ end
27
+
28
+ def test_to_xlsx_with_name
29
+ p = Post.to_xlsx :name=>'bob'
30
+ assert_equal(p.workbook.worksheets.first.name, 'bob')
31
+ end
22
32
 
23
33
  def test_xlsx_columns
24
34
  assert_equal( Post.xlsx_columns, Post.column_names.map {|c| c.to_sym})
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: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Randy Morgan
@@ -15,26 +15,28 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-06 00:00:00 Z
18
+ date: 2011-12-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
21
+ name: axlsx
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
22
24
  none: false
23
25
  requirements:
24
26
  - - ">="
25
27
  - !ruby/object:Gem::Version
26
- hash: 3
28
+ hash: 13
27
29
  segments:
28
30
  - 1
29
31
  - 0
30
- - 10
31
- version: 1.0.10
32
- requirement: *id001
32
+ - 13
33
+ version: 1.0.13
33
34
  type: :runtime
34
- prerelease: false
35
- name: axlsx
35
+ version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ name: activerecord
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
38
40
  none: false
39
41
  requirements:
40
42
  - - ">="
@@ -45,12 +47,12 @@ dependencies:
45
47
  - 3
46
48
  - 9
47
49
  version: 2.3.9
48
- requirement: *id002
49
50
  type: :runtime
50
- prerelease: false
51
- name: activerecord
51
+ version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ name: rake
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
54
56
  none: false
55
57
  requirements:
56
58
  - - ~>
@@ -60,12 +62,12 @@ dependencies:
60
62
  - 0
61
63
  - 9
62
64
  version: "0.9"
63
- requirement: *id003
64
65
  type: :development
65
- prerelease: false
66
- name: rake
66
+ version_requirements: *id003
67
67
  - !ruby/object:Gem::Dependency
68
- version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ name: bundler
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
69
71
  none: false
70
72
  requirements:
71
73
  - - ">="
@@ -74,12 +76,12 @@ dependencies:
74
76
  segments:
75
77
  - 0
76
78
  version: "0"
77
- requirement: *id004
78
79
  type: :development
79
- prerelease: false
80
- name: bundler
80
+ version_requirements: *id004
81
81
  - !ruby/object:Gem::Dependency
82
- version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ name: sqlite3
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
83
85
  none: false
84
86
  requirements:
85
87
  - - ">="
@@ -88,12 +90,12 @@ dependencies:
88
90
  segments:
89
91
  - 0
90
92
  version: "0"
91
- requirement: *id005
92
93
  type: :development
93
- prerelease: false
94
- name: sqlite3
94
+ version_requirements: *id005
95
95
  - !ruby/object:Gem::Dependency
96
- version_requirements: &id006 !ruby/object:Gem::Requirement
96
+ name: yard
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
97
99
  none: false
98
100
  requirements:
99
101
  - - ">="
@@ -102,12 +104,12 @@ dependencies:
102
104
  segments:
103
105
  - 0
104
106
  version: "0"
105
- requirement: *id006
106
107
  type: :development
107
- prerelease: false
108
- name: yard
108
+ version_requirements: *id006
109
109
  - !ruby/object:Gem::Dependency
110
- version_requirements: &id007 !ruby/object:Gem::Requirement
110
+ name: rdiscount
111
+ prerelease: false
112
+ requirement: &id007 !ruby/object:Gem::Requirement
111
113
  none: false
112
114
  requirements:
113
115
  - - ">="
@@ -116,11 +118,9 @@ dependencies:
116
118
  segments:
117
119
  - 0
118
120
  version: "0"
119
- requirement: *id007
120
121
  type: :development
121
- prerelease: false
122
- name: rdiscount
123
- description: " acts_as_xlsx lets you turn any ActiveRecord::Base inheriting class into an excel spreadsheet.\n"
122
+ version_requirements: *id007
123
+ description: " acts_as_xlsx lets you turn any ActiveRecord::Base inheriting class into an excel spreadsheet.\n It can be added to any finder method or scope chain and can use localized column and sheet names with I18n.\n"
124
124
  email: digital.ipseity@gmail.com
125
125
  executables: []
126
126
 
@@ -129,41 +129,22 @@ extensions: []
129
129
  extra_rdoc_files: []
130
130
 
131
131
  files:
132
- - doc/_index.html
133
- - doc/Axlsx/Ar/ClassMethods.html
134
- - doc/Axlsx/Ar/SingletonMethods.html
135
- - doc/Axlsx/Ar.html
136
- - doc/Axlsx.html
137
- - doc/class_list.html
138
- - doc/css/common.css
139
- - doc/css/full_list.css
140
- - doc/css/style.css
141
- - doc/file.CHANGELOG.html
142
- - doc/file.LICENSE.html
143
- - doc/file.README.html
144
- - doc/file_list.html
145
- - doc/frames.html
146
- - doc/index.html
147
- - doc/js/app.js
148
- - doc/js/full_list.js
149
- - doc/js/jquery.js
150
- - doc/method_list.html
151
- - doc/top-level-namespace.html
152
132
  - lib/acts_as_xlsx/ar.rb
153
133
  - lib/acts_as_xlsx/version.rb
154
134
  - lib/acts_as_xlsx/version.rb~
155
135
  - lib/acts_as_xlsx.rb
156
136
  - lib/acts_as_xlsx.rb~
137
+ - LICENSE
138
+ - README.md
139
+ - Rakefile
140
+ - CHANGELOG.md
141
+ - .yardopts
157
142
  - test/acts_as_xlsx.sqlite3.db
158
143
  - test/database.yml
159
144
  - test/helper.rb
160
145
  - test/helper.rb~
161
146
  - test/tc_acts_as_xlsx.rb
162
147
  - test/tc_acts_as_xlsx.rb~
163
- - LICENSE
164
- - README.md
165
- - Rakefile
166
- - CHANGELOG.md
167
148
  homepage: https://github.com/randym/acts_as_xlsx
168
149
  licenses: []
169
150
 
@@ -199,6 +180,11 @@ rubygems_version: 1.8.10
199
180
  signing_key:
200
181
  specification_version: 3
201
182
  summary: ActiveRecord support for Axlsx
202
- test_files: []
203
-
183
+ test_files:
184
+ - test/acts_as_xlsx.sqlite3.db
185
+ - test/database.yml
186
+ - test/helper.rb
187
+ - test/helper.rb~
188
+ - test/tc_acts_as_xlsx.rb
189
+ - test/tc_acts_as_xlsx.rb~
204
190
  has_rdoc: acts_as_xlsx
@@ -1,127 +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
8
-
9
- &mdash; acts_as_xlsx: a rails plug in for 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 (A)</a> &raquo;
37
-
38
-
39
- <span class="title">Axlsx</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
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/acts_as_xlsx/ar.rb<span class="defines">,<br />
76
- lib/acts_as_xlsx/version.rb</span>
77
- </dd>
78
-
79
- </dl>
80
- <div class="clear"></div>
81
-
82
- <h2>Overview</h2><div class="docstring">
83
- <div class="discussion">
84
- <p>
85
- Adding to the Axlsx module
86
- </p>
87
-
88
-
89
- </div>
90
- </div>
91
- <div class="tags">
92
-
93
-
94
- <h3>See Also:</h3>
95
- <ul class="see">
96
-
97
- <li><a href="http://github.com/randym/axlsx" target="_parent" title="http://github.com/randym/axlsx">http://github.com/randym/axlsx</a></li>
98
-
99
- </ul>
100
-
101
- </div><h2>Defined Under Namespace</h2>
102
- <p class="children">
103
-
104
-
105
- <strong class="modules">Modules:</strong> <span class='object_link'><a href="Axlsx/Ar.html" title="Axlsx::Ar (module)">Ar</a></span>
106
-
107
-
108
-
109
-
110
- </p>
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
- </div>
119
-
120
- <div id="footer">
121
- Generated on Tue Dec 6 18:49:19 2011 by
122
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
123
- 0.7.4 (ruby-1.8.7).
124
- </div>
125
-
126
- </body>
127
- </html>