class ODFWriter::Section
Section: poulate and grow sections
Attributes
collection[RW]
name[RW]
proc[RW]
Public Class Methods
new(options)
click to toggle source
initialize
# File lib/odf_writer/section.rb, line 39 def initialize(options) @name = options[:name] @field = options[:field] @key = @field || @name @collection = options[:collection] @proc = options[:proc] @fields = [] @bookmarks = [] @images = [] @texts = [] @tables = [] @sections = [] end
Public Instance Methods
get_section_content( doc )
click to toggle source
# File lib/odf_writer/section.rb, line 59 def get_section_content( doc ) return unless @section_node = find_section_node(doc) @section_node.content end
replace!(doc, manifest, file, row = nil)
click to toggle source
replace!
# File lib/odf_writer/section.rb, line 69 def replace!(doc, manifest, file, row = nil) return unless @section_node = find_section_node(doc) @collection = items(row, @key, @proc) if row @collection.each do |item| new_section = get_section_node # # experimental: new node must be added to doc prior to replace! # else new_section does not have a name space # @section_node.before(new_section) @tables.each { |t| t.replace!(new_section, manifest, file, item) } @sections.each { |s| s.replace!(new_section, manifest, file, item) } @texts.each { |t| t.replace!(new_section, item) } @fields.each { |f| f.replace!(new_section, item) } @bookmarks.each { |b| b.replace!(new_section, item) } @images.each { |b| b.replace!(new_section, manifest, file, item) } end Image.unique_image_names( doc) if @images.present? @section_node.remove end
Private Instance Methods
find_section_node(doc)
click to toggle source
private
# File lib/odf_writer/section.rb, line 106 def find_section_node(doc) sections = doc.xpath(".//text:section[@text:name='#{@name}']") sections.empty? ? nil : sections.first end
get_section_node()
click to toggle source
# File lib/odf_writer/section.rb, line 111 def get_section_node node = @section_node.dup name = node.get_attribute('text:name').to_s @idx ||=0; @idx +=1 node.set_attribute('text:name', "#{name}_#{@idx}") node end