Module: Asciidoctor::ISO::Blocks

Included in:
Converter
Defined in:
lib/asciidoctor/iso/blocks.rb

Instance Method Summary collapse

Instance Method Details

#admonition(node) ⇒ Object



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

def admonition(node)
  return termnote(node) if in_terms?
  return note(node) if node.attr("name") == "note"
  noko do |xml|
    xml.admonition **admonition_attrs(node) do |a|
      wrap_in_para(node, a)
    end
  end.join("\n")
end

#admonition_attrs(node) ⇒ Object



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

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

#example(node) ⇒ Object



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

def example(node)
  return term_example(node) if in_terms?
  noko do |xml|
    xml.example **id_attr(node) do |ex|
      content = node.content
      ex << content
    end
  end.join("\n")
end

#figure_title(node, f) ⇒ Object



131
132
133
134
135
# File 'lib/asciidoctor/iso/blocks.rb', line 131

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

#id_attr(node = nil) ⇒ Object



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

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

#image(node) ⇒ Object



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

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



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

def image_attributes(node)
  uri = node.image_uri node.attr("target")
  types = MIME::Types.type_for(uri)
  { src: uri,
    id: Utils::anchor_or_uuid,
    imagetype: types.first.sub_type.upcase,
    height: node.attr("height"),
    width: node.attr("width") }
end

#listing(node) ⇒ Object



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

def listing(node)
  # NOTE: html escaping is performed by Nokogiri
  noko do |xml|
    xml.sourcecode(**id_attr(node)) { |s| s << node.content }
    # xml.sourcecode(**id_attr(node)) { |s| s << node.lines.join("\n") }
  end
end

#literal(node) ⇒ Object



22
23
24
# File 'lib/asciidoctor/iso/blocks.rb', line 22

def literal(node)
  open(node)
end

#note(n) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/asciidoctor/iso/blocks.rb', line 65

def note(n)
  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



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

def open(node)
  result = []
  node.blocks.each do |b|
    result << send(b.context, b)
  end
  result
end

#paragraph(node) ⇒ Object



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

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

#preamble(node) ⇒ Object



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

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

#quote(node) ⇒ Object



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

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



161
162
163
164
165
166
167
168
169
170
# File 'lib/asciidoctor/iso/blocks.rb', line 161

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



157
158
159
# File 'lib/asciidoctor/iso/blocks.rb', line 157

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


48
49
50
51
52
53
54
55
# File 'lib/asciidoctor/iso/blocks.rb', line 48

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


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

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



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

def stem(node)
  stem_content = node.lines.join("\n")
  noko do |xml|
    xml.formula **id_attr(node) do |s|
      stem_parse(stem_content, s)
    end
  end
end

#term_example(node) ⇒ Object



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

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



57
58
59
60
61
62
63
# File 'lib/asciidoctor/iso/blocks.rb', line 57

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