Class: ODFReport::Template
- Inherits:
-
Object
- Object
- ODFReport::Template
- Defined in:
- lib/odf-report/template.rb
Constant Summary collapse
- CONTENT_FILES =
['content.xml', 'styles.xml']
- MANIFEST_FILE =
"META-INF/manifest.xml"
Instance Attribute Summary collapse
-
#output_stream ⇒ Object
Returns the value of attribute output_stream.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(template = nil, io: nil) ⇒ Template
constructor
A new instance of Template.
- #update_content ⇒ Object
- #update_file(name, data) ⇒ Object
- #update_files(&block) ⇒ Object
- #update_manifest(&block) ⇒ Object
Constructor Details
#initialize(template = nil, io: nil) ⇒ Template
Returns a new instance of Template.
9 10 11 12 13 14 15 |
# File 'lib/odf-report/template.rb', line 9 def initialize(template = nil, io: nil) raise "You must provide either a filename or an io: string" unless template || io raise "Template [#{template}] not found." unless template.nil? || ::File.exist?(template) @template = template @io = io end |
Instance Attribute Details
#output_stream ⇒ Object
Returns the value of attribute output_stream.
7 8 9 |
# File 'lib/odf-report/template.rb', line 7 def output_stream @output_stream end |
Instance Method Details
#data ⇒ Object
60 61 62 |
# File 'lib/odf-report/template.rb', line 60 def data @buffer.string end |
#update_content ⇒ Object
17 18 19 20 21 22 |
# File 'lib/odf-report/template.rb', line 17 def update_content @buffer = Zip::OutputStream.write_buffer do |out| @output_stream = out yield self end end |
#update_file(name, data) ⇒ Object
64 65 66 67 |
# File 'lib/odf-report/template.rb', line 64 def update_file(name, data) @output_stream.put_next_entry(name) @output_stream.write data end |
#update_files(&block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/odf-report/template.rb', line 24 def update_files(&block) get_template_entries.each do |entry| next if entry.directory? entry.get_input_stream do |is| data = is.sysread if CONTENT_FILES.include?(entry.name) process_entry(data, &block) end update_file(entry.name, data) unless entry.name == MANIFEST_FILE end end end |
#update_manifest(&block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/odf-report/template.rb', line 45 def update_manifest(&block) entry = get_template_entries.find_entry(MANIFEST_FILE) entry.get_input_stream do |is| data = is.sysread process_entry(data, &block) update_file(MANIFEST_FILE, data) end end |