Class: OpenXml::TemplateDocument
- Inherits:
-
Object
- Object
- OpenXml::TemplateDocument
- Defined in:
- lib/open_xml/template_document.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#template_path ⇒ Object
readonly
Returns the value of attribute template_path.
Instance Method Summary collapse
-
#initialize(options) ⇒ TemplateDocument
constructor
A new instance of TemplateDocument.
- #process ⇒ Object
- #to_zip_buffer ⇒ Object
Constructor Details
#initialize(options) ⇒ TemplateDocument
Returns a new instance of TemplateDocument.
10 11 12 13 14 15 |
# File 'lib/open_xml/template_document.rb', line 10 def initialize() @template_path = [:path] @parts = {} @data = [:data] split_parts end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/open_xml/template_document.rb', line 8 def data @data end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
8 9 10 |
# File 'lib/open_xml/template_document.rb', line 8 def parts @parts end |
#template_path ⇒ Object (readonly)
Returns the value of attribute template_path.
8 9 10 |
# File 'lib/open_xml/template_document.rb', line 8 def template_path @template_path end |
Instance Method Details
#process ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/open_xml/template_document.rb', line 26 def process doc = Nokogiri::XML(parts["word/document.xml"]) doc.xpath("//w:t").each do |node| data.each do |k, v| node.content = node.content.gsub(k, Array(v).join("\n")) if node.content[/#{k}/] end end parts["word/document.xml"] = doc.to_xml end |
#to_zip_buffer ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/open_xml/template_document.rb', line 17 def to_zip_buffer Zip::OutputStream.write_buffer do |w| parts.each do |k, v| w.put_next_entry k w.write v end end end |