diff options
| author | Weston Ganger <[email protected]> | 2022-10-09 14:40:24 -0700 |
|---|---|---|
| committer | Weston Ganger <[email protected]> | 2022-10-09 14:40:24 -0700 |
| commit | 03bad903f474fecccc7dacdc14ef17605d9e2aa2 (patch) | |
| tree | e0a88df15105a6c2d5dfda5c9178a428b280e6bf | |
| parent | 99b25655ef0e5c953007ff81b5bc08058831da8c (diff) | |
| download | caxlsx-03bad903f474fecccc7dacdc14ef17605d9e2aa2.tar.gz caxlsx-03bad903f474fecccc7dacdc14ef17605d9e2aa2.zip | |
Improvements
| -rw-r--r-- | lib/axlsx.rb | 11 | ||||
| -rw-r--r-- | lib/axlsx/workbook/workbook.rb | 17 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 2 | ||||
| -rw-r--r-- | lib/caxlsx.rb | 10 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_border_creator.rb | 40 |
5 files changed, 54 insertions, 26 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb index c30fcf26..e02256e6 100644 --- a/lib/axlsx.rb +++ b/lib/axlsx.rb @@ -28,8 +28,19 @@ require 'zip' #core dependencies require 'bigdecimal' +require 'set' require 'time' +begin + require "axlsx_styler" + + if defined?(AxlsxStyler) + raise StandardError.new("Please remove `axlsx_styler` from your Gemfile, the associated functionality is now built-in to `caxlsx` directly.") + end +rescue LoadError + # Do nothing, all good +end + # xlsx generation with charts, images, automated column width, customizable styles # and full schema validation. Axlsx excels at helping you generate beautiful # Office Open XML Spreadsheet documents without having to understand the entire diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index 417e15a3..ef56debd 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -188,7 +188,9 @@ require 'axlsx/workbook/worksheet/selection.rb' end # An array that holds all cells with styles - attr_accessor :styled_cells + def styled_cells + @styled_cells ||= Set.new + end # Checks if styles are indexed to make it work for pre 0.1.5 version # users that still explicitly call @workbook.apply_styles @@ -418,18 +420,5 @@ require 'axlsx/workbook/worksheet/selection.rb' str << '</workbook>' end - private - - # Utility method for performing a deep merge on a Hash - def hash_deep_merge(first_hash, second_hash) - first_hash.merge(second_hash) do |key, this_val, other_val| - if this_val.is_a?(Hash) && other_val.is_a?(Hash) - this_val.deep_merge(other_val, &block) - else - other_val - end - end - end - end end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 9ab93e61..125ca051 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -87,7 +87,6 @@ module Axlsx # The index of the cellXfs item to be applied to this cell. # @param [Hash] styles # @see Axlsx::Styles - require 'set' ### TODO: move to appropriate place def add_style(style) self.raw_style ||= {} @@ -106,7 +105,6 @@ module Axlsx wb = row.worksheet.workbook - wb.styled_cells ||= Set.new wb.styled_cells << self end diff --git a/lib/caxlsx.rb b/lib/caxlsx.rb index 1dcc6005..a82d49fb 100644 --- a/lib/caxlsx.rb +++ b/lib/caxlsx.rb @@ -1,12 +1,2 @@ # encoding: UTF-8 require 'axlsx.rb' - -begin - require "axlsx_styler" - - if defined?(AxlsxStyler) - raise StandardError.new("Please remove `axlsx_styler` from your Gemfile, the associated functionality is now built-in to `caxlsx` directly.") - end -rescue LoadError - # Do nothing, all good -end diff --git a/test/workbook/worksheet/tc_border_creator.rb b/test/workbook/worksheet/tc_border_creator.rb new file mode 100644 index 00000000..95a85b18 --- /dev/null +++ b/test/workbook/worksheet/tc_border_creator.rb @@ -0,0 +1,40 @@ +require 'tc_helper.rb' + +class TestBorderCreator < Test::Unit::TestCase + def setup + @p = Axlsx::Package.new + @wb = @p.workbook + @ws = @wb.add_worksheet + end + + def test_defaults + 3.times do + @ws.add_row [1,2,3] + end + + bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], {}) + assert_equal bc.instance_variable_get(:@edges), :all + assert_equal bc.instance_variable_get(:@width), :thin + assert_equal bc.instance_variable_get(:@color), "000000" + + bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], [:top]) + assert_equal bc.instance_variable_get(:@edges), [:top] + assert_equal bc.instance_variable_get(:@width), :thin + assert_equal bc.instance_variable_get(:@color), "000000" + + bc = Axlsx::BorderCreator.new(@ws, @ws["A1:B2"], {edges: [:top], style: :thick, color: "ffffff"}) + assert_equal bc.instance_variable_get(:@edges), [:top] + assert_equal bc.instance_variable_get(:@width), :thick + assert_equal bc.instance_variable_get(:@color), "ffffff" + end + + def test_draw + 5.times do + @ws.add_row [1,2,3,4,5] + end + + bc = Axlsx::BorderCreator.new(@ws, @ws["A1:C3"], {}) + bc.draw + # TODO add more expectations + end +end |
