Module: IsoDoc::Function::Blocks

Included in:
Common
Defined in:
lib/isodoc/function/reqt.rb,
lib/isodoc/function/blocks.rb,
lib/isodoc/function/blocks_example_note.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
EXAMPLE_TD_ATTR =
{ style: "vertical-align:top;padding:0;", class: "example" }.freeze

Instance Method Summary collapse

Instance Method Details

#admonition_attrs(node) ⇒ Object



133
134
135
136
# File 'lib/isodoc/function/blocks_example_note.rb', line 133

def admonition_attrs(node)
  attr_code(id: node["id"], class: admonition_class(node),
            style: keep_style(node), coverpage: node["coverpage"])
end

#admonition_class(_node) ⇒ Object



125
126
127
# File 'lib/isodoc/function/blocks_example_note.rb', line 125

def admonition_class(_node)
  "Admonition"
end

#admonition_name(node, _type) ⇒ Object



129
130
131
# File 'lib/isodoc/function/blocks_example_note.rb', line 129

def admonition_name(node, _type)
  node&.at(ns("./name"))
end

#admonition_name_parse(_node, div, name) ⇒ Object



119
120
121
122
123
# File 'lib/isodoc/function/blocks_example_note.rb', line 119

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



138
139
140
141
142
143
144
145
# File 'lib/isodoc/function/blocks_example_note.rb', line 138

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

#annotation_parse(node, out) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/isodoc/function/blocks.rb', line 97

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

#div_parse(node, out) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/isodoc/function/reqt.rb', line 41

def div_parse(node, out)
  out.div **reqt_attrs(node, node["type"]) do |t|
    node.children.each do |n|
      parse(n, t)
    end
  end
end

#example_div_attr(node) ⇒ Object



16
17
18
# File 'lib/isodoc/function/blocks_example_note.rb', line 16

def example_div_attr(node)
  attr_code(id: node["id"], class: "example", style: keep_style(node))
end

#example_div_parse(node, out) ⇒ Object

used if we are boxing examples



21
22
23
24
25
26
27
28
# File 'lib/isodoc/function/blocks_example_note.rb', line 21

def example_div_parse(node, out)
  out.div **example_div_attr(node) do |div|
    example_label(node, div, node.at(ns("./name")))
    node.children.each do |n|
      parse(n, div) unless n.name == "name"
    end
  end
end

#example_label(_node, div, name) ⇒ Object



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

def example_label(_node, div, name)
  return if name.nil?

  div.p class: "example-title" do |_p|
    name.children.each { |n| parse(n, div) }
  end
end

#example_parse(node, out) ⇒ Object



52
53
54
# File 'lib/isodoc/function/blocks_example_note.rb', line 52

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

#example_table_attr(node) ⇒ Object



30
31
32
33
34
# File 'lib/isodoc/function/blocks_example_note.rb', line 30

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

#example_table_parse(node, out) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/isodoc/function/blocks_example_note.rb', line 39

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|
        example_label(node, td, node.at(ns("./name")))
      end
      tr.td **EXAMPLE_TD_ATTR do |td|
        node.children.each { |n| parse(n, td) unless n.name == "name" }
      end
    end
  end
end

#figure_attrs(node) ⇒ Object



25
26
27
# File 'lib/isodoc/function/blocks.rb', line 25

def figure_attrs(node)
  attr_code(id: node["id"], class: "figure", style: keep_style(node))
end

#figure_key(out) ⇒ Object



19
20
21
22
23
# File 'lib/isodoc/function/blocks.rb', line 19

def figure_key(out)
  out.p style: "page-break-after:avoid;" do |p|
    p.b { |b| b << @i18n.key }
  end
end

#figure_name_parse(_node, div, name) ⇒ Object



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

def figure_name_parse(_node, div, name)
  name.nil? and return
  div.p class: "FigureTitle", style: "text-align:center;" do |p|
    name.children.each { |n| parse(n, p) }
  end
end

#figure_parse(node, out) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/isodoc/function/blocks.rb', line 29

def figure_parse(node, out)
  return pseudocode_parse(node, out) if node["class"] == "pseudocode" ||
    node["type"] == "pseudocode"

  @in_figure = true
  figure_parse1(node, out)
  @in_figure = false
end

#figure_parse1(node, out) ⇒ Object



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

