diff options
| author | Weston Ganger <[email protected]> | 2022-10-12 23:02:49 -0700 |
|---|---|---|
| committer | Weston Ganger <[email protected]> | 2022-10-12 23:10:08 -0700 |
| commit | 28d59a1dba55a9d98ceed26ac3bed6267cf18481 (patch) | |
| tree | 5b05b8926dd301f7bf0e714df848a5a209653348 /lib | |
| parent | 56f0977033d87c29fbcb5a20f0bd61d8fe3fb1ec (diff) | |
| download | caxlsx-28d59a1dba55a9d98ceed26ac3bed6267cf18481.tar.gz caxlsx-28d59a1dba55a9d98ceed26ac3bed6267cf18481.zip | |
Resolve all TODOs
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/stylesheet/styles.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/workbook/workbook.rb | 5 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/border_creator.rb | 50 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 6 |
4 files changed, 32 insertions, 33 deletions
diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index a84e6df7..1ddbb788 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -231,6 +231,10 @@ module Axlsx raise ArgumentError, "Type must be one of [:xf, :dxf]" unless [:xf, :dxf].include?(options[:type] ) + if options[:border].is_a?(Hash) && options[:border][:edges] == :all + options[:border][:edges] = Axlsx::Border::EDGES + end + if options[:type] == :xf # Check to see if style in cache already diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index ef56debd..938d4aee 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -188,12 +188,13 @@ require 'axlsx/workbook/worksheet/selection.rb' end # An array that holds all cells with styles + # @return Set 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 + # Are the styles added with workbook.add_styles applied yet + # @return Boolean attr_accessor :styles_applied # A helper to apply styles that were added using `worksheet.add_style` diff --git a/lib/axlsx/workbook/worksheet/border_creator.rb b/lib/axlsx/workbook/worksheet/border_creator.rb index a38e78b3..a4146ee1 100644 --- a/lib/axlsx/workbook/worksheet/border_creator.rb +++ b/lib/axlsx/workbook/worksheet/border_creator.rb @@ -8,49 +8,43 @@ module Axlsx @worksheet = worksheet @cells = cells if args.is_a?(Hash) - @edges = args[:edges] || :all + @edges = args[:edges] || Axlsx::Border::EDGES @width = args[:style] || :thin @color = args[:color] || '000000' else - @edges = args || :all + @edges = args || Axlsx::Border::Edges @width = :thin @color = '000000' end - end - - def draw - selected_edges(edges).each { |edge| add_border(edge, width, color) } - end - - private - def selected_edges(edges) - all_edges = [:top, :right, :bottom, :left] - if edges == :all - all_edges - elsif edges.is_a?(Array) && edges - all_edges == [] - edges.uniq + if @edges == :all + @edges = Axlsx::Border::EDGES + elsif @edges.is_a?(Array) + @edges = (@edges.map(&:to_sym).uniq & Axlsx::Border::EDGES) else - [] + @edges = [] end end - def add_border(position, width, color) - style = { - border: { - style: width, color: color, edges: [position.to_sym] - } - } - worksheet.add_style border_cells[position.to_sym], style + def draw + @edges.each do |edge| + worksheet.add_style( + border_cells[edge], + { + border: {style: @width, color: @color, edges: [edge]} + } + ) + end end + private + def border_cells - # example range "B2:D5" { - top: "#{first_cell}:#{last_col}#{first_row}", # "B2:D2" - right: "#{last_col}#{first_row}:#{last_cell}", # "D2:D5" - bottom: "#{first_col}#{last_row}:#{last_cell}", # "B5:D5" - left: "#{first_cell}:#{first_col}#{last_row}" # "B2:B5" + top: "#{first_cell}:#{last_col}#{first_row}", + right: "#{last_col}#{first_row}:#{last_cell}", + bottom: "#{first_col}#{last_row}:#{last_cell}", + left: "#{first_cell}:#{first_col}#{last_row}", } end diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 527d2e71..a240e8e9 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -565,7 +565,7 @@ module Axlsx # Set the style for cells in a specific column # @param [String|Array] cell references - # @param styles TODO: how to specify this + # @param [Hash] styles def add_style(cell_refs, *styles) if !cell_refs.is_a?(Array) cell_refs = [cell_refs] @@ -586,8 +586,8 @@ module Axlsx # Set the style for cells in a specific column # @param [String|Array] cell references - # @param [Hash|Symbol] options TODO: describe this - def add_border(cell_refs, options = :all) ### TODO: will we support the :all argument + # @param [Hash|Array|Symbol] border options + def add_border(cell_refs, options = Axlsx::Border::EDGES) if !cell_refs.is_a?(Array) cell_refs = [cell_refs] end |
