Class: DocxGenerator::Document
- Inherits:
-
Object
- Object
- DocxGenerator::Document
- Defined in:
- lib/docx_generator/document.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#add_paragraph(*text_fragments) ⇒ Object
text_fragments : Word::Text or String Later: Paragraph Object, with Text Object.
-
#initialize(filename) ⇒ Document
constructor
A new instance of Document.
- #save ⇒ Object
- #text(text_fragment, arguments = {}) ⇒ Object
Constructor Details
#initialize(filename) ⇒ Document
Returns a new instance of Document.
5 6 7 8 |
# File 'lib/docx_generator/document.rb', line 5 def initialize(filename) @filename = filename @content = [] end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/docx_generator/document.rb', line 3 def filename @filename end |
Instance Method Details
#add_paragraph(*text_fragments) ⇒ Object
text_fragments : Word::Text or String Later: Paragraph Object, with Text Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/docx_generator/document.rb', line 26 def add_paragraph(*text_fragments) content = [] text_fragments.each do |text_fragment| content.push(text_fragment.respond_to?(:generate) ? text_fragment : text(text_fragment)) content.push Word::Extensions.space end content.pop @content.push Word::Paragraph.new({}, content) self end |
#save ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/docx_generator/document.rb', line 10 def save content_types = generate_content_types rels = generate_rels document = generate_document Zip::Archive.open(@filename + ".docx", Zip::CREATE | Zip::TRUNC) do |docx| docx.add_dir('_rels') docx.add_dir('word') docx.add_buffer('[Content_Types].xml', content_types) docx.add_buffer('_rels/.rels', rels) docx.add_buffer('word/document.xml', document) end end |
#text(text_fragment, arguments = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/docx_generator/document.rb', line 37 def text(text_fragment, arguments = {}) content = [] if arguments.length != 0 = [] arguments.each do |option, value| .push parse_option(option, value) end content.push Word::RunProperties.new({}, ) end content.push Word::Text.new({}, [text_fragment]) Word::Run.new({}, content) end |