def figure_parse1(node, out)
  out.div **figure_attrs(node) 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, node.at(ns("./name")))
  end
end

#formula_attrs(node) ⇒ Object



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

def formula_attrs(node)
  attr_code(id: node["id"], style: keep_style(node))
end

#formula_parse(node, out) ⇒ Object



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

def formula_parse(node, out)
  out.div **formula_attrs(node) do |div|
    formula_parse1(node, div)
    node.children.each do |n|
      next if %w(stem name).include? n.name

      parse(n, div)
    end
  end
end

#formula_parse1(node, out) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/isodoc/function/blocks.rb', line 112

def formula_parse1(node, out)
  out.div **attr_code(class: "formula") do |div|
    div.p do |_p|
      parse(node.at(ns("./stem")), div)
      if lbl = node&.at(ns("./name"))&.text
        insert_tab(div, 1)
        div << "(#{lbl})"
      end
    end
  end
end

#keep_style(node) ⇒ Object



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

def keep_style(node)
  ret = ""
  node["keep-with-next"] == "true" and
    ret += "page-break-after: avoid;"
  node["keep-lines-together"] == "true" and
    ret += "page-break-inside: avoid;"
  return nil if ret.empty?

  ret
end

#middle_admonitions(isoxml, out) ⇒ Object



113
114
115
116
117
# File 'lib/isodoc/function/blocks_example_note.rb', line 113

def middle_admonitions(isoxml, out)
  isoxml.xpath(ns("//sections/note | //sections/admonition")).each do |x|
    parse(x, out)
  end
end

#middle_title(_isoxml, out) ⇒ Object



8
9
10
# File 'lib/isodoc/function/blocks.rb', line 8

def middle_title(_isoxml, out)
  out.p(class: "zzSTDTitle1") { |p| p << @meta.get[:doctitle] }
end

#note_attrs(node) ⇒ Object



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

def note_attrs(node)
  attr_code(id: node["id"], class: "Note", style: keep_style(node),
            coverpage: node["coverpage"])
end

#note_delimObject



56
57
58
# File 'lib/isodoc/function/blocks_example_note.rb', line 56

def note_delim
  ""
end

#note_p_parse(node, div) ⇒ Object



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

def note_p_parse(node, div)
  name = node&.at(ns("./name"))&.remove
  div.p do |p|
    name and p.span class: "note_label" do |s|
      name.children.each { |n| parse(n, s) }
      s << note_delim
    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



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

def note_parse(node, out)
  @note = true
  out.div **note_attrs(node) do |div|
    if node&.at(ns("./*[local-name() != 'name'][1]"))&.name == "p"
      note_p_parse(node, div)
    else
      note_parse1(node, div)
    end
  end
  @note = false
end

#note_parse1(node, div) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/isodoc/function/blocks_example_note.rb', line 73

def note_parse1(node, div)
  name = node&.at(ns("./name"))&.remove
  name and div.p do |p|
    p.span class: "note_label" do |s|
      name.children.each { |n| parse(n, s) }
      s << note_delim
    end
    insert_tab(p, 1)
  end
  node.children.each { |n| parse(n, div) }
end

#para_attrs(node) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/isodoc/function/blocks.rb', line 149

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

#para_class(node) ⇒ Object



139
140
141
142
143
144
145
146
147
# File 'lib/isodoc/function/blocks.rb', line 139

def para_class(node)
  classtype = nil
  classtype = "MsoCommentText" if in_comment
  classtype = "Sourcecode" if @annotation
  if node["type"] == "floating-title"
    classtype = "h#{node['depth']}"
  end
  classtype
end

#para_parse(node, out) ⇒ Object



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

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

#passthrough_parse(node, out) ⇒ Object



190
191
192
193
194
195
# File 'lib/isodoc/function/blocks.rb', line 190

def passthrough_parse(node, out)
  return if node["format"] &&
    !(node["format"].split(",").include? @format.to_s)

  out.passthrough node.text
end

#permission_parse(node, out) ⇒ Object



35
36
37
38
39
# File 'lib/isodoc/function/reqt.rb', line 35

def permission_parse(node, out)
  out.div **reqt_attrs(node, "permission") do |t|
    recommendation_parse1(node, t)
  end
end

#pre_parse(node, out) ⇒ Object



93
94
95
# File 'lib/isodoc/function/blocks.rb', line 93

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

#pseudocode_attrs(node) ⇒ Object



