Module: IsoDoc::Function::Blocks

Included in:
Common
Defined in:
lib/isodoc/function/reqt.rb,
lib/isodoc/function/blocks.rb

Constant Summary collapse

EXAMPLE_TBL_ATTR =
{ class: "example_label", style: "width:82.8pt;padding:0 0 0 0;\
margin-left:0pt;vertical-align:top;" }.freeze

Instance Method Summary collapse

Instance Method Details

#admonition_class(node) ⇒ Object



160
161
162
# File 'lib/isodoc/function/blocks.rb', line 160

def admonition_class(node)
  "Admonition"
end

#admonition_name(node, type) ⇒ Object



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

def admonition_name(node, type)
  name = node&.at(ns("./name")) and return name
  name = Nokogiri::XML::Node.new('name', node.document)
  return unless type && @admonition[type]
  name << @admonition[type]&.upcase
  name
end

#admonition_name_parse(_node, div, name) ⇒ Object



124
125
126
127
128
# File 'lib/isodoc/function/blocks.rb', line 124

def admonition_name_parse(_node, div, name)
  div.p **{ class: "AdmonitionTitle", style: "text-align:center;" } do |p|
    name.children.each { |n| parse(n, p) }
  end
end

#admonition_parse(node, out) ⇒ Object



172
173
174
175
176
177
178
179
180
181
# File 'lib/isodoc/function/blocks.rb', line 172

def admonition_parse(node, out)
  type = node["type"]
  name = admonition_name(node, type)
  out.div **{ class: admonition_class(node) } do |t|
    admonition_name_parse(node, t, name) if name
    node.children.each do |n|
      parse(n, t) unless n.name == "name"
    end
  end
end

#annotation_parse(node, out) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/isodoc/function/blocks.rb', line 146

def annotation_parse(node, out)
  @sourcecode = false
  @annotation = true
  node.at("./preceding-sibling::*[local-name() = 'annotation']") or
    out << "<br/>"
  out << "<br/>"
  #out.span **{ class: "zzMoveToFollowing" } do |s|
  out  << "&lt;#{node.at(ns("//callout[@target='#{node['id']}']")).text}&gt; "
  #end
  #node.children.each { |n| parse(n, out) }
  out << node&.children&.text&.strip
  @annotation = false
end

#example_div_parse(node, out) ⇒ Object

used if we are boxing examples



85
86
87
88
89
90
91
92
93
94
# File 'lib/isodoc/function/blocks.rb', line 85

def example_div_parse(node, out)
  out.div **attr_code(id: node["id"], class: "example") do |div|
    div.p **{ class: "example-title" } do |p|
      p << example_label(node)
    end
    node.children.each do |n|
      parse(n, div)
    end
  end
end

#example_label(node) ⇒ Object



73
74
75
76
77
# File 'lib/isodoc/function/blocks.rb', line 73

def example_label(node)
  n = get_anchors[node["id"]]
  return @example_lbl if n.nil? || n[:label].nil? || n[:label].empty?
  l10n("#{@example_lbl} #{n[:label]}")
end

#example_parse(node, out) ⇒ Object



114
115
116
# File 'lib/isodoc/function/blocks.rb', line 114

def example_parse(node, out)
  example_div_parse(node, out)
end

#example_table_attr(node) ⇒ Object



96
97
98
99
# File 'lib/isodoc/function/blocks.rb', line 96

def example_table_attr(node)
  attr_code(id: node["id"], class: "example",
            style: "border-collapse:collapse;border-spacing:0;" )
end

#example_table_parse(node, out) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/isodoc/function/blocks.rb', line 101

def example_table_parse(node, out)
  out.table **example_table_attr(node) do |t|
    t.tr do |tr|
      tr.td **EXAMPLE_TBL_ATTR do |td|
        td << example_label(node)
      end
      tr.td **{ style: "vertical-align:top;padding:0;", class: "example" } do |td|
        node.children.each { |n| parse(n, td) }
      end
    end
  end
end

#figure_key(out) ⇒ Object



54
55
56
57
58
# File 'lib/isodoc/function/blocks.rb', line 54

def figure_key(out)
  out.p do |p|
    p.b { |b| b << @key_lbl }
  end
end

#figure_name_parse(node, div, name) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/isodoc/function/blocks.rb', line 44

def figure_name_parse(node, div, name)
  return if name.nil? && node.at(ns("./figure"))
  div.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
    lbl = anchor(node['id'], :label, false)
    lbl.nil? or p << l10n("#{@figure_lbl} #{lbl}")
    name and !lbl.nil? and p << "&nbsp;&mdash; "
    name and name.children.each { |n| parse(n, div) }
  end
end

#figure_parse(node, out) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/isodoc/function/blocks.rb', line 60

