Class: Metanorma::Iso::Sts::Transformer::InlineTransformer

Inherits:
Transformer::Base
  • Object
show all
Includes:
ContentText
Defined in:
lib/metanorma/iso/sts/transformer/inline_transformer.rb

Instance Method Summary collapse

Methods included from ContentText

#extract_text, #extract_text_value

Instance Method Details

#apply_inline_content(source, target) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/metanorma/iso/sts/transformer/inline_transformer.rb', line 46

def apply_inline_content(source, target)
  source.each_mixed_content do |node|
    result = transform_inline(node)
    next unless result

    type, value = result
    if type == :content
      target.content value
    else
      target.send(type, value)
    end
  end
  target
end

#apply_tbx_content(source, target, text_attr: :value) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/metanorma/iso/sts/transformer/inline_transformer.rb', line 67

def apply_tbx_content(source, target, text_attr: :value)
  source.each_mixed_content do |node|
    result = transform_tbx_inline(node)
    next unless result

    type, value = result
    if type == :content
      target.send(text_attr, value)
    else
      target.send(type, value)
    end
  end
  target
end

#apply_term_inline_content(source, target) ⇒ Object



61
62
63
64
65
# File 'lib/metanorma/iso/sts/transformer/inline_transformer.rb', line 61

def apply_term_inline_content(source, target)
  text = extract_text(source)
  target.content = [text] if text && !text.empty?
  target
end

#build_tbx_bold(node) ⇒ Object



115
116
117
118
119
# File 'lib/metanorma/iso/sts/transformer/inline_transformer.rb', line 115

def build_tbx_bold(node)
  ::Sts::TbxIsoTml::Bold.new do |b|
    apply_inline_content(node, b)
  end
end

#build_tbx_italic(node) ⇒ Object



109
110
111
112
113
# File 'lib/metanorma/iso/sts/transformer/inline_transformer.rb', line 109

def build_tbx_italic(node)
  ::Sts::TbxIsoTml::Italic.new do |i|
    apply_inline_content(node, i)
  end
end

#transform_inline(node) ⇒ Object



9
10
11
12
13
14
15
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
# File 'lib/metanorma/iso/sts/transformer/inline_transformer.rb', line 9

def transform_inline(node)
  case node
  when String
    [:content, node]
  when Metanorma::Document::Components::Inline::EmRawElement
    [:italic, transform_italic(node)]
  when Metanorma::Document::Components::Inline::StrongRawElement
    [:bold, transform_bold(node)]
  when Metanorma::Document::Components::Inline::SubElement
    [:sub, transform_sub(node)]
  when Metanorma::Document::Components::Inline::SupElement
    [:sup, transform_sup(node)]
  when Metanorma::Document::Components::Inline::TtElement
    [:monospace, transform_monospace(node)]
  when Metanorma::Document::Components::Inline::SmallCapElement
    [:sc, transform_smallcap(node)]
  when Metanorma::Document::Components::Inline::XrefElement
    [:xref, transform_xref(node)]
  when Metanorma::Document::Components::Inline::ErefElement
    [:std, transform_eref(node)]
  when Metanorma::Document::Components::Inline::FnElement
    [:xref, transform_fn(node)]
  when Metanorma::Document::Components::Inline::LinkElement
    [:ext_link, transform_link(node)]
  when Metanorma::Document::Components::Inline::BrElement
    [:break, transform_br(node)]
  when Metanorma::Document::Components::Inline::StemInlineElement
    [:inline_formula, transform_stem(node)]
  when Metanorma::Document::Components::Inline::ConceptElement
    nil
  when Metanorma::Document::Components::Inline::SpanElement
    [:styled_content, transform_span(node)]
  when Metanorma::Document::Components::Inline::Bcp14Element
    [:bold, transform_bcp14(node)]
  end
end

#transform_tbx_inline(node) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/metanorma/iso/sts/transformer/inline_transformer.rb', line 82

def transform_tbx_inline(node)
  case node
  when String
    [:content, node]
  when Metanorma::Document::Components::Inline::EmRawElement
    [:italic, build_tbx_italic(node)]
  when Metanorma::Document::Components::Inline::StrongRawElement
    [:bold, build_tbx_bold(node)]
  when Metanorma::Document::Components::Inline::SubElement
    [:sub, transform_sub(node)]
  when Metanorma::Document::Components::Inline::SupElement
    [:sup, transform_sup(node)]
  when Metanorma::Document::Components::Inline::XrefElement
    [:xref, transform_xref(node)]
  when Metanorma::Document::Components::Inline::ErefElement
    [:std, transform_eref(node)]
  when Metanorma::Document::Components::Inline::FnElement
    [:xref, transform_fn(node)]
  when Metanorma::Document::Components::Inline::LinkElement
    [:ext_link, transform_link(node)]
  when Metanorma::Document::Components::Inline::StemInlineElement
    [:inline_formula, transform_stem(node)]
  when Metanorma::Document::Components::Inline::TtElement
    [:monospace, transform_monospace(node)]
  end
end