acts_as_xlsx 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Acts As Xlsx (Axlsx)
9
+ &mdash; 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 Sat Dec 3 11:39:32 2011 by
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.3 (ruby-1.8.7).
99
+ 0.7.4 (ruby-1.8.7).
100
100
  </div>
101
101
 
102
102
  </body>
@@ -1,95 +1,7 @@
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] 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
+
@@ -0,0 +1,6 @@
1
+ module Axlsx
2
+ module Ar
3
+ # The current version of the gem
4
+ VERSION = "1.0.3"
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Axlsx
2
+ module Ar
3
+ version = "1.0.2"
4
+ end
5
+ end
Binary file
@@ -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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
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-03 00:00:00 Z
18
+ date: 2011-12-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: axlsx
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
- requirement: &id002 !ruby/object:Gem::Requirement
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
- version_requirements: *id002
50
+ prerelease: false
51
+ name: activerecord
52
52
  - !ruby/object:Gem::Dependency
53
- name: i18n
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
- requirement: &id003 !ruby/object:Gem::Requirement
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: 7
73
+ hash: 3
61
74
  segments:
62
75
  - 0
63
- - 6
64
- - 0
65
- version: 0.6.0
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
- requirement: &id004 !ruby/object:Gem::Requirement
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
- version_requirements: *id004
93
+ prerelease: false
94
+ name: sqlite3
82
95
  - !ruby/object:Gem::Dependency
83
- name: rake
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
- requirement: &id005 !ruby/object:Gem::Requirement
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: 63
115
+ hash: 3
91
116
  segments:
92
117
  - 0
93
- - 9
94
- - 2
95
- version: 0.9.2
118
+ version: "0"
119
+ requirement: *id007
96
120
  type: :development
97
- version_requirements: *id005
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: 3
180
+ hash: 57
152
181
  segments:
153
- - 0
154
- version: "0"
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: