Class: Coradoc::Markdown::Transform::FromCoreModel

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

Overview

Transforms CoreModel models to Markdown equivalents

This transformer converts the canonical CoreModel representation to format-specific Markdown model.

Class Method Summary collapse

Class Method Details

.transform(model) ⇒ Coradoc::Markdown::Base

Transform a CoreModel to Markdown model

Parameters:

  • model (Coradoc::CoreModel::Base)

    CoreModel to transform

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/coradoc/markdown/transform/from_core_model.rb', line 16

def transform(model)
  case model
  when Coradoc::CoreModel::StructuralElement
    transform_structural_element(model)
  when Coradoc::CoreModel::AnnotationBlock
    # Must be checked before Block since AnnotationBlock < Block
    transform_annotation_block(model)
  when Coradoc::CoreModel::Block
    transform_block(model)
  when Coradoc::CoreModel::ListBlock
    transform_list(model)
  when Coradoc::CoreModel::DefinitionList
    transform_definition_list(model)
  when Coradoc::CoreModel::Table
    transform_table(model)
  when Coradoc::CoreModel::Image
    transform_image(model)
  when Coradoc::CoreModel::InlineElement
    transform_inline(model)
  when Coradoc::CoreModel::Footnote
    transform_footnote(model)
  when Coradoc::CoreModel::FootnoteReference
    transform_footnote_reference(model)
  when Coradoc::CoreModel::Abbreviation
    transform_abbreviation(model)
  when Coradoc::CoreModel::Toc
    Coradoc::Markdown::Extension.toc
  when Coradoc::CoreModel::Term
    Coradoc::Markdown::Strong.new(text: model.text.to_s)
  when Coradoc::CoreModel::Bibliography
    transform_bibliography(model)
  when Coradoc::CoreModel::BibliographyEntry
    transform_bibliography_entry(model)
  when Coradoc::CoreModel::TocEntry
    Coradoc::Markdown::Text.new(content: model.title.to_s)
  when Array
    model.map { |item| transform(item) }
  else
    model
  end
end