Class: Uniword::Resource::DocumentElementConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/resource/document_element_converter.rb

Overview

Converts document element templates into OOXML document structures.

Instance Method Summary collapse

Instance Method Details

#to_document(element) ⇒ Uniword::Wordprocessingml::DocumentRoot

Convert a template element to a standalone DocumentRoot

Parameters:

  • element (Hash)

    Template element definition

Returns:



23
24
25
26
27
28
29
# File 'lib/uniword/resource/document_element_converter.rb', line 23

def to_document(element)
  doc = Uniword::Wordprocessingml::DocumentRoot.new
  to_paragraphs(element).each do |para|
    doc.body.paragraphs << para
  end
  doc
end

#to_paragraphs(element) ⇒ Array<Uniword::Wordprocessingml::Paragraph>

Convert a template element to an array of OOXML paragraphs

Parameters:

  • element (Hash)

    Template element definition

Returns:



11
12
13
14
15
16
17
# File 'lib/uniword/resource/document_element_converter.rb', line 11

def to_paragraphs(element)
  return [] unless element && element["body"] && element["body"]["paragraphs"]

  element["body"]["paragraphs"].map do |para_def|
    build_paragraph(para_def)
  end
end