ruby2xlsx 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +8 -8
- data/lib/ruby2xlsx.rb +6 -6
- data/lib/ruby2xlsx/base.rb +7 -7
- data/lib/ruby2xlsx/document.rb +18 -18
- data/lib/ruby2xlsx/engine.rb +5 -3
- data/lib/ruby2xlsx/version.rb +1 -1
- metadata +16 -17
- data/lib/tasks/ruby2xlsx_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b19a9586278d113d34660eac59c9f4c1d3ed22e9
|
4
|
+
data.tar.gz: 8e874b6ea63d7027c763637379ee324185500936
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91edd945b70d6eb29de52792c5314d5c09a1db3fb442694858014ca9b03ee1be07422a7358a06c9880b25950f83aa60f4395ddb667c4bc788c026223ae7cd07b
|
7
|
+
data.tar.gz: 94bc04c690624d31274daab915d27d1d3c5d993c5f9d1b606dad6cdb0fbf62610b9ecc2c84bf1904d8b90abe0a6392783b9bb8571e29a48ba177a586f116c4fb
|
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ Export your data to Excel. Provide two ways for export data: template or rendere
|
|
4
4
|
|
5
5
|
== Install
|
6
6
|
|
7
|
-
|
7
|
+
Add gem to your Gemfile:
|
8
8
|
|
9
9
|
gem "ruby2xlsx"
|
10
10
|
|
@@ -25,8 +25,8 @@ You can use two types: template and renderer.
|
|
25
25
|
|
26
26
|
With options:
|
27
27
|
|
28
|
-
format.xlsx { render xlsx: @articles,
|
29
|
-
:columns => [:id, :title, :updated_at],
|
28
|
+
format.xlsx { render xlsx: @articles,
|
29
|
+
:columns => [:id, :title, :updated_at],
|
30
30
|
:filename => ["articles_", Time.now.to_s, ".xlsx"].join,
|
31
31
|
:worksheet_name => "My articles" }
|
32
32
|
|
@@ -36,22 +36,22 @@ In controller (app/controllers/articles_controller.rb):
|
|
36
36
|
|
37
37
|
class ArticlesController < ApplicationController
|
38
38
|
respond_to :xlsx, :only => [:index]
|
39
|
-
|
39
|
+
|
40
40
|
def index
|
41
41
|
@articles = Article.order('id DESC')
|
42
42
|
@xlsx_filename = "some_file_name"
|
43
|
-
|
43
|
+
|
44
44
|
respond_with(@articles)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
In view (app/views/articles/index.xlsx.xrb):
|
49
|
-
|
49
|
+
|
50
50
|
add_worksheet "Data"
|
51
51
|
|
52
52
|
bold = add_format(:bold => 1)
|
53
53
|
headings = [ 'Title', 'Views', 'Comments' ]
|
54
|
-
|
54
|
+
|
55
55
|
write('A1', headings, bold)
|
56
56
|
|
57
57
|
@articles.each_with_index do |article, index|
|
@@ -60,7 +60,7 @@ In view (app/views/articles/index.xlsx.xrb):
|
|
60
60
|
write(row, 1, article.views_count)
|
61
61
|
write(row, 2, article.comments_count)
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
chart4 = add_chart(:name => 'Results Chart', :type => 'Chart::Area')
|
65
65
|
|
66
66
|
# Configure the series.
|
data/lib/ruby2xlsx.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Ruby2xlsx
|
2
|
-
autoload :Xrb,
|
3
|
-
autoload :Base,
|
4
|
-
autoload :Template,
|
5
|
-
autoload :Document,
|
6
|
-
autoload :Default,
|
2
|
+
autoload :Xrb, 'ruby2xlsx/xrb'
|
3
|
+
autoload :Base, 'ruby2xlsx/base'
|
4
|
+
autoload :Template, 'ruby2xlsx/template'
|
5
|
+
autoload :Document, 'ruby2xlsx/document'
|
6
|
+
autoload :Default, 'ruby2xlsx/default'
|
7
7
|
end
|
8
8
|
|
9
|
-
require
|
9
|
+
require 'ruby2xlsx/engine'
|
data/lib/ruby2xlsx/base.rb
CHANGED
@@ -11,28 +11,28 @@ module Ruby2xlsx
|
|
11
11
|
@compiled = false
|
12
12
|
@io = ::StringIO.new
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def workbook
|
16
16
|
@workbook ||= ::WriteExcel.new(@io)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def worksheet
|
20
20
|
@worksheet ||= add_worksheet(worksheet_name)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def add_worksheet(*args)
|
24
24
|
@worksheet = workbook.add_worksheet(*args)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def render(*args)
|
28
28
|
workbook.close
|
29
29
|
@io.string
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def worksheet_name
|
33
|
-
|
33
|
+
'somename'
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def method_missing(m, *args, &block)
|
37
37
|
if worksheet.respond_to?(m)
|
38
38
|
worksheet.send(m, *args, &block)
|
data/lib/ruby2xlsx/document.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module Ruby2xlsx
|
2
2
|
class Document < Base
|
3
3
|
def render
|
4
|
-
date_format = workbook.add_format(:
|
5
|
-
time_format = workbook.add_format(:
|
6
|
-
|
4
|
+
date_format = workbook.add_format(num_format: 'dd.mm.yyyy')
|
5
|
+
time_format = workbook.add_format(num_format: 'dd.mm.yyyy HH:MM')
|
6
|
+
|
7
7
|
each_with_index do |record, index|
|
8
8
|
row = index + 1
|
9
|
-
|
9
|
+
|
10
10
|
columns_names.each_with_index do |column, num|
|
11
11
|
value = record.send(column)
|
12
|
-
|
12
|
+
|
13
13
|
case value
|
14
|
-
when Date then
|
14
|
+
when Date then
|
15
15
|
worksheet.write_string(row, num, value.strftime("%Y-%m-%dT"), date_format)
|
16
|
-
when DateTime, Time then
|
16
|
+
when DateTime, Time then
|
17
17
|
worksheet.write_date_time(row, num, value.strftime("%Y-%m-%dT%H:%M:%S.%L"), time_format)
|
18
18
|
when String then
|
19
19
|
worksheet.write_string(row, num, value)
|
@@ -22,34 +22,34 @@ module Ruby2xlsx
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
|
-
bold = workbook.add_format(:
|
25
|
+
|
26
|
+
bold = workbook.add_format(bold: 1)
|
27
27
|
worksheet.write('A1', human_columns_names, bold)
|
28
|
-
|
28
|
+
|
29
29
|
super
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def columns_names
|
33
33
|
@columns_names ||= (@options[:columns] || @klass.column_names)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def human_columns_names
|
37
37
|
@human_columns_names ||= columns_names.map { |column| @klass.human_attribute_name(column.to_s) }
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def worksheet_name
|
41
41
|
@worksheet_name ||= (@options[:worksheet_name] || @klass.model_name.human)
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def filename
|
45
|
-
@filename ||= [(@options[:filename] || @klass.model_name.plural ||
|
45
|
+
@filename ||= [(@options[:filename] || @klass.model_name.plural || 'document'), '.xls'].join
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def each_with_index
|
49
49
|
count = 0
|
50
50
|
if defined?(ActiveRecord) && @source.is_a?(::ActiveRecord::Relation)
|
51
51
|
@klass ||= @source.klass
|
52
|
-
|
52
|
+
|
53
53
|
@source.find_each do |item|
|
54
54
|
yield item, count
|
55
55
|
count += 1
|
@@ -58,7 +58,7 @@ module Ruby2xlsx
|
|
58
58
|
items = Array.wrap(@source)
|
59
59
|
@klass ||= items.first.class unless items.empty?
|
60
60
|
@klass ||= Default
|
61
|
-
|
61
|
+
|
62
62
|
items.each do |item|
|
63
63
|
yield item, count
|
64
64
|
count += 1
|
data/lib/ruby2xlsx/engine.rb
CHANGED
@@ -3,14 +3,16 @@ require 'ruby2xlsx'
|
|
3
3
|
|
4
4
|
module Ruby2xlsx
|
5
5
|
class Engine < ::Rails::Engine
|
6
|
-
initializer
|
7
|
-
::Mime::Type.register
|
6
|
+
initializer 'ruby2xlsx.setup' do
|
7
|
+
::Mime::Type.register 'application/vnd.ms-excel', :xlsx
|
8
8
|
|
9
9
|
::ActionView::Template.register_template_handler :xrb, Ruby2xlsx::Xrb.new
|
10
10
|
|
11
11
|
::ActionController::Renderers.add :xlsx do |collection, options|
|
12
12
|
doc = Ruby2xlsx::Document.new(collection, options)
|
13
|
-
send_data(doc.render, :
|
13
|
+
send_data(doc.render, filename: doc.filename,
|
14
|
+
type: 'application/vnd.ms-excel',
|
15
|
+
disposition: 'attachment')
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
data/lib/ruby2xlsx/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2xlsx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Galeta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: writeexcel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 1.0.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
|
-
version: 0.
|
26
|
+
version: 1.0.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.1.3
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.1.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sqlite3
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,13 +66,17 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.1.2
|
69
|
-
description: Another gem for exporting data to Excel
|
69
|
+
description: Another gem for easy exporting data to Excel
|
70
70
|
email:
|
71
71
|
- galeta.igor@gmail.com
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- MIT-LICENSE
|
77
|
+
- README.rdoc
|
78
|
+
- Rakefile
|
79
|
+
- lib/ruby2xlsx.rb
|
76
80
|
- lib/ruby2xlsx/base.rb
|
77
81
|
- lib/ruby2xlsx/default.rb
|
78
82
|
- lib/ruby2xlsx/document.rb
|
@@ -80,11 +84,7 @@ files:
|
|
80
84
|
- lib/ruby2xlsx/template.rb
|
81
85
|
- lib/ruby2xlsx/version.rb
|
82
86
|
- lib/ruby2xlsx/xrb.rb
|
83
|
-
-
|
84
|
-
- lib/tasks/ruby2xlsx_tasks.rake
|
85
|
-
- MIT-LICENSE
|
86
|
-
- Rakefile
|
87
|
-
- README.rdoc
|
87
|
+
- test/dummy/Rakefile
|
88
88
|
- test/dummy/app/assets/javascripts/application.js
|
89
89
|
- test/dummy/app/assets/javascripts/articles.js
|
90
90
|
- test/dummy/app/assets/stylesheets/application.css
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- test/dummy/app/views/articles/new.html.erb
|
103
103
|
- test/dummy/app/views/articles/show.html.erb
|
104
104
|
- test/dummy/app/views/layouts/application.html.erb
|
105
|
+
- test/dummy/config.ru
|
105
106
|
- test/dummy/config/application.rb
|
106
107
|
- test/dummy/config/boot.rb
|
107
108
|
- test/dummy/config/database.yml
|
@@ -117,13 +118,11 @@ files:
|
|
117
118
|
- test/dummy/config/initializers/wrap_parameters.rb
|
118
119
|
- test/dummy/config/locales/en.yml
|
119
120
|
- test/dummy/config/routes.rb
|
120
|
-
- test/dummy/config.ru
|
121
121
|
- test/dummy/db/migrate/20120116125427_create_articles.rb
|
122
122
|
- test/dummy/public/404.html
|
123
123
|
- test/dummy/public/422.html
|
124
124
|
- test/dummy/public/500.html
|
125
125
|
- test/dummy/public/favicon.ico
|
126
|
-
- test/dummy/Rakefile
|
127
126
|
- test/dummy/script/rails
|
128
127
|
- test/integration/navigation_test.rb
|
129
128
|
- test/ruby2xlsx_test.rb
|
@@ -148,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
147
|
version: '0'
|
149
148
|
requirements: []
|
150
149
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.
|
150
|
+
rubygems_version: 2.6.12
|
152
151
|
signing_key:
|
153
152
|
specification_version: 4
|
154
153
|
summary: 'Export your data to Excel. Provide two ways for export data: template or
|