lib/rubyXL/objects/relationships.rb in rubyXL-3.4.23 vs lib/rubyXL/objects/relationships.rb in rubyXL-3.4.24

- old
+ new

@@ -1,10 +1,9 @@ require 'pathname' require 'rubyXL/objects/ooxml_object' module RubyXL - class RID < OOXMLObject define_relationship(:required => true) end class Relationship < OOXMLObject @@ -14,11 +13,11 @@ define_attribute(:TargetMode, :string) define_element_name 'Relationship' end class OOXMLRelationshipsFile < OOXMLTopLevelObject - CONTENT_TYPE = 'application/vnd.openxmlformats-package.relationships+xml' + CONTENT_TYPE = 'application/vnd.openxmlformats-package.relationships+xml'.freeze SAVE_ORDER = 100 define_child_node(RubyXL::Relationship, :collection => true, :accessor => :relationships) define_element_name 'Relationships' set_namespaces('http://schemas.openxmlformats.org/package/2006/relationships' => nil) @@ -26,21 +25,21 @@ attr_accessor :related_files, :owner @@debug_indent = ($DEBUG ? 0 : nil) def new_relationship(target, type) - RubyXL::Relationship.new(:id => "rId#{relationships.size + 1}", - :type => type, + RubyXL::Relationship.new(:id => "rId#{relationships.size + 1}", + :type => type, :target => target) end protected :new_relationship def add_relationship(obj) return if obj.nil? || !defined?(obj.class::REL_TYPE) || (obj.respond_to?(:empty?) && obj.empty?) - relationships << RubyXL::Relationship.new(:id => "rId#{relationships.size + 1}", - :type => obj.class::REL_TYPE, + relationships << RubyXL::Relationship.new(:id => "rId#{relationships.size + 1}", + :type => obj.class::REL_TYPE, :target => obj.xlsx_path.relative_path_from(owner.xlsx_path.dirname)) end protected :add_relationship def find_by_rid(r_id) @@ -129,16 +128,14 @@ def self.rel_file_path(base_file_path) basename = base_file_path.root? ? '' : base_file_path.basename base_file_path.dirname.join('_rels', "#{basename}.rels").cleanpath end - end # +RelationshipSupport+ module enables automatic loading and saving of _rels for the respective file module RelationshipSupport - module ClassMehods def define_relationship(klass, accessor = nil) class_variable_get(:@@ooxml_relationships)[klass] = accessor attr_accessor(accessor) if accessor end @@ -210,9 +207,7 @@ if unknown && !RubyXL.class_variable_get(:@@suppress_warnings) then puts "WARNING: #{self.class} is not aware how to process #{related_file.class}" end self.generic_storage << related_file end - end - end