axlsx_styler 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/axlsx_styler.gemspec +14 -14
- data/lib/axlsx_styler/array.rb +6 -1
- data/lib/axlsx_styler/axlsx_cell.rb +1 -1
- data/lib/axlsx_styler/axlsx_workbook.rb +9 -12
- data/lib/axlsx_styler/version.rb +1 -1
- data/test/integration_test.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83dfa2cca4c51645feaa8b0dbf6693af425e42d9
|
4
|
+
data.tar.gz: 770fb362a94bc3ce157dbd4df1d61ff657910882
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: feba1d502575df2c5742ec0f3aeaf99c12cd9e571e5aab9fb3b58d917ffeea0c866c01b9edfb381b1b3f3b0b41b143fb6d024536c6791348b49d58d747a94ddd
|
7
|
+
data.tar.gz: 11fbe7c050e4091a084062567478ed84c58cee2a1f6e4a3f055002ad0e8974cdcbc2763b323ad81e1c34442b80c7b290cdbacaef9a42814c19f155ec251437bf
|
data/axlsx_styler.gemspec
CHANGED
@@ -4,33 +4,33 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'axlsx_styler/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'axlsx_styler'
|
8
8
|
spec.version = AxlsxStyler::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary = %q
|
12
|
-
spec.description = %q
|
9
|
+
spec.authors = ['Anton Sakovich']
|
10
|
+
spec.email = ['sakovias@gmail.com']
|
11
|
+
spec.summary = %q(This gem allows to separate data from styles when using Axlsx gem.)
|
12
|
+
spec.description = %q(
|
13
13
|
Axlsx gem is an excellent tool to build Excel worksheets. The sheets are
|
14
14
|
created row-by-row and styles are immediately added to each cell when a
|
15
15
|
row is created. This gem allows to follow an alternative route: fill out
|
16
16
|
a spreadsheet with data and apply styles later. Styles can be added
|
17
17
|
to individual cells as well as to ranges of cells. As a bonus, this gem
|
18
18
|
also simplifies drawing borders around groups of cells.
|
19
|
-
|
20
|
-
spec.homepage =
|
21
|
-
spec.license =
|
19
|
+
)
|
20
|
+
spec.homepage = 'https://github.com/sakovias/axlsx_styler'
|
21
|
+
spec.license = 'MIT'
|
22
22
|
|
23
23
|
spec.files = `git ls-files -z`.split("\x0")
|
24
24
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
25
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
26
|
-
spec.require_paths = [
|
26
|
+
spec.require_paths = ['lib']
|
27
27
|
spec.required_ruby_version = '>= 1.9.3'
|
28
28
|
|
29
|
-
spec.add_dependency
|
30
|
-
spec.add_dependency
|
29
|
+
spec.add_dependency 'axlsx', '~> 2.0'
|
30
|
+
spec.add_dependency 'activesupport', '~> 3.1'
|
31
31
|
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
33
|
+
spec.add_development_dependency 'rake', '~> 0.9'
|
34
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
35
35
|
spec.add_development_dependency 'awesome_print', '~> 1.6'
|
36
36
|
end
|
data/lib/axlsx_styler/array.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
module AxlsxStyler
|
2
|
+
# @TODO
|
3
|
+
# Move the functionality from Array to Worksheet. New DSL
|
4
|
+
# sheet.add_style 'A1:B5', b: true
|
5
|
+
# instead of
|
6
|
+
# sheet['A1:B5'].add_style, b: true
|
2
7
|
module Array
|
3
8
|
def add_style(style)
|
4
9
|
validate_cells
|
@@ -13,7 +18,7 @@ module AxlsxStyler
|
|
13
18
|
# hardcode style to :thin for now
|
14
19
|
def add_border(edges = :all)
|
15
20
|
validate_cells
|
16
|
-
selected_edges(edges).each{ |edge| add_border_at(edge) }
|
21
|
+
selected_edges(edges).each { |edge| add_border_at(edge) }
|
17
22
|
end
|
18
23
|
|
19
24
|
private
|
@@ -23,7 +23,7 @@ module AxlsxStyler
|
|
23
23
|
new_style = raw_style.deep_merge style
|
24
24
|
if with_border?(raw_style) && with_border?(style)
|
25
25
|
border_at = raw_style[:border][:edges] + style[:border][:edges]
|
26
|
-
new_style[:border][:edges] = border_at
|
26
|
+
new_style[:border][:edges] = border_at.uniq
|
27
27
|
elsif with_border?(style)
|
28
28
|
new_style[:border] = style[:border]
|
29
29
|
end
|
@@ -6,10 +6,10 @@ module AxlsxStyler
|
|
6
6
|
|
7
7
|
# An index for cell styles
|
8
8
|
# {
|
9
|
-
# < style_hash
|
10
|
-
# < style_hash
|
9
|
+
# 1 => < style_hash >,
|
10
|
+
# 2 => < style_hash >,
|
11
11
|
# ...
|
12
|
-
# < style_hash >
|
12
|
+
# K => < style_hash >
|
13
13
|
# }
|
14
14
|
# where keys are Cell#raw_style and values are styles
|
15
15
|
# codes as per Axlsx::Style
|
@@ -34,18 +34,15 @@ module AxlsxStyler
|
|
34
34
|
# @TODO fix this hack
|
35
35
|
self.style_index ||= {}
|
36
36
|
|
37
|
-
|
38
|
-
if
|
39
|
-
cell.style =
|
37
|
+
index_item = style_index.select { |_, v| v == cell.raw_style }.first
|
38
|
+
if index_item
|
39
|
+
cell.style = index_item.first
|
40
40
|
else
|
41
|
+
old_style = cell.raw_style.dup
|
41
42
|
new_style = styles.add_style(cell.raw_style)
|
42
43
|
cell.style = new_style
|
43
|
-
|
44
|
-
|
45
|
-
# the same; not sure if it's intended functionality
|
46
|
-
cell.raw_style.delete(:num_fmt)
|
47
|
-
|
48
|
-
style_index[cell.raw_style] = new_style
|
44
|
+
# cell.raw_style.delete(:num_fmt)
|
45
|
+
style_index[new_style] = old_style
|
49
46
|
end
|
50
47
|
end
|
51
48
|
end
|
data/lib/axlsx_styler/version.rb
CHANGED
data/test/integration_test.rb
CHANGED
@@ -29,6 +29,7 @@ class IntegrationTest < MiniTest::Test
|
|
29
29
|
__FILE__
|
30
30
|
)
|
31
31
|
assert_equal 12, workbook.style_index.count
|
32
|
+
assert_equal 12 + 2, workbook.style_index.keys.max
|
32
33
|
end
|
33
34
|
|
34
35
|
def test_table_with_num_fmt
|
@@ -52,4 +53,26 @@ class IntegrationTest < MiniTest::Test
|
|
52
53
|
__FILE__
|
53
54
|
)
|
54
55
|
end
|
56
|
+
|
57
|
+
def test_duplicate_styles
|
58
|
+
axlsx = Axlsx::Package.new
|
59
|
+
workbook = axlsx.workbook
|
60
|
+
workbook.add_worksheet do |sheet|
|
61
|
+
sheet.add_row %w(Index City)
|
62
|
+
sheet.add_row [1, 'Ottawa']
|
63
|
+
sheet.add_row [2, 'Boston']
|
64
|
+
|
65
|
+
sheet['A1:B1'].add_border [:bottom]
|
66
|
+
sheet['A1:B1'].add_border [:bottom]
|
67
|
+
sheet['A1:A3'].add_style b: true
|
68
|
+
sheet['A1:A3'].add_style b: true
|
69
|
+
end
|
70
|
+
workbook.apply_styles
|
71
|
+
assert_equal 4, workbook.styled_cells.count
|
72
|
+
assert_equal 3, workbook.style_index.count
|
73
|
+
axlsx.serialize File.expand_path(
|
74
|
+
'../../tmp/duplicate_styles.xlsx',
|
75
|
+
__FILE__
|
76
|
+
)
|
77
|
+
end
|
55
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: axlsx_styler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Sakovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: axlsx
|