48
49
50
# File 'lib/isodoc/function/blocks.rb', line 48

def pseudocode_attrs(node)
  attr_code(id: node["id"], class: "pseudocode", style: keep_style(node))
end

#pseudocode_parse(node, out) ⇒ Object



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

def pseudocode_parse(node, out)
  @in_figure = true
  name = node.at(ns("./name"))
  out.div **pseudocode_attrs(node) do |div|
    node.children.each { |n| parse(n, div) unless n.name == "name" }
    sourcecode_name_parse(node, div, name)
  end
  @in_figure = false
end

#quote_attribution(node, out) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
# File 'lib/isodoc/function/blocks.rb', line 167

def quote_attribution(node, out)
  author = node.at(ns("./author"))
  source = node.at(ns("./source"))
  return if author.nil? && source.nil?

  out.p class: "QuoteAttribution" do |p|
    p << "&#x2014; #{author.text}" if author
    p << ", " if author && source
    eref_parse(source, p) if source
  end
end

#quote_parse(node, out) ⇒ Object



179
180
181
182
183
184
185
186
187
188
# File 'lib/isodoc/function/blocks.rb', line 179

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 %w(author source).include? n.name
    end
    quote_attribution(node, out)
  end
end

#recommendation_name(name, out) ⇒ Object



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

def recommendation_name(name, out)
  return if name.nil?

  out.p **{ class: "RecommendationTitle" } do |p|
    name.children.each { |n| parse(n, p) }
  end
end

#recommendation_parse(node, out) ⇒ Object



16
17
18
19
20
# File 'lib/isodoc/function/reqt.rb', line 16

def recommendation_parse(node, out)
  out.div **reqt_attrs(node, "recommend") do |t|
    recommendation_parse1(node, t)
  end
end

#recommendation_parse1(node, out) ⇒ Object



22
23
24
25
26
27
# File 'lib/isodoc/function/reqt.rb', line 22

def recommendation_parse1(node, out)
  recommendation_name(node.at(ns("./name")), out)
  node.children.each do |n|
    parse(n, out) unless n.name == "name"
  end
end

#reqt_attrs(node, klass) ⇒ Object



12
13
14
# File 'lib/isodoc/function/reqt.rb', line 12

def reqt_attrs(node, klass)
  attr_code(class: klass, id: node["id"], style: keep_style(node))
end

#requirement_parse(node, out) ⇒ Object



29
30
31
32
33
# File 'lib/isodoc/function/reqt.rb', line 29

def requirement_parse(node, out)
  out.div **reqt_attrs(node, "require") do |t|
    recommendation_parse1(node, t)
  end
end

#sourcecode_attrs(node) ⇒ Object



70
71
72
# File 'lib/isodoc/function/blocks.rb', line 70

def sourcecode_attrs(node)
  attr_code(id: node["id"], class: "Sourcecode", style: keep_style(node))
end

#sourcecode_name_parse(_node, div, name) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/isodoc/function/blocks.rb', line 62

def sourcecode_name_parse(_node, div, name)
  return if name.nil?

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

#sourcecode_parse(node, out) ⇒ Object



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

def sourcecode_parse(node, out)
  name = node.at(ns("./name"))
  out.p **sourcecode_attrs(node) do |div|
    sourcecode_parse1(node, div)
  end
  sourcecode_name_parse(node, out, name)
end

#sourcecode_parse1(node, div) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/isodoc/function/blocks.rb', line 82

def sourcecode_parse1(node, div)
  @sourcecode = "pre"
  node.at(ns(".//table[@class = 'rouge-line-table']")) ||
    node.at("./ancestor::xmlns:table[@class = 'rouge-line-table']") and
    @sourcecode = "table"
  # !node.ancestors("table").empty? and
  # @sourcecode = "table"
  node.children.each { |n| parse(n, div) unless n.name == "name" }
  @sourcecode = false
end

#svg_parse(node, out) ⇒ Object



197
198
199
# File 'lib/isodoc/function/blocks.rb', line 197

def svg_parse(node, out)
  out.parent.add_child(node)
end

#toc_parse(node, out) ⇒ Object



201
202
203
204
205
# File 'lib/isodoc/function/blocks.rb', line 201

def toc_parse(node, out)
  out.div class: "toc" do |div|
    node.children.each { |n| parse(n, div) }
  end
end