to_xls-rails 1.2.4 → 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: 8ba1b200c866f319a584ad8f3032158de948cec0
4
- data.tar.gz: 3a0e4b1bb36b0da889ea388fc94d87f7101d018d
3
+ metadata.gz: cc85729ab994d87bba3fdf13b49dfa92733ae35d
4
+ data.tar.gz: fdc0cac96d55a7c464874e578c5764723b431b2b
5
5
  SHA512:
6
- metadata.gz: ee49ac54a35ded1d7994d89a89e55f84e933004842d32c975f9d39999ec62e5ea857bb8e0588a8ffa4a0b05d1f637ca176e76c9ea6950cfbae535721c4bd0b00
7
- data.tar.gz: 5a51296bc1f13dccaac9e938e7a08bdab4c6efac81bfdc69fabc5d6143fa56f22d9e2f80505291d1c77612396a12ec579e9c4c49c7345c106a7d59a9b8235d94
6
+ metadata.gz: 5ee3489afa3488a7f7c799bd047c481163c82fed92a800489359b7d220197f0542e7b3b38d66d6f114b3fdcb146d5a420d6ddc709aec1669ea839048186f5007
7
+ data.tar.gz: 140d26d179ca13a1e8bfe678df3cdf2ef392b73af58b609caed766a5a9026416c91655be6183d6282aeff6c0a1b6965ca3e253375a47c77369af831be62a8e35
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in refinerycms-multisite.gemspec
4
- gemspec
5
-
6
- gem 'spreadsheet', '>= 0.8.5'
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in refinerycms-multisite.gemspec
4
+ gemspec
5
+
6
+ gem 'spreadsheet', '>= 0.8.5'
@@ -1,20 +1,20 @@
1
- Copyright (c) 2010 [name of plugin creator]
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,111 +1,118 @@
1
- == to_xls-rails
2
-
3
- This simple plugin gives you the ability to call to_xls to a collection of activerecords for Rails.
4
-
5
-
6
- In your Gemfile:
7
-
8
- gem 'to_xls-rails'# Last officially released gem
9
- # gem "to_xls-rails", :git => "git://github.com/liangwenke/to_xls-rails.git" # Track git repo
10
-
11
- or, to install as a gem:
12
-
13
- gem install to_xls-rails
14
-
15
- or, to install as a plugin:
16
-
17
- rails plugin install git://github.com/liangwenke/to_xls-rails.git
18
-
19
- In your controller:
20
-
21
- def index
22
- @posts = Post.all
23
-
24
- respond_to do |format|
25
- format.html
26
- format.xls { send_data(@posts.to_xls) }
27
- # format.xls {
28
- # filename = "Posts-#{Time.now.strftime("%Y%m%d%H%M%S")}.xls"
29
- # send_data(@posts.to_xls, :type => "text/xls; charset=utf-8; header=present", :filename => filename)
30
- # }
31
- end
32
- end
33
-
34
- In your view:
35
-
36
- <%= link_to 'Excel Download', posts_path(:format => :xls %>
37
-
38
-
39
- == Usage
40
-
41
- add below to RAILS_ROOT/config/initializers/mime_types.rb
42
- Mime::Type.register_alias "text/excel", :xls
43
-
44
- @posts = Post.all
45
-
46
- #
47
- # default are export header and all fileds
48
- #
49
-
50
- @posts.to_xls
51
- @posts.to_xls(:only => [:title, :body])
52
- @posts.to_xls(:except => [:id])
53
- @posts.to_xls(:header => false)
54
-
55
- # Will prepend above header
56
- # | Col 0, Row 0 | Col 1, Row 0 |
57
- # | Col 0, Row 1 | |
58
- @posts.to_xls(:prepend => [["Col 0, Row 0", "Col 1, Row 0"], ["Col 0, Row 1"]])
59
-
60
- # Translation of a column-value
61
- @posts.to_xls{|column, value, row_index| column==:salutation ? t(value) + " at #{row_index}" : value}
62
-
63
- # Added width options
64
- @posts.to_xls(:column_width => [17,15,15,40,25,37])
65
-
66
-
67
- == Example
68
-
69
- class PostsController < ApplicationController
70
- def index
71
- @posts = Post.all
72
-
73
- respond_to do |format|
74
- format.xls { send_data(@posts.to_xls) }
75
- # format.xls {
76
- # filename = "posts-#{Time.now.strftime("%Y%m%d%H%M%S")}.xls"
77
- # send_data(@posts.to_xls, :type => "application/excel; charset=utf-8; header=present", :filename => filename)
78
- # }
79
- end
80
- end
81
- end
82
-
83
-
84
- Works on Rails 3:
85
-
86
- class PostsController < ApplicationController
87
- def index
88
- # add this to config/initializers/mime_types.rb
89
- Mime::Type.register "application/vnd.ms-excel", :xls
90
-
91
- @posts = Post.all
92
-
93
- respond_to do |format|
94
- format.xls {
95
- send_data @posts.to_xls
96
- return # prevet Rails to seek for index.xls.erb
97
- }
98
- end
99
- end
100
- end
101
-
102
-
103
- == Contributors
104
-
105
- * {Juan Pablo Marzetti}[http://github.com/yonpols] Added Support for Value-Substitution
106
- * {Denis Yagofarov}[http://github.com/denyago] Added prepend some data above header and access current array element index in &block
107
-
108
-
109
- == Note
110
-
111
- Copyright (c) 2010 liangwenke.com@gmail.com, released under the MIT license
1
+ == to_xls-rails
2
+
3
+ This simple plugin gives you the ability to call to_xls to a collection of activerecords for Rails.
4
+
5
+
6
+ In your Gemfile:
7
+
8
+ gem 'to_xls-rails'# Last officially released gem
9
+ # gem "to_xls-rails", :git => "git://github.com/liangwenke/to_xls-rails.git" # Track git repo
10
+
11
+ or, to install as a gem:
12
+
13
+ gem install to_xls-rails
14
+
15
+ or, to install as a plugin:
16
+
17
+ rails plugin install git://github.com/liangwenke/to_xls-rails.git
18
+
19
+ In your controller:
20
+
21
+ def index
22
+ @posts = Post.all
23
+
24
+ respond_to do |format|
25
+ format.html # don't forget if you pass html
26
+ format.xls { send_data(@posts.to_xls) }
27
+ # format.xls {
28
+ # filename = "Posts-#{Time.now.strftime("%Y%m%d%H%M%S")}.xls"
29
+ # send_data(@posts.to_xls, :type => "text/xls; charset=utf-8; header=present", :filename => filename)
30
+ # }
31
+ end
32
+ end
33
+
34
+ In your view:
35
+
36
+ <%= link_to 'Excel Download', posts_path(:format => :xls) %>
37
+
38
+
39
+ == Usage
40
+
41
+ add below to RAILS_ROOT/config/initializers/mime_types.rb
42
+ Mime::Type.register_alias "text/excel", :xls
43
+
44
+ @posts = Post.all
45
+
46
+ #
47
+ # default are export header and all fileds
48
+ #
49
+
50
+ @posts.to_xls
51
+ @posts.to_xls(:only => [:title, :body])
52
+ @posts.to_xls(:except => [:id])
53
+ @posts.to_xls(:header => false)
54
+
55
+ # Array of Hashes support
56
+ [ { name: 'ruby', version: '2.1.0' }, { name: 'rails', version: '4.1.0' } ].to_xls
57
+
58
+ # Will prepend above header
59
+ # | Col 0, Row 0 | Col 1, Row 0 |
60
+ # | Col 0, Row 1 | |
61
+ @posts.to_xls(:prepend => [["Col 0, Row 0", "Col 1, Row 0"], ["Col 0, Row 1"]])
62
+
63
+ # Translation of a column-value
64
+ @posts.to_xls{|column, value, row_index| column==:salutation ? t(value) + " at #{row_index}" : value}
65
+
66
+ # Added width options
67
+ @posts.to_xls(:column_width => [17,15,15,40,25,37])
68
+
69
+
70
+ == Example
71
+
72
+ class PostsController < ApplicationController
73
+ def index
74
+ @posts = Post.all
75
+
76
+ respond_to do |format|
77
+ format.xls { send_data(@posts.to_xls) }
78
+ # format.xls {
79
+ # filename = "posts-#{Time.now.strftime("%Y%m%d%H%M%S")}.xls"
80
+ # send_data(@posts.to_xls, :type => "application/excel; charset=utf-8; header=present", :filename => filename)
81
+ # }
82
+ end
83
+ end
84
+ end
85
+
86
+
87
+ Works on Rails 3:
88
+
89
+ class PostsController < ApplicationController
90
+ def index
91
+ # add this to config/initializers/mime_types.rb
92
+ Mime::Type.register "application/vnd.ms-excel", :xls
93
+
94
+ @posts = Post.all
95
+
96
+ respond_to do |format|
97
+ format.xls {
98
+ send_data @posts.to_xls
99
+ return # prevet Rails to seek for index.xls.erb
100
+ }
101
+ end
102
+ end
103
+ end
104
+
105
+
106
+ == Contributors
107
+
108
+ * {Juan Pablo Marzetti}[http://github.com/yonpols]
109
+ * {Denis Yagofarov}[http://github.com/denyago]
110
+ * {MrCherry}[https://github.com/MrCherry]
111
+ * {Andreas König}[https://github.com/koa]
112
+ * {nikneroz}[https://github.com/nikneroz]
113
+ * {Gordon B. Isnor}[https://github.com/gordonbisnor]
114
+
115
+
116
+ == Note
117
+
118
+ Copyright (c) 2010 liangwenke.com@gmail.com, released under the MIT license
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
- require 'rake/gempackagetask'
5
-
6
- desc 'Default: run unit tests.'
7
- task :default => :test
8
-
9
- desc 'Test the to_xls-rails plugin.'
10
- Rake::TestTask.new(:test) do |t|
11
- t.libs << 'lib'
12
- t.libs << 'test'
13
- t.pattern = 'test/**/*_test.rb'
14
- t.verbose = true
15
- end
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the to_xls-rails plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.4
1
+ 1.3.0
data/init.rb CHANGED
@@ -1 +1 @@
1
- require 'to_xls-rails'
1
+ require 'to_xls-rails'
@@ -1,59 +1,70 @@
1
- require 'spreadsheet'
2
-
3
- class Array
4
-
5
- def to_xls(options = {}, &block)
6
-
7
- return '' if self.empty? && options[:prepend].blank?
8
-
9
- columns = []
10
- options.reverse_merge!(:header => true)
11
-
12
- xls_report = StringIO.new
13
-
14
- Spreadsheet.client_encoding = options[:client_encoding] || "UTF-8"
15
-
16
- book = Spreadsheet::Workbook.new
17
- sheet = book.create_worksheet
18
-
19
- if options[:only]
20
- columns = Array(options[:only]).map(&:to_sym)
21
- elsif !self.empty?
22
- columns = self.first.class.column_names.map(&:to_sym) - Array(options[:except]).map(&:to_sym)
23
- end
24
-
25
- return '' if columns.empty? && options[:prepend].blank?
26
-
27
- sheet_index = 0
28
-
29
- unless options[:prepend].blank?
30
- options[:prepend].each do |array|
31
- sheet.row(sheet_index).concat(array)
32
- sheet_index += 1
33
- end
34
- end
35
-
36
- if options[:header]
37
- sheet.row(sheet_index).concat(options[:header_columns].blank? ? columns.map(&:to_s).map(&:humanize) : options[:header_columns])
38
- sheet_index += 1
39
- end
40
-
41
- if options[:column_width]
42
- options[:column_width].each_index {|index| sheet.column(index).width = options[:column_width][index]}
43
- end
44
-
45
- self.each_with_index do |obj, index|
46
- if block
47
- sheet.row(sheet_index).replace(columns.map { |column| block.call(column, obj.send(column), index) })
48
- else
49
- sheet.row(sheet_index).replace(columns.map { |column| obj.send(column) })
50
- end
51
- sheet_index += 1
52
- end
53
-
54
- book.write(xls_report)
55
-
56
- xls_report.string
57
- end
58
-
59
- end
1
+ require 'spreadsheet'
2
+
3
+ class Array
4
+
5
+ def to_xls(options = {}, &block)
6
+
7
+ return '' if self.empty? && options[:prepend].blank?
8
+
9
+ columns = []
10
+ options.reverse_merge!(:header => true)
11
+
12
+ xls_report = StringIO.new
13
+
14
+ Spreadsheet.client_encoding = options[:client_encoding] || "UTF-8"
15
+
16
+ book = Spreadsheet::Workbook.new
17
+ sheet = book.create_worksheet
18
+
19
+ if options[:only]
20
+ columns = Array(options[:only]).map(&:to_sym)
21
+ elsif !self.empty?
22
+ if self.first.is_a? Hash
23
+ columns = self.first.keys.map(&:to_sym) - Array(options[:except]).map(&:to_sym)
24
+ else
25
+ columns = self.first.class.attributes.keys.map(&:to_sym) - Array(options[:except]).map(&:to_sym)
26
+ end
27
+ end
28
+
29
+ return '' if columns.empty? && options[:prepend].blank?
30
+
31
+ sheet_index = 0
32
+
33
+ unless options[:prepend].blank?
34
+ options[:prepend].each do |array|
35
+ sheet.row(sheet_index).concat(array)
36
+ sheet_index += 1
37
+ end
38
+ end
39
+
40
+ if options[:header]
41
+ sheet.row(sheet_index).concat(options[:header_columns].blank? ? columns.map(&:to_s).map(&:humanize) : options[:header_columns])
42
+ sheet_index += 1
43
+ end
44
+
45
+ if options[:column_width]
46
+ options[:column_width].each_index {|index| sheet.column(index).width = options[:column_width][index]}
47
+ end
48
+
49
+ self.each_with_index do |obj, index|
50
+ if block
51
+ sheet.row(sheet_index).replace(columns.map { |column| block.call(column, obj.is_a?(Hash) ? obj[column] : obj.send(column), index) })
52
+ else
53
+ sheet.row(sheet_index).replace(columns.map { |column| obj.is_a?(Hash) ? obj[column] : obj.send(column) })
54
+ end
55
+ sheet_index += 1
56
+ end
57
+
58
+ unless options[:append].blank?
59
+ options[:append].each do |array|
60
+ sheet.row(sheet_index).concat(array)
61
+ sheet_index += 1
62
+ end
63
+ end
64
+
65
+ book.write(xls_report)
66
+
67
+ xls_report.string
68
+ end
69
+
70
+ end
@@ -1,22 +1,22 @@
1
- # encoding: utf-8
2
-
3
- version = File.read(File.expand_path("../VERSION", __FILE__)).strip
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'to_xls-rails'
7
- spec.version = version
8
- spec.author = "Mike Liang"
9
- spec.email = "liangwenke.com@gmail.com"
10
- spec.homepage = "http://github.com/liangwenke/to_xls-rails"
11
- spec.summary = "Export Rails ActiveRecord data to excel file"
12
- spec.description = "This simple plugin gives you the ability to call to_xls to a collection of activerecords for Rails."
13
-
14
- spec.files = Dir["{lib,test}/**/*", "[a-zA-Z]*", "init.rb"] - ["Gemfile.lock"]
15
- spec.require_path = "lib"
16
- spec.license = 'MIT'
17
-
18
- spec.add_dependency('spreadsheet', '>= 0.8.5')
19
-
20
- spec.platform = Gem::Platform::RUBY
21
- spec.required_rubygems_version = ">= 1.3.4"
22
- end
1
+ # encoding: utf-8
2
+
3
+ version = File.read(File.expand_path("../VERSION", __FILE__)).strip
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'to_xls-rails'
7
+ spec.version = version
8
+ spec.author = "Mike Liang"
9
+ spec.email = "liangwenke.com@gmail.com"
10
+ spec.homepage = "http://github.com/liangwenke/to_xls-rails"
11
+ spec.summary = "Export Rails ActiveRecord data to excel file"
12
+ spec.description = "This simple plugin gives you the ability to call to_xls to a collection of activerecords for Rails."
13
+
14
+ spec.files = Dir["{lib,test}/**/*", "[a-zA-Z]*", "init.rb"] - ["Gemfile.lock"]
15
+ spec.require_path = "lib"
16
+ spec.license = 'MIT'
17
+
18
+ spec.add_dependency('spreadsheet', '>= 0.8.5')
19
+
20
+ spec.platform = Gem::Platform::RUBY
21
+ spec.required_rubygems_version = ">= 1.3.4"
22
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_xls-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Liang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-24 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spreadsheet
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.8.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.8.5
27
27
  description: This simple plugin gives you the ability to call to_xls to a collection
@@ -31,14 +31,14 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - lib/to_xls-rails.rb
35
34
  - Gemfile
36
- - init.rb
37
35
  - MIT-LICENSE
38
- - Rakefile
39
36
  - README.rdoc
40
- - to_xls-rails.gemspec
37
+ - Rakefile
41
38
  - VERSION
39
+ - init.rb
40
+ - lib/to_xls-rails.rb
41
+ - to_xls-rails.gemspec
42
42
  homepage: http://github.com/liangwenke/to_xls-rails
43
43
  licenses:
44
44
  - MIT
@@ -49,17 +49,17 @@ require_paths:
49
49
  - lib
50
50
  required_ruby_version: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - '>='
57
+ - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: 1.3.4
60
60
  requirements: []
61
61
  rubyforge_project:
62
- rubygems_version: 2.0.0
62
+ rubygems_version: 2.2.2
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: Export Rails ActiveRecord data to excel file