From 88c26606594a2024e17adff9dd9853812dc839cc Mon Sep 17 00:00:00 2001 From: Paul Kmiec Date: Sun, 7 May 2023 16:09:03 -0700 Subject: Do not change the whitespace that is produced by to_xml_string's --- .rubocop_todo.yml | 1 - lib/axlsx/content_type/abstract_content_type.rb | 7 +++++-- lib/axlsx/rels/relationship.rb | 5 ++++- lib/axlsx/workbook/worksheet/conditional_formatting.rb | 5 ++++- lib/axlsx/workbook/worksheet/data_validation.rb | 6 ++++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ad151878..8f8f4bd7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -441,7 +441,6 @@ Style/ParenthesesAroundCondition: - 'lib/axlsx/stylesheet/font.rb' - 'lib/axlsx/util/validators.rb' - 'lib/axlsx/workbook/worksheet/cell.rb' - - 'lib/axlsx/workbook/worksheet/data_validation.rb' - 'lib/axlsx/workbook/worksheet/rich_text_run.rb' # This cop supports safe autocorrection (--autocorrect). diff --git a/lib/axlsx/content_type/abstract_content_type.rb b/lib/axlsx/content_type/abstract_content_type.rb index bca08b7e..6aae8c4b 100644 --- a/lib/axlsx/content_type/abstract_content_type.rb +++ b/lib/axlsx/content_type/abstract_content_type.rb @@ -23,8 +23,11 @@ module Axlsx # Serialize the contenty type to xml def to_xml_string(node_name = '', str = +'') - str << "<#{node_name} " - Axlsx.instance_values_for(self).each { |key, value| str << Axlsx::camel(key) << '="' << value.to_s << '" ' } + str << '<' << node_name << ' ' + Axlsx.instance_values_for(self).each_with_index do |key_value, index| + str << ' ' unless index.zero? + str << Axlsx::camel(key_value.first) << '="' << key_value.last.to_s << '"' + end str << '/>' end end diff --git a/lib/axlsx/rels/relationship.rb b/lib/axlsx/rels/relationship.rb index e379fa41..14d15457 100644 --- a/lib/axlsx/rels/relationship.rb +++ b/lib/axlsx/rels/relationship.rb @@ -105,7 +105,10 @@ module Axlsx def to_xml_string(str = +'') h = Axlsx.instance_values_for(self).reject { |k, _| k == "source_obj" } str << '' end diff --git a/lib/axlsx/workbook/worksheet/conditional_formatting.rb b/lib/axlsx/workbook/worksheet/conditional_formatting.rb index 7c05c77e..5f8f2474 100644 --- a/lib/axlsx/workbook/worksheet/conditional_formatting.rb +++ b/lib/axlsx/workbook/worksheet/conditional_formatting.rb @@ -76,7 +76,10 @@ module Axlsx # @return [String] def to_xml_string(str = +'') str << '' - rules.each { |rule| rule.to_xml_string(str) } + rules.each_with_index do |rule, index| + str << ' ' unless index.zero? + rule.to_xml_string(str) + end str << '' end end diff --git a/lib/axlsx/workbook/worksheet/data_validation.rb b/lib/axlsx/workbook/worksheet/data_validation.rb index d5fa5908..eca90743 100644 --- a/lib/axlsx/workbook/worksheet/data_validation.rb +++ b/lib/axlsx/workbook/worksheet/data_validation.rb @@ -235,10 +235,12 @@ module Axlsx # @return [String] def to_xml_string(str = +'') valid_attributes = get_valid_attributes + h = Axlsx.instance_values_for(self).select { |key, _| valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym) } str << '' str << '' << self.formula1 << '' if @formula1 and valid_attributes.include?(:formula1) -- cgit v1.2.3