Module: Asciidoctor::Standoc::Blocks

Included in:
Converter
Defined in:
lib/asciidoctor/standoc/reqt.rb,
lib/asciidoctor/standoc/blocks.rb,
lib/asciidoctor/standoc/blocks_notes.rb

Instance Method Summary collapse

Instance Method Details

#admonition(node) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/asciidoctor/standoc/blocks_notes.rb', line 92

def admonition(node)
  return termnote(node) if in_terms?
  return note(node) if node.attr("name") == "note"
  return todo(node) if node.attr("name") == "todo"

  noko do |xml|
    xml.admonition **admonition_attrs(node) do |a|
      node.title.nil? or a.name { |name| name << node.title }
      wrap_in_para(node, a)
    end
  end.join("\n")
end

#admonition_attrs(node) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/asciidoctor/standoc/blocks_notes.rb', line 79

def admonition_attrs(node)
  name = node.attr("name")
  a = node.attr("type") and ["danger", "safety precautions"].each do |t|
    name = t if a.casecmp(t).zero?
  end
  attr_code(
    keep_attrs(node).merge(
      id: Metanorma::Utils::anchor_or_uuid(node), type: name,
      beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
    )
  )
end

#example(node) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/asciidoctor/standoc/blocks.rb', line 87

def example(node)
  return term_example(node) if in_terms?

  role = node.role || node.attr("style")
  %w(recommendation requirement permission).include?(role) and
    return requirement(node, role)
  return pseudocode_example(node) if role == "pseudocode"
  return svgmap_example(node) if role == "svgmap"
  return form(node) if role == "form"
  return termdefinition(node) if role == "definition"

  reqt_subpart(role) and return requirement_subpart(node)
  example_proper(node)
end

#example_attrs(node) ⇒ Object



132
133
134
# File 'lib/asciidoctor/standoc/blocks.rb', line 132

def example_attrs(node)
  attr_code(id_unnum_attrs(node).merge(keep_attrs(node)))
end

#example_proper(node) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/asciidoctor/standoc/blocks.rb', line 136

def example_proper(node)
  noko do |xml|
    xml.example **example_attrs(node) do |ex|
      node.title.nil? or ex.name { |name| name << node.title }
      wrap_in_para(node, ex)
    end
  end.join("\n")
end

#figure_attrs(node) ⇒ Object



151
152
153
# File 'lib/asciidoctor/standoc/blocks.rb', line 151

def figure_attrs(node)
  attr_code(id_unnum_attrs(node).merge(keep_attrs(node)))
end

#figure_title(node, out) ⇒ Object



145
146
147
148
149
# File 'lib/asciidoctor/standoc/blocks.rb', line 145

def figure_title(node, out)
  return if node.title.nil?

  out.name { |name| name << node.title }
end

#form(node) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/asciidoctor/standoc/blocks.rb', line 44

def form(node)
  noko do |xml|
    xml.form **attr_code(
      id: Metanorma::Utils::anchor_or_uuid, class: node.attr("class"),
      name: node.attr("name"), action: node.attr("action")
    ) do |f|
      f << node.content
    end
  end
end

#formula_attrs(node) ⇒ Object



19
20
21
22
23
24
# File 'lib/asciidoctor/standoc/blocks.rb', line 19

def formula_attrs(node)
  attr_code(id_unnum_attrs(node)
    .merge(keep_attrs(node).merge(
             inequality: node.option?("inequality") ? "true" : nil,
           )))
end

#id_attr(node = nil) ⇒ Object



8
9
10
# File 'lib/asciidoctor/standoc/blocks.rb', line 8

def id_attr(node = nil)
  { id: Metanorma::Utils::anchor_or_uuid(node) }
end

#id_unnum_attrs(node) ⇒ Object



12
13
14
15
16
17
# File 'lib/asciidoctor/standoc/blocks.rb', line 12

def id_unnum_attrs(node)
  attr_code(id: Metanorma::Utils::anchor_or_uuid(node),
            unnumbered: node.option?("unnumbered") ? "true" : nil,
            number: node.attr("number"),
            subsequence: node.attr("subsequence"))
