Class: Doct::Formats::Odt

Inherits:
OpenFormat show all
Defined in:
lib/doct/formats/odt.rb

Instance Method Summary collapse

Methods inherited from OpenFormat

#content_entry?, #placeholders, #render

Methods inherited from Base

#initialize, #placeholders, #render

Constructor Details

This class inherits a constructor from Doct::Formats::Base

Instance Method Details

#content_entriesObject



5
6
7
# File 'lib/doct/formats/odt.rb', line 5

def content_entries
  %w(content.xml styles.xml)
end

#entry_placeholders(entry, content) ⇒ Object



36
37
38
39
# File 'lib/doct/formats/odt.rb', line 36

def entry_placeholders(entry, content)
  xml = Nokogiri::XML(content)
  xml.xpath("//text:database-display").collect { |node| node.attributes["column-name"].to_s }
end

#entry_render(entry, content, params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/doct/formats/odt.rb', line 9

def entry_render(entry, content, params)
  xml = Nokogiri::XML(content)
  orig_xml = xml.dup
  current_xml = xml
  text_node = xml.xpath("//office:text").first
  if entry == 'content.xml'
    for page in params
      nodes = current_xml.xpath("//office:text/*")
      nodes.xpath("//text:database-display").each do |node|
        param_name = node.attributes["column-name"].to_s
        node.replace page[param_name.to_sym].to_s
      end
      text_node.add_child(nodes)
      if page != params.last
        text_node.add_child("<text:soft-page-break>")
      end
      current_xml = orig_xml.dup
    end
  elsif not params.empty?
    xml.xpath("//text:database-display").each do |node|
      param_name = node.attributes["column-name"].to_s
      node.replace params.first[param_name.to_sym].to_s
    end
  end
  xml.to_s
end