Class: OxmlMaker::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/oxml_maker/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename: nil, params: {}) {|_self| ... } ⇒ Document

Returns a new instance of Document.

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
16
# File 'lib/oxml_maker/document.rb', line 12

def initialize(filename: nil, params: {}, &block)
  @filename = filename
  @params = params
  yield(self) if block_given?
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



10
11
12
# File 'lib/oxml_maker/document.rb', line 10

def filename
  @filename
end

#paramsObject

Returns the value of attribute params.



9
10
11
# File 'lib/oxml_maker/document.rb', line 9

def params
  @params
end

Instance Method Details

#createObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/oxml_maker/document.rb', line 33

def create
  prepare_paths
  cleanup_temp_files
  ensure_directories
  write_document_xml
  zip_docx_folder
  convert_zip_to_docx
  copy_to_public
  cleanup_temp_files
end

#templateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/oxml_maker/document.rb', line 18

def template
  "    <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n    <w:document xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">\n      <w:body>\n        \#{generate_sections}\n        <w:sectPr>\n          <w:pgSz w:w='\#{params[:page_size][:width]}' w:h='\#{params[:page_size][:height]}'/>\n          <w:pgMar w:top='\#{params[:page_margin][:top]}' w:right='\#{params[:page_margin][:right]}' w:bottom='\#{params[:page_margin][:bottom]}' w:left='\#{params[:page_margin][:left]}' w:header='\#{params[:page_margin][:header]}' w:footer='\#{params[:page_margin][:footer]}' w:gutter='\#{params[:page_margin][:gutter]}'/>\n        </w:sectPr>\n      </w:body>\n    </w:document>\n  XML\nend\n"