Module: Asciidoctor::Standoc::Blocks

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

Instance Method Summary collapse

Instance Method Details

#admonition(node) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/asciidoctor/standoc/blocks.rb', line 125

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



116
117
118
119
120
121
122
123
# File 'lib/asciidoctor/standoc/blocks.rb', line 116

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(id: Utils::anchor_or_uuid(node), type: name,
            beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil)
end

#example(node) ⇒ Object



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

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"
  example_proper(node)
end

#example_attrs(node) ⇒ Object



165
166
167
# File 'lib/asciidoctor/standoc/blocks.rb', line 165

def example_attrs(node)
  attr_code(id_unnum_attr(node))
end

#example_proper(node) ⇒ Object



169
170
171
172
173
174
175
176
# File 'lib/asciidoctor/standoc/blocks.rb', line 169

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



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

def figure_attrs(node)
  attr_code(id_unnum_attr(node))
end

#figure_title(node, f) ⇒ Object



178
179
180
181
# File 'lib/asciidoctor/standoc/blocks.rb', line 178

def figure_title(node, f)
  return if node.title.nil?
  f.name { |name| name << node.title }
end

#formula_attr(node) ⇒ Object



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

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

#id_attr(node = nil) ⇒ Object



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

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

#id_unnum_attr(node) ⇒ Object



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

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

#image(node) ⇒ Object



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

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

#listing(node) ⇒ Object

NOTE: html escaping is performed by Nokogiri



241
242
243
244
245
246
247
248
249
250
# File 'lib/asciidoctor/standoc/blocks.rb', line 241

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



233
234
235
236
237
238
# File 'lib/asciidoctor/standoc/blocks.rb', line 233

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

#literal(node) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/asciidoctor/standoc/blocks.rb', line 50

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: Utils::anchor_or_uuid,
                                               alt: node.attr("alt"))
    end
  end
end

#literal_attrs(node) ⇒ Object



46
47
48
# File 'lib/asciidoctor/standoc/blocks.rb', line 46

def literal_attrs(node)
  attr_code(id_attr(node))
end

#note(n) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/asciidoctor/standoc/blocks.rb', line 108

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

#note_attr(node) ⇒ Object



29
30
31
32
33
# File 'lib/asciidoctor/standoc/blocks.rb', line 29

def note_attr(node)
  attr_code(id_attr(node).merge(
    "keep-separate": node.attr("keep-separate"),
    beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil))
end

#open(node) ⇒ Object

We append each contained block to its parent



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

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

#para_attrs(node) ⇒ Object



196
197
198
# File 'lib/asciidoctor/standoc/blocks.rb', line 196

def para_attrs(node)
  attr_code(align: node.attr("align"), id: Utils::anchor_or_uuid(node))
end

#paragraph(node) ⇒ Object



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

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



252
253
254
255
256
257
258
# File 'lib/asciidoctor/standoc/blocks.rb', line 252

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

#pseudocode_example(node) ⇒ Object



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

def pseudocode_example(node)
  # prevent A's and other subs inappropriate for pseudocode
  node.blocks.each { |b| b.remove_sub(:replacements) }
  noko do |xml|
    xml.figure **id_unnum_attr(node).merge(class: "pseudocode") do |ex|
      figure_title(node, ex)
      wrap_in_para(node, ex)
    end
  end.join("\n")
end

#quote(node) ⇒ Object



224
225
226
227
228
229
230
231
# File 'lib/asciidoctor/standoc/blocks.rb', line 224

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



213
214
215
216
217
218
219
220
221
222
# File 'lib/asciidoctor/standoc/blocks.rb', line 213

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



209
210
211
# File 'lib/asciidoctor/standoc/blocks.rb', line 209

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

#req_classif_parse(classif) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/asciidoctor/standoc/reqt.rb', line 19

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_attributes(node) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/asciidoctor/standoc/reqt.rb', line 38

def reqt_attributes(node)
  {
    id: Utils::anchor_or_uuid(node),
    unnumbered: node.option?("unnumbered") ? "true" : nil,
    subsequence: node.attr("subsequence"),
    obligation: node.attr("obligation"),
    filename: node.attr("filename"),
    type: node.attr("type"),
    model: node.attr("model"),
  }
end

#requirement(node, obligation) ⇒ Object



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

def requirement(node, obligation)
  classif = node.attr("classification")
  noko do |xml|
    xml.send obligation, **attr_code(reqt_attributes(node)) do |ex|
      node.title and ex.title { |t| t << node.title }
      node.attr("label") and ex.label { |l| l << node.attr("label") }
      node.attr("subject") and ex.subject { |s| s << node.attr("subject") }
      i = HTMLEntities.new.decode(node.attr("inherit"))
      i&.split(/;\s*/)&.each do |i|
        ex.inherit { |inh| inh << i }
      end
      requirement_classification(classif, ex) if classif
      wrap_in_para(node, ex)
    end
  end.join("\n")
end

#requirement_classification(classif, ex) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/asciidoctor/standoc/reqt.rb', line 29

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

#requirement_subpart(node) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/asciidoctor/standoc/reqt.rb', line 9

def requirement_subpart(node)
  name = node.role || node.attr("style")
  noko do |xml|
    xml.send name, **attr_code(exclude: node.option?("exclude"),
                               type: node.attr("type")) do |o|
      o << node.content
    end
  end
end


74
75
76
77
78
79
80
81
# File 'lib/asciidoctor/standoc/blocks.rb', line 74

def sidebar(node)
  return unless draft?
  noko do |xml|
    xml.review **(sidebar_attrs(node)) do |r|
      wrap_in_para(node, r)
    end
  end
end


69
70
71
72
# File 'lib/asciidoctor/standoc/blocks.rb', line 69

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



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

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

#term_example(node) ⇒ Object



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

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(n) ⇒ Object



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

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

#termnote_attr(node) ⇒ Object



24
25
26
27
# File 'lib/asciidoctor/standoc/blocks.rb', line 24

def termnote_attr(node)
  attr_code(id_attr(node).merge(
    "keep-separate": node.attr("keep-separate")))
end

#todo(node) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/asciidoctor/standoc/blocks.rb', line 92

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



83
84
85
86
87
88
89
90
# File 'lib/asciidoctor/standoc/blocks.rb', line 83

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