Class: Woa::Energon::OdDocument
- Includes:
- REXML
- Defined in:
- lib/energon/od_document.rb
Overview
This is a subclass of Document but it deals with OpenDocument (OpenOffice) templates instead of Text templates. It works with the writer and the spreadsheet files.
Everything is the same as Document (Except the input and the output). See Document for more details.
:include: rdoc-header
Constant Summary
Constants inherited from Document
Document::DefaultDelimiter, Document::DefaultNewLine
Instance Attribute Summary
Attributes inherited from Document
Instance Method Summary collapse
- #write ⇒ Object (also: #close)
Methods inherited from Document
#add_value, #add_values, #initialize, #valid?
Constructor Details
This class inherits a constructor from Woa::Energon::Document
Instance Method Details
#write ⇒ Object Also known as: close
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/energon/od_document.rb', line 17 def write() raise NoPlaceholderFound if @placeholders.empty? rows = {} @placeholders.each do |placeholder_hash| placeholder = placeholder_hash[:placeholder] data = Parser.merge(placeholder, @datas) if data.is_a?(Array) element = placeholder_hash[:element] parent = XPath.first(element, "ancestor::table:table-row") # if not in a table if parent.nil? element.text = element.text.to_s.sub("#{delimiter}#{placeholder}#{delimiter}", data.join) else rows[parent] ||= [] rows[parent] << {:element => element, :data => data, :placeholder => placeholder} end else element = placeholder_hash[:element] element.text = element.text.to_s.sub("#{delimiter}#{placeholder}#{delimiter}", data) end end originals = {} rows.each do |row, elements| continue = true while continue originals.each do |element, text| element.text = text originals.delete(element) end elements.each do |hash| element = hash[:element] data = hash[:data] placeholder = hash[:placeholder] if data.empty? continue = false break end originals[element] = element.text.to_s.clone txt = element.text = element.text.to_s.sub("#{delimiter}#{placeholder}#{delimiter}", data.pop) end row.parent.insert_after(row, row.deep_clone) if continue end row.parent.delete_element(row) end @odt.save(@content) @odt.write end |