Class: RubyDocx::Document
- Inherits:
-
Object
- Object
- RubyDocx::Document
- Defined in:
- lib/ruby_docx/elements/document.rb
Constant Summary collapse
- TEMPLATE =
'document.xml'
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
Instance Method Summary collapse
- #append(block) ⇒ Object
- #build ⇒ Object
- #file ⇒ Object
-
#initialize(children = []) ⇒ Document
constructor
A new instance of Document.
- #prepend(block) ⇒ Object
- #render ⇒ Object
- #save(path) ⇒ Object
Constructor Details
#initialize(children = []) ⇒ Document
Returns a new instance of Document.
7 8 9 |
# File 'lib/ruby_docx/elements/document.rb', line 7 def initialize(children = []) @children = children end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/ruby_docx/elements/document.rb', line 5 def children @children end |
Instance Method Details
#append(block) ⇒ Object
11 12 13 |
# File 'lib/ruby_docx/elements/document.rb', line 11 def append(block) @children << block end |
#build ⇒ Object
19 20 21 22 23 24 |
# File 'lib/ruby_docx/elements/document.rb', line 19 def build doc = Nokogiri::XML(File.read( File.("../../templates/#{TEMPLATE}", __FILE__) )) body = doc.at '/w:document/w:body' @children.each { |child| body.add_child child.build } doc end |
#file ⇒ Object
30 31 32 33 |
# File 'lib/ruby_docx/elements/document.rb', line 30 def file file = Tempfile.new('order_preview') write_file(file) end |
#prepend(block) ⇒ Object
15 16 17 |
# File 'lib/ruby_docx/elements/document.rb', line 15 def prepend(block) @children.unshift block end |
#render ⇒ Object
26 27 28 |
# File 'lib/ruby_docx/elements/document.rb', line 26 def render build.to_s end |
#save(path) ⇒ Object
35 36 37 38 |
# File 'lib/ruby_docx/elements/document.rb', line 35 def save(path) file = File.open(path, 'w') write_file(file).close end |