Class: Serenity::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/serenity/serenity/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, output) ⇒ Template

Returns a new instance of Template.



8
9
10
11
# File 'lib/serenity/serenity/template.rb', line 8

def initialize(template, output)
  FileUtils.cp(template, output)
  @template = output
end

Instance Attribute Details

#templateObject

Returns the value of attribute template.



6
7
8
# File 'lib/serenity/serenity/template.rb', line 6

def template
  @template
end

Instance Method Details

#process(context) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/serenity/serenity/template.rb', line 13

def process context
  tmpfiles = []
  Zip::ZipFile.open(@template) do |zipfile|
    %w(content.xml styles.xml).each do |xml_file|
      content = zipfile.read(xml_file)
      odteruby = OdtEruby.new(XmlReader.new(content))
      out = odteruby.evaluate(context)
      out.force_encoding Encoding.default_external.to_s

      tmpfiles << (file = Tempfile.new("serenity"))
      file << out
      file.close

      zipfile.replace(xml_file, file.path)
    end
  end
end