acts_as_caxlsx 1.0.8 → 1.0.10
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +10 -10
- data/Rakefile +5 -10
- data/lib/acts_as_xlsx/ar.rb +31 -17
- data/lib/acts_as_xlsx/version.rb +1 -1
- data/test/{tc_acts_as_xlsx.rb → tc_acts_as_xlsx_test.rb} +8 -1
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 929a9ff3b96cbc95728446948d62a6f254fea46612a919c66f21c7dbcf5b57a6
|
|
4
|
+
data.tar.gz: a89a4d43599dd1d1d74a76a1d902ed9b61b76e8dc07671304a84474dd41e9a3b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a2b1f3c42a937f4ae39e8771ae5a2c0cc8406f0e21eba4b12fd2f1dbc469e6df1d1c4600b8264d51f41097f4ad67381746f988fd6c019a19916f5a02e2c13f4c
|
|
7
|
+
data.tar.gz: 6a23a8a5fc3452e4a091f31aba50d60b93fdd5dc98baaa7e71990fe7c1b0ef81ac92774f0c7eac9e68d51f0bdfb6de0f4481217d1d39070374592fcdf6b4e851
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
# Acts as
|
|
1
|
+
# Acts as Caxlsx
|
|
2
2
|
|
|
3
|
-
[](https://github.com/caxlsx/acts_as_caxlsx/actions/workflows/test.yml)
|
|
4
|
+
[](https://badge.fury.io/rb/acts_as_caxlsx)
|
|
5
|
+

|
|
4
6
|
|
|
5
7
|
## Notice: Community Axlsx Organization
|
|
6
8
|
|
|
@@ -12,7 +14,7 @@ http://github.com/caxlsx
|
|
|
12
14
|
|
|
13
15
|
## Synopsis
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
Acts_as_caxlsx is an active record plugin for automatic Office Open XML Spreadsheet Generation using Caxlsx. It makes generating excel spreadsheets from any subclass of ActiveRecord::Base as simple as a couple of lines of code.
|
|
16
18
|
|
|
17
19
|
## Feature List
|
|
18
20
|
|
|
@@ -26,13 +28,11 @@ Acts_as_xlsx is an active record plugin for automatic Office Open XML Spreadshee
|
|
|
26
28
|
|
|
27
29
|
5. Lets you specify columns and methods chains you want to call to populate your table in one go.
|
|
28
30
|
|
|
29
|
-
6. Gives you access to the
|
|
30
|
-
|
|
31
|
-
7. Plays nicely with both ruby 1.8.7 + rails 2.3 as well as ruby 1.9.3 + rails 3
|
|
31
|
+
6. Gives you access to the Caxlsx package so you can add styles, charts and pictures to satisfy those flashy sales guys.
|
|
32
32
|
|
|
33
33
|
8. Automatically registers xlsx Mime type for use in respond_to web-service support.
|
|
34
34
|
|
|
35
|
-
9. Allows you to specify the
|
|
35
|
+
9. Allows you to specify the Caxlsx package to add your data to so you can create a single workbook with a sheet for each to_xlsx call.
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
## Install
|
|
@@ -40,7 +40,7 @@ Acts_as_xlsx is an active record plugin for automatic Office Open XML Spreadshee
|
|
|
40
40
|
To install, add the following to your Gemfile:
|
|
41
41
|
|
|
42
42
|
```ruby
|
|
43
|
-
gem '
|
|
43
|
+
gem 'acts_as_caxlsx'
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
|
|
@@ -56,7 +56,7 @@ The following Usage guides need to be extracted and added to this README
|
|
|
56
56
|
|
|
57
57
|
Detailed documentation is available at:
|
|
58
58
|
|
|
59
|
-
[https://www.rubydoc.info/gems/
|
|
59
|
+
[https://www.rubydoc.info/gems/acts_as_caxlsx/](https://www.rubydoc.info/gems/acts_as_caxlsx/)
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
## Credits
|
|
@@ -65,4 +65,4 @@ Originally created by Randy Morgan - @randym
|
|
|
65
65
|
|
|
66
66
|
Forked in 2019, to enable the community to maintain the Axlsx ecosystem - http://github.com/caxlsx
|
|
67
67
|
|
|
68
|
-
Open source software is a community effort. None of this could have been done without the help of [our Contributors](https://github.com/caxlsx/
|
|
68
|
+
Open source software is a community effort. None of this could have been done without the help of [our Contributors](https://github.com/caxlsx/acts_as_caxlsx/graphs/contributors).
|
data/Rakefile
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/lib/acts_as_xlsx/version.rb')
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
end
|
|
3
|
+
require 'bundler'
|
|
4
|
+
Bundler::GemHelper.install_tasks
|
|
6
5
|
|
|
7
|
-
task :gendoc do
|
|
6
|
+
task :gendoc do
|
|
8
7
|
system "yardoc"
|
|
9
8
|
end
|
|
10
9
|
|
|
11
|
-
task :test do
|
|
10
|
+
task :test do
|
|
12
11
|
require 'rake/testtask'
|
|
13
12
|
Rake::TestTask.new do |t|
|
|
14
13
|
t.libs << 'test'
|
|
@@ -17,8 +16,4 @@ task :test do
|
|
|
17
16
|
end
|
|
18
17
|
end
|
|
19
18
|
|
|
20
|
-
task :
|
|
21
|
-
system "gem push acts_as_xlsx-#{Axlsx::Ar::VERSION}.gem"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
task :default => :test
|
|
19
|
+
task :default => :test
|
data/lib/acts_as_xlsx/ar.rb
CHANGED
|
@@ -54,36 +54,50 @@ module Axlsx
|
|
|
54
54
|
header_style = options.delete(:header_style) || row_style
|
|
55
55
|
types = [options.delete(:types) || []].flatten
|
|
56
56
|
|
|
57
|
-
i18n = options.
|
|
58
|
-
|
|
57
|
+
i18n = if options.key?(:i18n)
|
|
58
|
+
options.delete(:i18n)
|
|
59
|
+
else
|
|
60
|
+
self.xlsx_i18n
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# columns => [["column_name", "header"], [...], ...]
|
|
64
|
+
columns = Array.wrap(options.delete(:columns) || self.xlsx_columns).flat_map { |col|
|
|
65
|
+
col.is_a?(Hash) ? col.to_a : [[col, nil]]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
headers = options.delete(:headers)
|
|
69
|
+
headers||= columns.map { |(col_name, col_header)|
|
|
70
|
+
if col_header
|
|
71
|
+
col_header
|
|
72
|
+
elsif i18n == true
|
|
73
|
+
self.human_attribute_name(col_name)
|
|
74
|
+
elsif i18n
|
|
75
|
+
I18n.t("#{i18n_key}.#{self.name.underscore}.#{col_name}", default: col_name.to_s.humanize)
|
|
76
|
+
else
|
|
77
|
+
col_name.to_s.humanize
|
|
78
|
+
end
|
|
79
|
+
}
|
|
59
80
|
|
|
60
81
|
p = options.delete(:package) || Package.new
|
|
61
82
|
row_style = p.workbook.styles.add_style(row_style) unless row_style.nil?
|
|
62
83
|
header_style = p.workbook.styles.add_style(header_style) unless header_style.nil?
|
|
63
|
-
|
|
64
|
-
sheet_name = options.delete(:name) || (i18n ? (
|
|
84
|
+
i18n_key = i18n == true ? 'activerecord.attributes' : i18n
|
|
85
|
+
sheet_name = options.delete(:name) || (i18n ? (i18n == true ? self.model_name.human : I18n.t("#{i18n_key}.#{table_name.underscore}", default: table_name.humanize)) : table_name.humanize)
|
|
65
86
|
data = options.delete(:data) || where(options[:where]).order(options[:order]).to_a
|
|
66
87
|
data = data.compact.flatten
|
|
67
88
|
|
|
68
89
|
|
|
69
90
|
return p if data.empty?
|
|
70
91
|
p.workbook.add_worksheet(:name=>sheet_name) do |sheet|
|
|
71
|
-
|
|
72
|
-
col_labels = if i18n
|
|
73
|
-
columns.map { |c| self.xlsx_i18n == true ? self.human_attribute_name(c) : I18n.t("#{i18n}.#{self.name.underscore}.#{c}") }
|
|
74
|
-
else
|
|
75
|
-
columns.map { |c| c.to_s.humanize }
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
sheet.add_row col_labels, :style=>header_style
|
|
92
|
+
sheet.add_row headers, :style=>header_style
|
|
79
93
|
|
|
80
94
|
data.each do |r|
|
|
81
|
-
row_data = columns.map do |
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
r.send(c)
|
|
95
|
+
row_data = columns.map do |(column_name, _column_header)|
|
|
96
|
+
v = r
|
|
97
|
+
column_name.to_s.split('.').each do |method|
|
|
98
|
+
!v.nil? ? v = v.send(method) : v = nil
|
|
86
99
|
end
|
|
100
|
+
v
|
|
87
101
|
end
|
|
88
102
|
sheet.add_row row_data, :style=>row_style, :types=>types
|
|
89
103
|
end
|
data/lib/acts_as_xlsx/version.rb
CHANGED
|
@@ -70,7 +70,14 @@ class TestToXlsx < Test::Unit::TestCase
|
|
|
70
70
|
assert_equal(Post.last.comments.last.author.name, sheet.rows.last.cells.last.value)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
def test_complex_columns
|
|
74
|
+
p = Post.to_xlsx columns: [{name: "CUSTOM NAME HEADER", votes: "CUSTOM VOTES HEADER"}, :content, ranking: "CUSTOM RANKING HEADER"]
|
|
75
|
+
sheet = p.workbook.worksheets.first
|
|
76
|
+
assert_equal("CUSTOM NAME HEADER", sheet.rows.first.cells[0].value)
|
|
77
|
+
assert_equal("CUSTOM VOTES HEADER", sheet.rows.first.cells[1].value)
|
|
78
|
+
assert_equal("Content", sheet.rows.first.cells[2].value)
|
|
79
|
+
assert_equal("CUSTOM RANKING HEADER", sheet.rows.first.cells[3].value)
|
|
80
|
+
end
|
|
74
81
|
|
|
75
82
|
end
|
|
76
83
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: acts_as_caxlsx
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Randy Morgan
|
|
8
8
|
- Noel Peden
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-04-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: caxlsx
|
|
@@ -71,7 +71,7 @@ files:
|
|
|
71
71
|
- lib/acts_as_xlsx/version.rb
|
|
72
72
|
- test/database.yml
|
|
73
73
|
- test/helper.rb
|
|
74
|
-
- test/
|
|
74
|
+
- test/tc_acts_as_xlsx_test.rb
|
|
75
75
|
homepage: https://github.com/caxlsx/acts_as_caxlsx
|
|
76
76
|
licenses: []
|
|
77
77
|
metadata: {}
|
|
@@ -82,17 +82,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
82
82
|
requirements:
|
|
83
83
|
- - ">="
|
|
84
84
|
- !ruby/object:Gem::Version
|
|
85
|
-
version: '2.
|
|
85
|
+
version: '2.6'
|
|
86
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
requirements:
|
|
88
88
|
- - ">="
|
|
89
89
|
- !ruby/object:Gem::Version
|
|
90
90
|
version: '0'
|
|
91
91
|
requirements: []
|
|
92
|
-
rubygems_version:
|
|
92
|
+
rubygems_version: 4.0.6
|
|
93
93
|
specification_version: 4
|
|
94
94
|
summary: ActiveRecord support for Axlsx
|
|
95
95
|
test_files:
|
|
96
96
|
- test/database.yml
|
|
97
97
|
- test/helper.rb
|
|
98
|
-
- test/
|
|
98
|
+
- test/tc_acts_as_xlsx_test.rb
|