Class: Coradoc::Docx::Transform::FromCoreModel

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/docx/transform/from_core_model.rb

Overview

Transforms CoreModel to OOXML document via Uniword Builder.

Follows the hub-and-spoke architecture: CoreModel elements are dispatched to handler methods that produce Uniword OOXML objects. The resulting DocumentRoot is serialized to .docx format.

Examples:

Convert CoreModel to DOCX file

Coradoc::Docx::Transform::FromCoreModel.transform_to_file(core, "output.docx")

Get Uniword DocumentRoot

doc = Coradoc::Docx::Transform::FromCoreModel.transform(core)
doc.save("output.docx")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.transform(core) ⇒ Uniword::Wordprocessingml::DocumentRoot

Transform a CoreModel document to a Uniword DocumentRoot

Parameters:

  • core (Coradoc::CoreModel::Base)

    CoreModel document

Returns:

  • (Uniword::Wordprocessingml::DocumentRoot)

    OOXML document



26
27
28
# File 'lib/coradoc/docx/transform/from_core_model.rb', line 26

def transform(core)
  new.transform(core)
end

.transform_to_file(core, path) ⇒ void

This method returns an undefined value.

Transform a CoreModel document and save to .docx file

Parameters:

  • core (Coradoc::CoreModel::Base)

    CoreModel document

  • path (String)

    output file path



35
36
37
38
# File 'lib/coradoc/docx/transform/from_core_model.rb', line 35

def transform_to_file(core, path)
  doc = transform(core)
  doc.save(path)
end

Instance Method Details

#transform(core) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/coradoc/docx/transform/from_core_model.rb', line 41

def transform(core)
  case core
  when Coradoc::CoreModel::StructuralElement
    transform_structural_element(core)
  when Coradoc::CoreModel::AnnotationBlock
    transform_annotation_block(core)
  when Coradoc::CoreModel::Block
    transform_block(core)
  when Coradoc::CoreModel::ListBlock
    transform_list(core)
  when Coradoc::CoreModel::Table
    transform_table(core)
  when Coradoc::CoreModel::Image
    transform_image(core)
  when Coradoc::CoreModel::InlineElement
    transform_inline(core)
  when Coradoc::CoreModel::FootnoteReference
    build_ooxml_footnote_reference(core)
  when Coradoc::CoreModel::Footnote
    build_ooxml_footnote(core)
  when Coradoc::CoreModel::DefinitionList
    build_ooxml_definition_list(core)
  when Coradoc::CoreModel::Toc
    build_ooxml_toc(core)
  when Coradoc::CoreModel::Term
    build_ooxml_term(core)
  when Coradoc::CoreModel::Abbreviation
    build_ooxml_abbreviation(core)
  when Coradoc::CoreModel::Bibliography
    build_ooxml_bibliography(core)
  when Coradoc::CoreModel::BibliographyEntry
    build_ooxml_bibliography_entry(core)
  when Coradoc::CoreModel::TocEntry
    build_ooxml_toc_entry(core)
  when Array
    transform_array(core)
  else
    core
  end
end