Module: Asciidoctor::Standoc::Blocks

Included in:
Converter
Defined in:
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



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

def admonition_attrs(node)
  name = node.attr("name")
  if type = node.attr("type")
    ["danger", "safety precautions"].each do |t|
      name = t if type.casecmp(t).zero?
    end
  end
  { id: Utils::anchor_or_uuid(node), type: name }
end

#datauri(uri) ⇒ Object



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

def datauri(uri)
  types = MIME::Types.type_for(@localdir + uri)
  type = types ? types.first.to_s : 'text/plain; charset="utf-8"'
  bin = File.open(@localdir + uri, 'rb') {|io| io.read}
  data = Base64.strict_encode64(bin)
  "data:#{type};base64,#{data}"
end

#example(node) ⇒ Object



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

def example(node)
  return term_example(node) if in_terms?
  return requirement(node, "recommendation") if node.attr("style") == "recommendation"
  return requirement(node, "requirement") if node.attr("style") == "requirement"
  return requirement(node, "permission") if node.attr("style") == "permission"
  noko do |xml|
    xml.example **id_attr(node) do |ex|
      wrap_in_para(node, ex)
    end
  end.join("\n")
end

#figure_title(node, f) ⇒ Object



228
229
230
231
232
# File 'lib/asciidoctor/standoc/blocks.rb', line 228

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

#id_attr(node = nil) ⇒ Object



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

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

#image(node) ⇒ Object



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

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

#image_attributes(node) ⇒ Object



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

def image_attributes(node)
  uri = node.image_uri (node.attr("target") || node.target)
  types = MIME::Types.type_for(uri)
  { src: @datauriimage ? datauri(uri) : uri,
    id: Utils::anchor_or_uuid,
    imagetype: types.first.sub_type.upcase,
    height: node.attr("height") || "auto",
    width: node.attr("width") || "auto" ,
    filename: node.attr("filename"),
    alt: node.alt == node.attr("default-alt") ? nil : node.alt }
end

#inline_image(node) ⇒ Object



243
244
245
246
247
# File 'lib/asciidoctor/standoc/blocks.rb', line 243

def inline_image(node)
  noko do |xml|
    xml.image **attr_code(image_attributes(node))
  end.join("")
end

#listing(node) ⇒ Object

NOTE: html escaping is performed by Nokogiri



294
295
296
297
298
299
300
301
302
303
# File 'lib/asciidoctor/standoc/blocks.rb', line 294

def listing(node)
  fragment = ::Nokogiri::XML::Builder.new do |xml|
    xml.sourcecode **attr_code(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



285
286
287
288
289
290
291
# File 'lib/asciidoctor/standoc/blocks.rb', line 285

def listing_attrs(node)
  {
    lang: node.attr("language"),
    id: Utils::anchor_or_uuid(node),
    filename: node.attr("filename")
  }
end

#literal(node) ⇒ Object



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

def literal(node)
  noko do |xml|
    xml.figure **id_attr(node) do |f|
      figure_title(node, f)
      f.pre node.lines.join("\n"), **{ id: Utils::anchor_or_uuid }
    end
  end
end

#note(n) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/asciidoctor/standoc/blocks.rb', line 102

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

#open(node) ⇒ Object

open block is a container of multiple blocks, treated as a single block. We append each contained block to its parent



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

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

#paragraph(node) ⇒ Object



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

def paragraph(node)
  return termsource(node) if node.role == "source"
  attrs = { align: node.attr("align"),
            id: Utils::anchor_or_uuid(node) }
  noko do |xml|
    xml.p **attr_code(attrs) do |xml_t|
      xml_t << node.content
    end
  end.join("\n")
end

#pass(node) ⇒ Object



305
306
307
# File 'lib/asciidoctor/standoc/blocks.rb', line 305

def pass(node)
  node.content
end

#preamble(node) ⇒ Object



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

def preamble(node)
  noko do |xml|
    xml.foreword do |xml_abstract|
      xml_abstract.title { |t| t << (node.blocks[0].title || "Foreword") }
      content = node.content
      xml_abstract << content
    end
  end.join("\n")
end

#quote(node) ⇒ Object



276
277
278
279
280
281
282
283
# File 'lib/asciidoctor/standoc/blocks.rb', line 276

def quote(node)
  noko do |xml|
    xml.quote **attr_code(quote_attrs(node)) do |q|
      quote_attribution(node, q)
      wrap_in_para(node, q)
    end
  end
end

#quote_attribution(node, out) ⇒ Object



265
266
267
268
269
270
271
272
273
274
# File 'lib/asciidoctor/standoc/blocks.rb', line 265

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

#quote_attrs(node) ⇒ Object



261
262
263
# File 'lib/asciidoctor/standoc/blocks.rb', line 261

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

#req_classif_parse(classif) ⇒ Object



157
158
159
160
161
162
163
164
165
# File 'lib/asciidoctor/standoc/blocks.rb', line 157

def req_classif_parse(classif)
  ret = []
  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



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

def reqt_attributes(node)
  {
    id: Utils::anchor_or_uuid,
    obligation: node.attr("obligation"),
    filename: node.attr("filename")
  }
end

#requirement(node, obligation) ⇒ Object



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

def requirement(node, obligation)
  classif = node.attr("classification")
  noko do |xml|
    xml.send obligation, **attr_code(reqt_attributes(node)) do |ex|
      ex.title node.title if node.title
      ex.label node.attr("label") if node.attr("label")
      ex.subject node.attr("subject") if node.attr("subject")
      ex.inherit node.attr("inherit") if node.attr("inherit")
      requirement_classification(classif, ex) if classif
      wrap_in_para(node, ex)
    end
  end.join("\n")
end

#requirement_classification(classif, ex) ⇒ Object



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

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

#requirement_subpart(node) ⇒ Object



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

def requirement_subpart(node)
  name = 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.join("\n")
end


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

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


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/asciidoctor/standoc/blocks.rb', line 55

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

#stem(node) ⇒ Object

NOTE: html escaping is performed by Nokogiri



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

def stem(node)
  stem_content = node.lines.join("\n")
  noko do |xml|
    xml.formula **id_attr(node) do |s|
      stem_parse(stem_content, 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



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

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

#todo(node) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/asciidoctor/standoc/blocks.rb', line 86

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

#todo_attrs(node) ⇒ Object



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

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