Module: Coradoc::Docx

Defined in:
lib/coradoc/docx.rb,
lib/coradoc/docx/version.rb,
lib/coradoc/docx/transform.rb,
lib/coradoc/docx/transform/rule.rb,
lib/coradoc/docx/transform/context.rb,
lib/coradoc/docx/transform/rule_registry.rb,
lib/coradoc/docx/transform/to_core_model.rb,
lib/coradoc/docx/transform/rules/run_rule.rb,
lib/coradoc/docx/transform/style_resolver.rb,
lib/coradoc/docx/transform/from_core_model.rb,
lib/coradoc/docx/transform/ordered_content.rb,
lib/coradoc/docx/transform/rules/math_rule.rb,
lib/coradoc/docx/transform/rules/text_rule.rb,
lib/coradoc/docx/transform/rules/break_rule.rb,
lib/coradoc/docx/transform/rules/image_rule.rb,
lib/coradoc/docx/transform/rules/table_rule.rb,
lib/coradoc/docx/transform/numbering_resolver.rb,
lib/coradoc/docx/transform/rules/heading_rule.rb,
lib/coradoc/docx/transform/rules/bookmark_rule.rb,
lib/coradoc/docx/transform/rules/footnote_rule.rb,
lib/coradoc/docx/transform/rules/hyperlink_rule.rb,
lib/coradoc/docx/transform/rules/list_item_rule.rb,
lib/coradoc/docx/transform/rules/paragraph_rule.rb,
lib/coradoc/docx/transform/rules/proof_error_rule.rb,
lib/coradoc/docx/transform/rules/simple_field_rule.rb,
lib/coradoc/docx/transform/rules/structured_document_tag_rule.rb

Defined Under Namespace

Modules: Transform

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.parse(input, _options = {}) ⇒ Uniword::Wordprocessingml::DocumentRoot

Parse a DOCX input to Uniword model (no CoreModel conversion)

Parameters:

  • input (String, IO)

    path to .docx file or IO stream

Returns:

  • (Uniword::Wordprocessingml::DocumentRoot)

    Uniword document model



40
41
42
# File 'lib/coradoc/docx.rb', line 40

def parse(input, _options = {})
  coerce_to_document(input)
end

.parse_to_core(input, _options = {}) ⇒ Coradoc::CoreModel::StructuralElement

Parse a DOCX input to CoreModel

Parameters:

  • input (String, IO, Uniword::Wordprocessingml::DocumentRoot)

    Path to .docx file, IO stream, or pre-parsed Uniword document

  • _options (Hash) (defaults to: {})

    additional options (reserved)

Returns:

  • (Coradoc::CoreModel::StructuralElement)

    CoreModel document



31
32
33
34
# File 'lib/coradoc/docx.rb', line 31

def parse_to_core(input, _options = {})
  document = coerce_to_document(input)
  Transform::ToCoreModel.transform(document)
end

.serialize(core_model, **options) ⇒ String, Uniword::Wordprocessingml::DocumentRoot

Serialize CoreModel to DOCX

Parameters:

  • core_model (Coradoc::CoreModel::Base)

    CoreModel document

  • options (Hash)

    serialization options

Options Hash (**options):

  • :output_path (String)

    Path to write .docx file

Returns:

  • (String, Uniword::Wordprocessingml::DocumentRoot)

    Returns the output path if :output_path given, otherwise the DocumentRoot



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/coradoc/docx.rb', line 56

def serialize(core_model, **options)
  document = Transform::FromCoreModel.transform(core_model)

  if options[:output_path]
    document.save(options[:output_path])
    options[:output_path]
  elsif options[:to_io]
    io = options[:to_io]
    document.save(io.path)
    io
  else
    document
  end
end

.serialize?Boolean

Whether this format supports serialization

Returns:

  • (Boolean)


45
46
47
# File 'lib/coradoc/docx.rb', line 45

def serialize?
  true
end