Sha256: 33d2012ee934b37a12fa097d83dc57f6b30458d407963044ce8229f3f7a7c7a9

Contents?: true

Size: 923 Bytes

Versions: 2

Compression:

Stored size: 923 Bytes

Contents

require 'set'
require 'active_support/core_ext/hash/deep_merge'

module AxlsxStyler
  module Workbook
    # An array that holds all cells with styles
    attr_accessor :styled_cells

    # Checks if styles are indexed to make it work for pre 0.1.5 version
    # users that still explicitly call @workbook.apply_styles
    attr_accessor :styles_applied

    def add_styled_cell(cell)
      self.styled_cells ||= Set.new
      self.styled_cells << cell
    end

    def apply_styles
      return unless styled_cells

      styled_cells.each do |cell|
        current_style = styles.style_index[cell.style]

        if current_style
          new_style = current_style.deep_merge(cell.raw_style)
        else
          new_style = cell.raw_style
        end

        cell.style = styles.add_style(new_style)
      end

      self.styles_applied = true
    end

  end
end

Axlsx::Workbook.send(:include, AxlsxStyler::Workbook)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
axlsx_styler-1.2.0 lib/axlsx_styler/axlsx_workbook.rb
axlsx_styler-1.1.0 lib/axlsx_styler/axlsx_workbook.rb