def figure_parse(node, out)
  @in_figure = true
  name = node.at(ns("./name"))
  out.div **attr_code(id: node["id"], class: "figure") do |div|
    node.children.each do |n|
      figure_key(out) if n.name == "dl"
      parse(n, div) unless n.name == "name"
    end
    figure_name_parse(node, div, name)
  end
  @in_figure = false
end

#formula_parse(node, out) ⇒ Object



202
203
204
205
206
207
208
209
# File 'lib/isodoc/function/blocks.rb', line 202

def formula_parse(node, out)
  formula_parse1(node, out)
  formula_where(node.at(ns("./dl")), out)
  node.children.each do |n|
    next if %w(stem dl).include? n.name
    parse(n, out)
  end
end

#formula_parse1(node, out) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/isodoc/function/blocks.rb', line 189

def formula_parse1(node, out)
  out.div **attr_code(id: node["id"], class: "formula") do |div|
    div.p do |p|
      parse(node.at(ns("./stem")), div)
      lbl = anchor(node['id'], :label, false)
      unless lbl.nil?
        insert_tab(div, 1)
        div << "(#{lbl})"
      end
    end
  end
end

#formula_where(dl, out) ⇒ Object



183
184
185
186
187
# File 'lib/isodoc/function/blocks.rb', line 183

def formula_where(dl, out)
  return unless dl
  out.p { |p| p << @where_lbl }
  parse(dl, out)
end

#image_parse(node, out, caption) ⇒ Object



266
267
268
269
270
271
272
273
# File 'lib/isodoc/function/blocks.rb', line 266

def image_parse(node, out, caption)
  attrs = { src: node["src"],
            height: node["height"] || "auto",
            width: node["width"] || "auto",
            alt: node["alt"]  }
  out.img **attr_code(attrs)
  image_title_parse(out, caption)
end

#image_title_parse(out, caption) ⇒ Object



258
259
260
261
262
263
264
# File 'lib/isodoc/function/blocks.rb', line 258

def image_title_parse(out, caption)
  unless caption.nil?
    out.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
      p.b { |b| b << caption.to_s }
    end
  end
end

#note_label(node) ⇒ Object



5
6
7
8
9
# File 'lib/isodoc/function/blocks.rb', line 5

def note_label(node)
  n = get_anchors[node["id"]]
  return @note_lbl if n.nil? || n[:label].nil? || n[:label].empty?
  l10n("#{@note_lbl} #{n[:label]}")
end

#note_p_parse(node, div) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/isodoc/function/blocks.rb', line 11

def note_p_parse(node, div)
  div.p do |p|
    p.span **{ class: "note_label" } do |s|
      s << note_label(node)
    end
    insert_tab(p, 1)
    node.first_element_child.children.each { |n| parse(n, p) }
  end
  node.element_children[1..-1].each { |n| parse(n, div) }
end

#note_parse(node, out) ⇒ Object



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

def note_parse(node, out)
  @note = true
  out.div **{ id: node["id"], class: "Note" } do |div|
    if node.first_element_child.name == "p"
      note_p_parse(node, div)
    else
      note_parse1(node, div)
    end
  end
  @note = false
end

#note_parse1(node, div) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/isodoc/function/blocks.rb', line 22

def note_parse1(node, div)
  div.p do |p|
    p.span **{ class: "note_label" } do |s|
      s << note_label(node)
    end
    insert_tab(p, 1)
  end
  node.children.each { |n| parse(n, div) }
end

#para_attrs(node) ⇒ Object



218
219
220
221
222
223
224
225
# File 'lib/isodoc/function/blocks.rb', line 218

def para_attrs(node)
  attrs = { class: para_class(node), id: node["id"] }
  unless node["align"].nil?
    #attrs[:align] = node["align"] unless node["align"] == "justify"
    attrs[:style] = "text-align:#{node['align']};"
  end
  attrs
end

#para_class(_node) ⇒ Object



211
212
213
214
215
216
# File 'lib/isodoc/function/blocks.rb', line 211

def para_class(_node)
  classtype = nil
  classtype = "MsoCommentText" if in_comment
  classtype = "Sourcecode" if @annotation
  classtype
end

#para_parse(node, out) ⇒ Object



227
228
229
230
231
232
233
234
235
# File 'lib/isodoc/function/blocks.rb', line 227

def para_parse(node, out)
  out.p **attr_code(para_attrs(node)) do |p|
    unless @termdomain.empty?
      p << "&lt;#{@termdomain}&gt; "
      @termdomain = ""
    end
    node.children.each { |n| parse(n, p) }
  end
end

#permission_parse(node, out) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/isodoc/function/reqt.rb', line 67

def permission_parse(node, out)
  out.div **{ class: "permission" } do |t|
    recommendation_name(node, t, @permission_lbl)
    recommendation_attributes(node, out)
    node.children.each do |n|
      parse(n, t) unless %w(label title).include? n.name
    end
  end
end

#pre_parse(node, out) ⇒ Object



