class Docxer::Relationships

Attributes

relationships[RW]

Public Class Methods

new() click to toggle source
# File lib/docxer/relationships.rb, line 9
def initialize
  @relationships = []
  @counter = 0
  add("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "word/document.xml")
  add("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml")
  add("http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml")
end

Public Instance Methods

add(type, target) click to toggle source
# File lib/docxer/relationships.rb, line 17
def add(type, target)
  relationship = create_relationship(sequence, type, target)
  @relationships << relationship if relationship
  relationship
end
render(zip) click to toggle source
# File lib/docxer/relationships.rb, line 23
def render(zip)
  zip.put_next_entry('_rels/.rels')
  zip.write(Docxer.to_xml(document))
end

Private Instance Methods

create_relationship(id, type, target) click to toggle source
# File lib/docxer/relationships.rb, line 39
def create_relationship(id, type, target)
  Relationship.new(id, type, target)
end
document() click to toggle source
# File lib/docxer/relationships.rb, line 29
def document
  Nokogiri::XML::Builder.with(Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>')) do |xml|
    xml.Relationships(xmlns: 'http://schemas.openxmlformats.org/package/2006/relationships') do
      @relationships.each do |relationship|
        relationship.build(xml)
      end
    end
  end
end
sequence() click to toggle source
# File lib/docxer/relationships.rb, line 43
def sequence
  @counter += 1
  @@prefix + @counter.to_s
end