Class: DocxGenerator::DSL::Document
- Inherits:
-
Object
- Object
- DocxGenerator::DSL::Document
- Defined in:
- lib/docx_generator/dsl/document.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #add(*objects) ⇒ Object
-
#initialize(filename) {|_self| ... } ⇒ Document
constructor
A new instance of Document.
- #paragraph(options = {}) {|par| ... } ⇒ Object
-
#save ⇒ Object
Could be better.
Constructor Details
#initialize(filename) {|_self| ... } ⇒ Document
Returns a new instance of Document.
6 7 8 9 10 |
# File 'lib/docx_generator/dsl/document.rb', line 6 def initialize(filename, &block) @filename = filename + ".docx" @objects = [] # It contains all the DSL elements yield self if block end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/docx_generator/dsl/document.rb', line 4 def filename @filename end |
Instance Method Details
#add(*objects) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/docx_generator/dsl/document.rb', line 34 def add(*objects) objects.each do |object| @objects << object end self end |
#paragraph(options = {}) {|par| ... } ⇒ Object
28 29 30 31 32 |
# File 'lib/docx_generator/dsl/document.rb', line 28 def paragraph( = {}, &block) par = DocxGenerator::DSL::Paragraph.new() yield par if block @objects << par end |
#save ⇒ Object
Could be better
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/docx_generator/dsl/document.rb', line 13 def save content_types = generate_content_types rels = generate_rels document = generate_document File.delete(@filename) if File.exists?(@filename) Zip::ZipFile.open(@filename, Zip::ZipFile::CREATE) do |docx| docx.mkdir('_rels') docx.mkdir('word') docx.get_output_stream('[Content_Types].xml') { |f| f.puts content_types } docx.get_output_stream('_rels/.rels') { |f| f.puts rels } docx.get_output_stream('word/document.xml') { |f| f.puts document } end end |