Class: DocXify::Container
- Inherits:
-
Object
- Object
- DocXify::Container
- Defined in:
- lib/docxify/container.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
Instance Method Summary collapse
- #document_xml_rels ⇒ Object
-
#initialize(document) ⇒ Container
constructor
A new instance of Container.
- #render ⇒ Object
Constructor Details
#initialize(document) ⇒ Container
Returns a new instance of Container.
7 8 9 |
# File 'lib/docxify/container.rb', line 7 def initialize(document) @document = document end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
5 6 7 |
# File 'lib/docxify/container.rb', line 5 def document @document end |
Instance Method Details
#document_xml_rels ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/docxify/container.rb', line 58 def document_xml_rels xml = <<~XML <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> <Relationship Id="rId3" Target="webSettings.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"/> <Relationship Id="rId2" Target="settings.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"/> <Relationship Id="rId1" Target="styles.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"/> <Relationship Id="rId5" Target="theme/theme1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"/> <Relationship Id="rId4" Target="fontTable.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"/> XML @document.relationships.each do |relation| xml << relation.to_s end xml << "</Relationships>" xml end |
#render ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/docxify/container.rb', line 11 def render temp_file = Tempfile.new("docxify.zip") Zip::OutputStream.open(temp_file) do |zip| zip.put_next_entry "_rels/.rels" zip.write DocXify::Template.top_level_rels zip.put_next_entry "[Content_Types].xml" zip.write DocXify::Template.content_types zip.put_next_entry "word/theme/theme1.xml" zip.write DocXify::Template.theme zip.put_next_entry "word/fontTable.xml" zip.write DocXify::Template.font_table zip.put_next_entry "word/settings.xml" zip.write DocXify::Template.settings zip.put_next_entry "word/styles.xml" zip.write DocXify::Template.styles zip.put_next_entry "word/webSettings.xml" zip.write DocXify::Template.web_settings zip.put_next_entry "word/document.xml" zip.write document.build_xml(self) zip.put_next_entry "word/_rels/document.xml.rels" zip.write document_xml_rels @document.relationships.each do |relation| if relation.is_a?(DocXify::Element::File) zip.put_next_entry "word/media/#{relation.filename}" zip.write relation.data end end end temp_file.flush temp_file.rewind temp_file.read ensure temp_file.close temp_file.unlink end |