acts_as_xlsx 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.
- data/README.md +12 -4
- data/Rakefile +6 -0
- data/doc/Axlsx.html +6 -4
- data/doc/Axlsx/Ar.html +35 -8
- data/doc/Axlsx/Ar/ClassMethods.html +14 -14
- data/doc/Axlsx/Ar/SingletonMethods.html +41 -41
- data/doc/_index.html +7 -4
- data/doc/css/style.css +10 -10
- data/doc/file.CHANGELOG.html +67 -0
- data/doc/file.LICENSE.html +3 -3
- data/doc/file.README.html +43 -32
- data/doc/file_list.html +3 -0
- data/doc/frames.html +1 -1
- data/doc/index.html +43 -32
- data/doc/js/app.js +4 -4
- data/doc/top-level-namespace.html +3 -3
- data/lib/acts_as_xlsx.rb +6 -94
- data/lib/acts_as_xlsx.rb~ +0 -0
- data/lib/acts_as_xlsx/ar.rb +95 -0
- data/lib/acts_as_xlsx/version.rb +6 -0
- data/lib/acts_as_xlsx/version.rb~ +5 -0
- data/test/acts_as_xlsx.sqlite3.db +0 -0
- data/test/helper.rb~ +9 -0
- data/test/tc_acts_as_xlsx.rb~ +0 -0
- metadata +73 -42
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -44
- data/acts_as_xlsx.gemspec +0 -34
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Top Level Namespace
|
8
8
|
|
9
|
-
—
|
9
|
+
— acts_as_xlsx: a rails plug in for axlsx
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -94,9 +94,9 @@
|
|
94
94
|
</div>
|
95
95
|
|
96
96
|
<div id="footer">
|
97
|
-
Generated on
|
97
|
+
Generated on Tue Dec 6 18:49:19 2011 by
|
98
98
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
99
|
-
0.7.
|
99
|
+
0.7.4 (ruby-1.8.7).
|
100
100
|
</div>
|
101
101
|
|
102
102
|
</body>
|
data/lib/acts_as_xlsx.rb
CHANGED
@@ -1,95 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# Adding to the Axlsx module
|
9
|
-
# @see http://github.com/randym/axlsx
|
10
|
-
module Axlsx
|
11
|
-
# === Overview
|
12
|
-
# This module defines the acts_as_xlsx class method and provides to_xlsx support to both AR classes and instances
|
13
|
-
module Ar
|
14
|
-
|
15
|
-
def self.included(base) # :nodoc:
|
16
|
-
base.send :extend, ClassMethods
|
17
|
-
end
|
18
|
-
|
19
|
-
# Class methods for the mixin
|
20
|
-
module ClassMethods
|
21
|
-
|
22
|
-
# defines the class method to inject to_xlsx
|
23
|
-
# @option options [Array, Symbol] columns an array of symbols defining the columns and methods to call in generating sheet data for each row.
|
24
|
-
# @option options [String] i18n (default nil) The path to search for localization. When this is specified your i18n.t will be used to determine the labels for columns.
|
25
|
-
# @example
|
26
|
-
# class MyModel < ActiveRecord::Base
|
27
|
-
# acts_as_xlsx :columns=> [:id, :created_at, :updated_at], :i18n => 'activerecord.attributes'
|
28
|
-
def acts_as_xlsx(options={})
|
29
|
-
cattr_accessor :xlsx_i18n, :xlsx_columns
|
30
|
-
self.xlsx_i18n = options.delete(:i18n) || false
|
31
|
-
self.xlsx_columns = options.delete(:columns) || self.column_names.map { |c| c = c.to_sym }
|
32
|
-
extend Axlsx::Ar::SingletonMethods
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Singleton methods for the mixin
|
37
|
-
module SingletonMethods
|
38
|
-
|
39
|
-
# Maps the AR class to an Axlsx package
|
40
|
-
# options are passed into AR find
|
41
|
-
# @param [Array, Array] columns as an array of symbols or a symbol that defines the attributes or methods to render in the sheet.
|
42
|
-
# @option options [Integer] header_style to apply to the first row of field names
|
43
|
-
# @option options [Array, Symbol] an array of Axlsx types for each cell in data rows or a single type that will be applied to all types.
|
44
|
-
# @option options [Integer, Array] style The style to pass to Worksheet#add_row
|
45
|
-
# @option options [String] i18n The path to i18n attributes. (usually activerecord.attributes)
|
46
|
-
# @see Worksheet#add_row
|
47
|
-
def to_xlsx(options = {})
|
48
|
-
|
49
|
-
row_style = options.delete(:style)
|
50
|
-
header_style = options.delete(:header_style) || row_style
|
51
|
-
types = [options.delete(:types) || []].flatten
|
52
|
-
|
53
|
-
i18n = options.delete(:i18n) || self.xlsx_i18n
|
54
|
-
columns = options.delete(:columns) || self.xlsx_columns
|
55
|
-
|
56
|
-
p = Package.new
|
57
|
-
row_style = p.workbook.styles.add_style(row_style) unless row_style.nil?
|
58
|
-
header_style = p.workbook.styles.add_style(header_style) unless header_style.nil?
|
59
|
-
|
60
|
-
data = [*find(:all, options)]
|
61
|
-
data.compact!
|
62
|
-
data.flatten!
|
63
|
-
|
64
|
-
return p if data.empty?
|
65
|
-
p.workbook.add_worksheet(:name=>table_name.humanize) do |sheet|
|
66
|
-
|
67
|
-
col_labels = if i18n
|
68
|
-
columns.map { |c| I18n.t("#{i18n}.#{self.name.underscore}.#{c}") }
|
69
|
-
else
|
70
|
-
columns.map { |c| c.to_s.humanize }
|
71
|
-
end
|
72
|
-
|
73
|
-
sheet.add_row col_labels, :style=>header_style
|
74
|
-
|
75
|
-
data.each do |r|
|
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
|
84
|
-
end
|
85
|
-
end
|
86
|
-
p
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
1
|
+
require 'acts_as_xlsx/ar.rb'
|
2
|
+
begin
|
3
|
+
# The mime type to be used in respond_to |format| style web-services in rails
|
4
|
+
Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
|
5
|
+
rescue NameError
|
6
|
+
puts "Mime module not defines. Skipping registration of xlsx"
|
90
7
|
end
|
91
|
-
|
92
|
-
require 'active_record'
|
93
|
-
ActiveRecord::Base.send :include, Axlsx::Ar
|
94
|
-
|
95
|
-
|
File without changes
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Axlsx is a gem or generating excel spreadsheets with charts, images and many other features.
|
3
|
+
#
|
4
|
+
# acts_as_xlsx provides integration into active_record for Axlsx.
|
5
|
+
#
|
6
|
+
require 'axlsx'
|
7
|
+
|
8
|
+
# Adding to the Axlsx module
|
9
|
+
# @see http://github.com/randym/axlsx
|
10
|
+
module Axlsx
|
11
|
+
# === Overview
|
12
|
+
# This module defines the acts_as_xlsx class method and provides to_xlsx support to both AR classes and instances
|
13
|
+
module Ar
|
14
|
+
|
15
|
+
def self.included(base) # :nodoc:
|
16
|
+
base.send :extend, ClassMethods
|
17
|
+
end
|
18
|
+
|
19
|
+
# Class methods for the mixin
|
20
|
+
module ClassMethods
|
21
|
+
|
22
|
+
# defines the class method to inject to_xlsx
|
23
|
+
# @option options [Array, Symbol] columns an array of symbols defining the columns and methods to call in generating sheet data for each row.
|
24
|
+
# @option options [String] i18n (default nil) The path to search for localization. When this is specified your i18n.t will be used to determine the labels for columns.
|
25
|
+
# @example
|
26
|
+
# class MyModel < ActiveRecord::Base
|
27
|
+
# acts_as_xlsx :columns=> [:id, :created_at, :updated_at], :i18n => 'activerecord.attributes'
|
28
|
+
def acts_as_xlsx(options={})
|
29
|
+
cattr_accessor :xlsx_i18n, :xlsx_columns
|
30
|
+
self.xlsx_i18n = options.delete(:i18n) || false
|
31
|
+
self.xlsx_columns = options.delete(:columns) || self.column_names.map { |c| c = c.to_sym }
|
32
|
+
extend Axlsx::Ar::SingletonMethods
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Singleton methods for the mixin
|
37
|
+
module SingletonMethods
|
38
|
+
|
39
|
+
# Maps the AR class to an Axlsx package
|
40
|
+
# options are passed into AR find
|
41
|
+
# @param [Array, Array] columns as an array of symbols or a symbol that defines the attributes or methods to render in the sheet.
|
42
|
+
# @option options [Integer] header_style to apply to the first row of field names
|
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
|
+
# @option options [Integer, Array] style The style to pass to Worksheet#add_row
|
45
|
+
# @option options [String] i18n The path to i18n attributes. (usually activerecord.attributes)
|
46
|
+
# @see Worksheet#add_row
|
47
|
+
def to_xlsx(options = {})
|
48
|
+
|
49
|
+
row_style = options.delete(:style)
|
50
|
+
header_style = options.delete(:header_style) || row_style
|
51
|
+
types = [options.delete(:types) || []].flatten
|
52
|
+
|
53
|
+
i18n = options.delete(:i18n) || self.xlsx_i18n
|
54
|
+
columns = options.delete(:columns) || self.xlsx_columns
|
55
|
+
|
56
|
+
p = Package.new
|
57
|
+
row_style = p.workbook.styles.add_style(row_style) unless row_style.nil?
|
58
|
+
header_style = p.workbook.styles.add_style(header_style) unless header_style.nil?
|
59
|
+
|
60
|
+
data = [*find(:all, options)]
|
61
|
+
data.compact!
|
62
|
+
data.flatten!
|
63
|
+
|
64
|
+
return p if data.empty?
|
65
|
+
p.workbook.add_worksheet(:name=>table_name.humanize) do |sheet|
|
66
|
+
|
67
|
+
col_labels = if i18n
|
68
|
+
columns.map { |c| I18n.t("#{i18n}.#{self.name.underscore}.#{c}") }
|
69
|
+
else
|
70
|
+
columns.map { |c| c.to_s.humanize }
|
71
|
+
end
|
72
|
+
|
73
|
+
sheet.add_row col_labels, :style=>header_style
|
74
|
+
|
75
|
+
data.each do |r|
|
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
|
84
|
+
end
|
85
|
+
end
|
86
|
+
p
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
require 'active_record'
|
93
|
+
ActiveRecord::Base.send :include, Axlsx::Ar
|
94
|
+
|
95
|
+
|
Binary file
|
data/test/helper.rb~
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'acts_as_xlsx'
|
2
|
+
|
3
|
+
|
4
|
+
def load_schema
|
5
|
+
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
6
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
7
|
+
ActiveRecord::Base.establish_connection(config['sqlite3'])
|
8
|
+
load(File.dirname(__FILE__) + "/schema.rb")
|
9
|
+
end
|
File without changes
|
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:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 3
|
10
|
+
version: 1.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Randy Morgan
|
@@ -15,12 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-12-
|
18
|
+
date: 2011-12-06 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
22
|
none: false
|
25
23
|
requirements:
|
26
24
|
- - ">="
|
@@ -31,12 +29,12 @@ dependencies:
|
|
31
29
|
- 0
|
32
30
|
- 10
|
33
31
|
version: 1.0.10
|
32
|
+
requirement: *id001
|
34
33
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: activerecord
|
38
34
|
prerelease: false
|
39
|
-
|
35
|
+
name: axlsx
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
38
|
none: false
|
41
39
|
requirements:
|
42
40
|
- - ">="
|
@@ -47,28 +45,41 @@ dependencies:
|
|
47
45
|
- 3
|
48
46
|
- 9
|
49
47
|
version: 2.3.9
|
48
|
+
requirement: *id002
|
50
49
|
type: :runtime
|
51
|
-
|
50
|
+
prerelease: false
|
51
|
+
name: activerecord
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
|
-
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 25
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
- 9
|
62
|
+
version: "0.9"
|
63
|
+
requirement: *id003
|
64
|
+
type: :development
|
54
65
|
prerelease: false
|
55
|
-
|
66
|
+
name: rake
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
56
69
|
none: false
|
57
70
|
requirements:
|
58
71
|
- - ">="
|
59
72
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
73
|
+
hash: 3
|
61
74
|
segments:
|
62
75
|
- 0
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
type: :runtime
|
67
|
-
version_requirements: *id003
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: sqlite3
|
76
|
+
version: "0"
|
77
|
+
requirement: *id004
|
78
|
+
type: :development
|
70
79
|
prerelease: false
|
71
|
-
|
80
|
+
name: bundler
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ">="
|
@@ -77,24 +88,38 @@ dependencies:
|
|
77
88
|
segments:
|
78
89
|
- 0
|
79
90
|
version: "0"
|
91
|
+
requirement: *id005
|
80
92
|
type: :development
|
81
|
-
|
93
|
+
prerelease: false
|
94
|
+
name: sqlite3
|
82
95
|
- !ruby/object:Gem::Dependency
|
83
|
-
|
96
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirement: *id006
|
106
|
+
type: :development
|
84
107
|
prerelease: false
|
85
|
-
|
108
|
+
name: yard
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
86
111
|
none: false
|
87
112
|
requirements:
|
88
113
|
- - ">="
|
89
114
|
- !ruby/object:Gem::Version
|
90
|
-
hash:
|
115
|
+
hash: 3
|
91
116
|
segments:
|
92
117
|
- 0
|
93
|
-
|
94
|
-
|
95
|
-
version: 0.9.2
|
118
|
+
version: "0"
|
119
|
+
requirement: *id007
|
96
120
|
type: :development
|
97
|
-
|
121
|
+
prerelease: false
|
122
|
+
name: rdiscount
|
98
123
|
description: " acts_as_xlsx lets you turn any ActiveRecord::Base inheriting class into an excel spreadsheet.\n"
|
99
124
|
email: digital.ipseity@gmail.com
|
100
125
|
executables: []
|
@@ -104,14 +129,6 @@ extensions: []
|
|
104
129
|
extra_rdoc_files: []
|
105
130
|
|
106
131
|
files:
|
107
|
-
- acts_as_xlsx.gemspec
|
108
|
-
- CHANGELOG.md
|
109
|
-
- Gemfile
|
110
|
-
- Gemfile.lock
|
111
|
-
- LICENSE
|
112
|
-
- Rakefile
|
113
|
-
- README.md
|
114
|
-
- lib/acts_as_xlsx.rb
|
115
132
|
- doc/_index.html
|
116
133
|
- doc/Axlsx/Ar/ClassMethods.html
|
117
134
|
- doc/Axlsx/Ar/SingletonMethods.html
|
@@ -121,6 +138,7 @@ files:
|
|
121
138
|
- doc/css/common.css
|
122
139
|
- doc/css/full_list.css
|
123
140
|
- doc/css/style.css
|
141
|
+
- doc/file.CHANGELOG.html
|
124
142
|
- doc/file.LICENSE.html
|
125
143
|
- doc/file.README.html
|
126
144
|
- doc/file_list.html
|
@@ -131,10 +149,21 @@ files:
|
|
131
149
|
- doc/js/jquery.js
|
132
150
|
- doc/method_list.html
|
133
151
|
- doc/top-level-namespace.html
|
152
|
+
- lib/acts_as_xlsx/ar.rb
|
153
|
+
- lib/acts_as_xlsx/version.rb
|
154
|
+
- lib/acts_as_xlsx/version.rb~
|
155
|
+
- lib/acts_as_xlsx.rb
|
156
|
+
- lib/acts_as_xlsx.rb~
|
134
157
|
- test/acts_as_xlsx.sqlite3.db
|
135
158
|
- test/database.yml
|
136
159
|
- test/helper.rb
|
160
|
+
- test/helper.rb~
|
137
161
|
- test/tc_acts_as_xlsx.rb
|
162
|
+
- test/tc_acts_as_xlsx.rb~
|
163
|
+
- LICENSE
|
164
|
+
- README.md
|
165
|
+
- Rakefile
|
166
|
+
- CHANGELOG.md
|
138
167
|
homepage: https://github.com/randym/acts_as_xlsx
|
139
168
|
licenses: []
|
140
169
|
|
@@ -148,10 +177,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
177
|
requirements:
|
149
178
|
- - ">="
|
150
179
|
- !ruby/object:Gem::Version
|
151
|
-
hash:
|
180
|
+
hash: 57
|
152
181
|
segments:
|
153
|
-
-
|
154
|
-
|
182
|
+
- 1
|
183
|
+
- 8
|
184
|
+
- 7
|
185
|
+
version: 1.8.7
|
155
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
187
|
none: false
|
157
188
|
requirements:
|