end

#image(node) ⇒ Object



155
156
157
158
159
160
161
162
# File 'lib/asciidoctor/standoc/blocks.rb', line 155

def image(node)
  noko do |xml|
    xml.figure **figure_attrs(node) do |f|
      figure_title(node, f)
      f.image **image_attributes(node)
    end
  end
end

#keep_attrs(node) ⇒ Object



26
27
28
29
# File 'lib/asciidoctor/standoc/blocks.rb', line 26

def keep_attrs(node)
  { "keep-with-next": node.attr("keep-with-next"),
    "keep-lines-together": node.attr("keep-lines-together") }
end

#listing(node) ⇒ Object

NOTE: html escaping is performed by Nokogiri



218
219
220
221
222
223
224
225
226
227
# File 'lib/asciidoctor/standoc/blocks.rb', line 218

def listing(node)
  fragment = ::Nokogiri::XML::Builder.new do |xml|
    xml.sourcecode **listing_attrs(node) do |s|
      figure_title(node, s)
      s << node.content
    end
  end
  fragment.to_xml(encoding: "US-ASCII", save_with:
                  Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
end

#listing_attrs(node) ⇒ Object



208
209
210
211
212
213
214
215
# File 'lib/asciidoctor/standoc/blocks.rb', line 208

def listing_attrs(node)
  attr_code(keep_attrs(node)
            .merge(lang: node.attr("language"),
                   id: Metanorma::Utils::anchor_or_uuid(node),
                   unnumbered: node.option?("unnumbered") ? "true" : nil,
                   number: node.attr("number"),
                   filename: node.attr("filename")))
end

#literal(node) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/asciidoctor/standoc/blocks.rb', line 59

def literal(node)
  noko do |xml|
    xml.figure **literal_attrs(node) do |f|
      figure_title(node, f)
      f.pre node.lines.join("\n"),
            **attr_code(id: Metanorma::Utils::anchor_or_uuid,
                        alt: node.attr("alt"))
    end
  end
end

#literal_attrs(node) ⇒ Object



55
56
57
# File 'lib/asciidoctor/standoc/blocks.rb', line 55

def literal_attrs(node)
  attr_code(id_attr(node).merge(keep_attrs(node)))
end

#note(node) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/asciidoctor/standoc/blocks_notes.rb', line 71

def note(node)
  noko do |xml|
    xml.note **note_attrs(node) do |c|
      wrap_in_para(node, c)
    end
  end.join("\n")
end

#note_attrs(node) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/asciidoctor/standoc/blocks_notes.rb', line 17

def note_attrs(node)
  attr_code(
    termnote_attrs(node).merge(
      type: node.attr("type"),
      beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
    )
  )
end

#open(node) ⇒ Object

We append each contained block to its parent



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/asciidoctor/standoc/blocks.rb', line 32

def open(node)
  role = node.role || node.attr("style")
  reqt_subpart(role) and return requirement_subpart(node)
  role == "form" and return form(node)
  role == "definition" and return termdefinition(node)
  result = []
  node.blocks.each do |b|
    result << send(b.context, b)
  end
  result
end

#para_attrs(node) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/asciidoctor/standoc/blocks.rb', line 164

def para_attrs(node)
  attr_code(keep_attrs(node)
    .merge(align: node.attr("align"),
           variant_title: node.role == "variant-title" ? true : nil,
           type: node.attr("type"),
           id: Metanorma::Utils::anchor_or_uuid(node)))
end

#paragraph(node) ⇒ Object



172
173
174
175
176
177
178
179
180
# File 'lib/asciidoctor/standoc/blocks.rb', line 172

def paragraph(node)
  return termsource(node) if node.role == "source"

  noko do |xml|
    xml.p **para_attrs(node) do |xml_t|
      xml_t << node.content
    end
  end.join("\n")
end

#pass(node) ⇒ Object



229
230
231
232
233
234
235
236
# File 'lib/asciidoctor/standoc/blocks.rb', line 229

def pass(node)
  noko do |xml|
    xml.passthrough **attr_code(formats:
                                node.attr("format") || "metanorma") do |p|
      p << HTMLEntities.new.encode(node.content, :basic, :hexadecimal)
    end
  end
end

#pseudocode_example(node) ⇒ Object

prevent A’s and other subs inappropriate for pseudocode



122
123
124
125
126
127
128
129
130
# File 'lib/asciidoctor/standoc/blocks.rb', line 122

def pseudocode_example(node)
  node.blocks.each { |b| b.remove_sub(:replacements) }
  noko do |xml|
    xml.figure **example_attrs(node).merge(class: "pseudocode") do |ex|
      figure_title(node, ex)
      wrap_in_para(node, ex)
    end
  end.join("\n")
end

#quote(node) ⇒ Object



199
200
201
202
203
204
205
206
# File 'lib/asciidoctor/standoc/blocks.rb', line 199

def quote(node)
  noko do |xml|
    xml.quote **quote_attrs(node) do |q|
      quote_attribution(node, q)
      wrap_in_para(node, q)
    end
  end.join("\n")
end

#quote_attribution(node, out) ⇒ Object



188
189
190
191
192
193
194
195
196
197
# File 'lib/asciidoctor/standoc/blocks.rb', line 188

def quote_attribution(node, out)
  if node.attr("citetitle")
    m = /^(?<cite>[^,]+)(,(?<text>.*$))?$/m.match node.attr("citetitle")
    out.source **attr_code(target: m[:cite], type: "inline") do |s|
      s <<  m[:text]
    end
  end
  node.attr("attribution") and
    out.author { |a| a << node.attr("attribution") }
end

#quote_attrs(node) ⇒ Object



182
183
184
185
186
# File 'lib/asciidoctor/standoc/blocks.rb', line 182

def quote_attrs(node)
  attr_code(keep_attrs(node)
    .merge(align: node.attr("align"),
           id: Metanorma::Utils::anchor_or_uuid(node)))
end

#req_classif_parse(classif) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/asciidoctor/standoc/reqt.rb', line 31

def req_classif_parse(classif)
  ret = []
  HTMLEntities.new.decode(classif).split(/;\s*/).each do |c|
    c1 = c.split(/:\s*/)
    next unless c1.size == 2

    c1[1].split(/,\s*/).each { |v| ret << [c1[0], v] }
  end
  ret
end

#reqt_attrs(node) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/asciidoctor/standoc/reqt.rb', line 51

def reqt_attrs(node)
  attr_code(keep_attrs(node).merge(id_unnum_attrs(node)).merge(
              id: Metanorma::Utils::anchor_or_uuid(node),
              unnumbered: node.option?("unnumbered") ? "true" : nil,
              number: node.attr("number"),
              subsequence: node.attr("subsequence"),
              obligation: node.attr("obligation"),
              filename: node.attr("filename"),
              type: node.attr("type"),
              model: node.attr("model"),
            ))
end

#reqt_subpart(name) ⇒ Object



9
10
11
12
# File 'lib/asciidoctor/standoc/reqt.rb', line 9

def reqt_subpart(name)
  %w(specification measurement-target verification import label title
     description component subject inherit classification).include? name
end

#reqt_subpart_attrs(node, name) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/asciidoctor/standoc/reqt.rb', line 14

def reqt_subpart_attrs(node, name)
  klass = node.attr("class") || "component"
  attr_code(keep_attrs(node)
    .merge(exclude: node.option?("exclude"),
           type: node.attr("type"),
           class: name == "component" ? klass : nil))
end

#requirement(node, obligation) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/asciidoctor/standoc/reqt.rb', line 80

def requirement(node, obligation)
  noko do |xml|
    xml.send obligation, **reqt_attrs(node) do |ex|
      requirement_elems(node, ex)
      wrap_in_para(node, ex)
    end
  end.join("\n")
end

#requirement_classification(classif, out) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/asciidoctor/standoc/reqt.rb', line 42

def requirement_classification(classif, out)
  req_classif_parse(classif).each do |r|
    out.classification do |c|
      c.tag { |t| t << r[0] }
      c.value { |v| v << r[1] }
    end
  end
end

#requirement_elems(node, out) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/asciidoctor/standoc/reqt.rb', line 64

def requirement_elems(node, out)
  node.title and out.title { |t| t << node.title }
  a = node.attr("label") and out.label do |l|
    l << a
  end
  a = node.attr("subject") and csv_split(a)&.each do |subj|
    out.subject { |s| s << subj }
  end
  a = HTMLEntities.new.decode(node.attr("inherit")) and
    csv_split(a)&.each do |i|
      out.inherit { |inh| inh << i }
    end
  classif = node.attr("classification") and
    requirement_classification(classif, out)
end

#requirement_subpart(node) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/asciidoctor/standoc/reqt.rb', line 22

def requirement_subpart(node)
  name = node.role || node.attr("style")
  noko do |xml|
    xml.send name, **reqt_subpart_attrs(node, name) do |o|
      o << node.content
    end
  end
end


35
36
37
38
39
40
41
42
43
# File 'lib/asciidoctor/standoc/blocks_notes.rb', line 35

def sidebar(node)
  return unless draft?

  noko do |xml|
    xml.review **sidebar_attrs(node) do |r|
      wrap_in_para(node, r)
    end
  end
end


26
27
28
29
30
31
32
33
# File 'lib/asciidoctor/standoc/blocks_notes.rb', line 26

def sidebar_attrs(node)
  todo_attrs(node).merge(
    attr_code(
      from: node.attr("from"),
      to: node.attr("to") || node.attr("from")
    )
  )
end

#stem(node) ⇒ Object

NOTE: html escaping is performed by Nokogiri



71
72
73
74
75
76
77
# File 'lib/asciidoctor/standoc/blocks.rb', line 71

def stem(node)
  noko do |xml|
    xml.formula **formula_attrs(node) do |s|
      stem_parse(node.lines.join("\n"), s, node.style.to_sym)
    end
  end
end

#svgmap_attrs(node) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/asciidoctor/standoc/blocks.rb', line 102

def svgmap_attrs(node)
  attr_code({ id: node.id,
              unnumbered: node.option?("unnumbered") ? "true" : nil,
              number: node.attr("number"),
              subsequence: node.attr("subsequence") }
  .merge(keep_attrs(node)))
end

#svgmap_example(node) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/asciidoctor/standoc/blocks.rb', line 110

def svgmap_example(node)
  noko do |xml|
    xml.svgmap **attr_code(svgmap_attrs(node).merge(
                             src: node.attr("src"), alt: node.attr("alt"),
                           )) do |ex|
      figure_title(node, ex)
      ex << node.content
    end
  end.join("\n")
end

#term_example(node) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/asciidoctor/standoc/blocks.rb', line 79

def term_example(node)
  noko do |xml|
    xml.termexample **id_attr(node) do |ex|
      wrap_in_para(node, ex)
    end
  end.join("\n")
end

#termnote(node) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/asciidoctor/standoc/blocks_notes.rb', line 63

def termnote(node)
  noko do |xml|
    xml.termnote **termnote_attrs(node) do |ex|
      wrap_in_para(node, ex)
    end
  end.join("\n")
end

#termnote_attrs(node) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/asciidoctor/standoc/blocks_notes.rb', line 4

def termnote_attrs(node)
  attr_code(
    id_attr(node).merge(
      unnumbered: node.attr("unnumbered"),
      number: node.attr("number"),
      subsequence: node.attr("subsequence"),
      "keep-with-next": node.attr("keep-with-next"),
      "keep-lines-together": node.attr("keep-with-next"),
      "keep-separate": node.attr("keep-separate")
    )
  )
end

#todo(node) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/asciidoctor/standoc/blocks_notes.rb', line 55

def todo(node)
  noko do |xml|
    xml.review **todo_attrs(node) do |r|
      wrap_in_para(node, r)
    end
  end
end

#todo_attrs(node) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/asciidoctor/standoc/blocks_notes.rb', line 45

def todo_attrs(node)
  date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
  date += "T00:00:00Z" unless /T/.match? date
  attr_code(
    id: ::Metanorma::Utils::anchor_or_uuid(node),
    reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
    date: date
  )
end