Class: Serenity::Template
- Inherits:
-
Object
- Object
- Serenity::Template
- Defined in:
- lib/serenity/template.rb
Instance Attribute Summary collapse
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(template, output) ⇒ Template
constructor
A new instance of Template.
- #process(context) ⇒ Object
Constructor Details
#initialize(template, output) ⇒ Template
Returns a new instance of Template.
16 17 18 19 |
# File 'lib/serenity/template.rb', line 16 def initialize(template, output) FileUtils.cp(template, output) @template = output end |
Instance Attribute Details
#template ⇒ Object
Returns the value of attribute template.
14 15 16 |
# File 'lib/serenity/template.rb', line 14 def template @template end |
Instance Method Details
#process(context) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/serenity/template.rb', line 21 def process context tmpfiles = [] ZipFile.open(@template) do |zipfile| %w(content.xml styles.xml).each do |xml_file| content = zipfile.read(xml_file) # Images replacement images_replacements = ImagesProcessor.new(content, context).generate_replacements images_replacements.each do |r| zipfile.replace(r.first, r.last) end odteruby = OdtEruby.new(XmlReader.new(content)) out = odteruby.evaluate(context) out.force_encoding Encoding.default_external tmpfiles << (file = Tempfile.new("serenity")) file << out file.close zipfile.replace(xml_file, file.path) end end end |