142
143
144
# File 'lib/isodoc/function/blocks.rb', line 142

def pre_parse(node, out)
  out.pre node.text, **attr_code(id: node["id"])
end

#quote_attribution(node, out) ⇒ Object



237
238
239
240
241
242
243
244
245
# File 'lib/isodoc/function/blocks.rb', line 237

def quote_attribution(node, out)
  author = node.at(ns("./author"))
  source = node.at(ns("./source"))
  out.p **{ class: "QuoteAttribution" } do |p|
    p << "&mdash; #{author.text}" if author
    p << ", " if author && source
    eref_parse(source, p) if source
  end
end

#quote_parse(node, out) ⇒ Object



247
248
249
250
251
252
253
254
255
256
# File 'lib/isodoc/function/blocks.rb', line 247

def quote_parse(node, out)
  attrs = para_attrs(node)
  attrs[:class] = "Quote"
  out.div **attr_code(attrs) do |p|
    node.children.each do |n|
      parse(n, p) unless ["author", "source"].include? n.name
    end
    quote_attribution(node, out)
  end
end

#recommendation_attributes(node, out) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/isodoc/function/reqt.rb', line 37

def recommendation_attributes(node, out)
  ret = recommendation_attributes1(node)
  return if ret.empty?
  out.p do |p|
    p.i do |i|
      i << ret.join("<br/>")
    end
  end
end

#recommendation_attributes1(node) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/isodoc/function/reqt.rb', line 24

def recommendation_attributes1(node) 
  out = [] 
  oblig = node["obligation"] and out << "Obligation: #{oblig}" 
  subj = node&.at(ns("./subject"))&.text and out << "Subject: #{subj}" 
  node.xpath(ns("./classification")).each do |c|
    tag = c.at(ns("./tag"))
    value = c.at(ns("./value"))
    tag && value or next
    out << "#{tag.text.capitalize}: #{value.text}"
  end
  out
end

#recommendation_labels(node) ⇒ Object



3
4
5
6
# File 'lib/isodoc/function/reqt.rb', line 3

def recommendation_labels(node)
  [node.at(ns("./label")), node.at(ns("./title")), 
   anchor(node['id'], :label, false)]
end

#recommendation_name(node, out, type) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/isodoc/function/reqt.rb', line 8

def recommendation_name(node, out, type)
  label, title, lbl = recommendation_labels(node)
  #label = node.at(ns("./label"))
  #title = node.at(ns("./title"))
  out.p **{ class: "AdmonitionTitle" }  do |b|
    #lbl = anchor(node['id'], :label, false)
    b << (lbl.nil? ? l10n("#{type}:") : l10n("#{type} #{lbl}:"))
    if label || title
      b.br
      label and label.children.each { |n| parse(n,b) }
      b << "#{clausedelim} " if label && title
      title and title.children.each { |n| parse(n,b) }
    end
  end
end

#recommendation_parse(node, out) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/isodoc/function/reqt.rb', line 47

def recommendation_parse(node, out)
  out.div **{ class: "recommend" } do |t|
    recommendation_name(node, t, @recommendation_lbl)
    recommendation_attributes(node, out)
    node.children.each do |n|
      parse(n, t) unless %w(label title).include? n.name
    end
  end
end

#requirement_component_parse(node, out) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/isodoc/function/reqt.rb', line 77

def requirement_component_parse(node, out)
  return if node["exclude"] == "true"
  out.div **{ class: "requirement-" + node.name } do |div|
    node.children.each do |n|
      parse(n, div)
    end
  end
end

#requirement_parse(node, out) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/isodoc/function/reqt.rb', line 57

def requirement_parse(node, out)
  out.div **{ class: "require" } do |t|
    recommendation_name(node, t, @requirement_lbl)
    recommendation_attributes(node, out)
    node.children.each do |n|
      parse(n, t) unless %w(label title).include? n.name
    end
  end
end

#requirement_skip_parse(node, out) ⇒ Object



86
87
# File 'lib/isodoc/function/reqt.rb', line 86

def requirement_skip_parse(node, out)
end

#sourcecode_name_parse(_node, div, name) ⇒ Object



118
119
120
121
122
# File 'lib/isodoc/function/blocks.rb', line 118

def sourcecode_name_parse(_node, div, name)
  div.p **{ class: "SourceTitle", style: "text-align:center;" } do |p|
    name.children.each { |n| parse(n, p) }
  end
end

#sourcecode_parse(node, out) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/isodoc/function/blocks.rb', line 130

def sourcecode_parse(node, out)
  name = node.at(ns("./name"))
  out.p **attr_code(id: node["id"], class: "Sourcecode") do |div|
    @sourcecode = true
    node.children.each do |n|
      parse(n, div) unless n.name == "name"
    end
    @sourcecode = false
    sourcecode_name_parse(node, div, name) if name
  end
end