Class: PureDocx::Document
- Inherits:
-
Object
- Object
- PureDocx::Document
- Defined in:
- lib/puredocx/document.rb
Instance Attribute Summary collapse
-
#body_content ⇒ Object
Returns the value of attribute body_content.
-
#brake ⇒ Object
readonly
Returns the value of attribute brake.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#header_content ⇒ Object
Returns the value of attribute header_content.
-
#new_page ⇒ Object
readonly
Returns the value of attribute new_page.
-
#pagination_position ⇒ Object
readonly
Returns the value of attribute pagination_position.
-
#rels_constructor ⇒ Object
readonly
Returns the value of attribute rels_constructor.
Instance Method Summary collapse
- #content(items) ⇒ Object
- #ensure_file! ⇒ Object
- #header(items) ⇒ Object
-
#initialize(file_path, arguments = {}) ⇒ Document
constructor
A new instance of Document.
- #save! ⇒ Object
Constructor Details
#initialize(file_path, arguments = {}) ⇒ Document
Returns a new instance of Document.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puredocx/document.rb', line 6 def initialize(file_path, arguments = {}) @file_path = file_path ensure_file! @file_name = File.basename(file_path) @pagination_position = arguments[:pagination_position] @rels_constructor = PureDocx::Constructors::Rels.new @brake = File.read(DocArchive.template_path('brake.xml')) @new_page = File.read(DocArchive.template_path('new_page.xml')) @header_content = '' @body_content = '' (class << self; self; end).class_eval do %i[text table image].each do |method_name| define_method method_name do |content, = {}| Object.const_get( "PureDocx::XmlGenerators::#{method_name.to_s.capitalize}" ).new(content, rels_constructor, ).xml end end end end |
Instance Attribute Details
#body_content ⇒ Object
Returns the value of attribute body_content.
3 4 5 |
# File 'lib/puredocx/document.rb', line 3 def body_content @body_content end |
#brake ⇒ Object (readonly)
Returns the value of attribute brake.
4 5 6 |
# File 'lib/puredocx/document.rb', line 4 def brake @brake end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
4 5 6 |
# File 'lib/puredocx/document.rb', line 4 def file_name @file_name end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
4 5 6 |
# File 'lib/puredocx/document.rb', line 4 def file_path @file_path end |
#header_content ⇒ Object
Returns the value of attribute header_content.
3 4 5 |
# File 'lib/puredocx/document.rb', line 3 def header_content @header_content end |
#new_page ⇒ Object (readonly)
Returns the value of attribute new_page.
4 5 6 |
# File 'lib/puredocx/document.rb', line 4 def new_page @new_page end |
#pagination_position ⇒ Object (readonly)
Returns the value of attribute pagination_position.
4 5 6 |
# File 'lib/puredocx/document.rb', line 4 def pagination_position @pagination_position end |
#rels_constructor ⇒ Object (readonly)
Returns the value of attribute rels_constructor.
4 5 6 |
# File 'lib/puredocx/document.rb', line 4 def rels_constructor @rels_constructor end |
Instance Method Details
#content(items) ⇒ Object
31 32 33 |
# File 'lib/puredocx/document.rb', line 31 def content(items) self.body_content += items.join end |
#ensure_file! ⇒ Object
35 36 37 38 |
# File 'lib/puredocx/document.rb', line 35 def ensure_file! return unless File.exist?(file_path) raise FileCreatingError, 'File already exists in this directory. Please change the file name!' end |
#header(items) ⇒ Object
27 28 29 |
# File 'lib/puredocx/document.rb', line 27 def header(items) self.header_content += items.join end |
#save! ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/puredocx/document.rb', line 40 def save! rels_constructor.prepare_basic_rels! DocArchive.open(file_path, rels_constructor.rels) do |file| file.add('[Content_Types].xml', DocArchive.template_path('[Content_Types].xml')) file.save_rels file.save_document_content(body_content, header_content, pagination_position) end end |