Module: ODFReport::Images

Included in:
Report
Defined in:
lib/odf-report/images.rb

Instance Method Summary collapse

Instance Method Details

#find_image_name_matches(content) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/odf-report/images.rb', line 5

def find_image_name_matches(content)

  @images.each_pair do |image_name, path|
    if node = content.xpath("//draw:frame[@draw:name='#{image_name}']/draw:image").first
      placeholder_path = node.attribute('href').value
      @image_names_replacements[path] = File.basename(placeholder_path)
    end
  end

end

#replace_images(new_file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/odf-report/images.rb', line 16

def replace_images(new_file)

  unless @images.empty?
    image_dir_name = "Pictures"
    FileUtils.mkdir(File.join("#{@tmp_dir}", image_dir_name))
    @image_names_replacements.each_pair do |path, template_image|
      template_image_path = File.join(image_dir_name, template_image)
      update_file_from_zip(new_file, template_image_path) do |content|
        content.replace File.read(path)
      end
    end
  end

end