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
- #admonition_attrs(node) ⇒ Object
- #admonition_class(node) ⇒ Object
- #admonition_name(node, type) ⇒ Object
- #admonition_name_parse(_node, div, name) ⇒ Object
- #admonition_parse(node, out) ⇒ Object
- #annotation_parse(node, out) ⇒ Object
- #example_div_attr(node) ⇒ Object
-
#example_div_parse(node, out) ⇒ Object
used if we are boxing examples.
- #example_label(node, div, name) ⇒ Object
- #example_parse(node, out) ⇒ Object
- #example_table_attr(node) ⇒ Object
- #example_table_parse(node, out) ⇒ Object
- #figure_attrs(node) ⇒ Object
- #figure_key(out) ⇒ Object
- #figure_name_parse(node, div, name) ⇒ Object
- #figure_parse(node, out) ⇒ Object
- #formula_attrs(node) ⇒ Object
- #formula_parse(node, out) ⇒ Object
- #formula_parse1(node, out) ⇒ Object
- #formula_where(dl, out) ⇒ Object
- #keep_style(node) ⇒ Object
- #note_attrs(node) ⇒ Object
- #note_label(node) ⇒ Object
- #note_p_parse(node, div) ⇒ Object
- #note_parse(node, out) ⇒ Object
- #note_parse1(node, div) ⇒ Object
- #para_attrs(node) ⇒ Object
- #para_class(_node) ⇒ Object
- #para_parse(node, out) ⇒ Object
- #passthrough_parse(node, out) ⇒ Object
- #permission_parse(node, out) ⇒ Object
- #pre_parse(node, out) ⇒ Object
- #pseudocode_attrs(node) ⇒ Object
- #pseudocode_parse(node, out) ⇒ Object
- #quote_attribution(node, out) ⇒ Object
- #quote_parse(node, out) ⇒ Object
- #recommendation_attr_keyvalue(node, key, value) ⇒ Object
- #recommendation_attr_parse(node, label) ⇒ Object
- #recommendation_attributes(node, out) ⇒ Object
- #recommendation_attributes1(node) ⇒ Object
- #recommendation_labels(node) ⇒ Object
- #recommendation_name(node, out, type) ⇒ Object
- #recommendation_parse(node, out) ⇒ Object
- #reqt_attrs(node, klass) ⇒ Object
- #reqt_component_attrs(node) ⇒ Object
- #reqt_metadata_node(n) ⇒ Object
- #requirement_component_parse(node, out) ⇒ Object
- #requirement_parse(node, out) ⇒ Object
- #requirement_skip_parse(node, out) ⇒ Object
- #sourcecode_attrs(node) ⇒ Object
- #sourcecode_name_parse(node, div, name) ⇒ Object
- #sourcecode_parse(node, out) ⇒ Object
Instance Method Details
#admonition_attrs(node) ⇒ Object
117 118 119 120 |
# File 'lib/isodoc/function/blocks.rb', line 117 def admonition_attrs(node) attr_code(id: node["id"], class: admonition_class(node), style: keep_style(node)) end |
#admonition_class(node) ⇒ Object
105 106 107 |
# File 'lib/isodoc/function/blocks.rb', line 105 def admonition_class(node) "Admonition" end |
#admonition_name(node, type) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/isodoc/function/blocks.rb', line 109 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
70 71 72 73 74 |
# File 'lib/isodoc/function/blocks.rb', line 70 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
122 123 124 125 126 127 128 129 |
# File 'lib/isodoc/function/blocks.rb', line 122 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
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/isodoc/function/blocks.rb', line 94 def annotation_parse(node, out) @sourcecode = false @annotation = true node.at("./preceding-sibling::*[local-name() = 'annotation']") or out << "<br/>" callout = node.at(ns("//callout[@target='#{node['id']}']")) out << "<br/><#{callout.text}> " out << node&.children&.text&.strip @annotation = false end |
#example_div_attr(node) ⇒ Object
18 19 20 |
# File 'lib/isodoc/function/blocks_example_note.rb', line 18 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
23 24 25 26 27 28 29 30 |
# File 'lib/isodoc/function/blocks_example_note.rb', line 23 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
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/isodoc/function/blocks_example_note.rb', line 3 def example_label(node, div, name) n = @xrefs.get[node["id"]] div.p **{ class: "example-title" } do |p| lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @example_lbl : l10n("#{@example_lbl} #{n[:label]}") p << lbl name and !lbl.nil? and p << " — " name and name.children.each { |n| parse(n, div) } end end |
#example_parse(node, out) ⇒ Object
54 55 56 |
# File 'lib/isodoc/function/blocks_example_note.rb', line 54 def example_parse(node, out) example_div_parse(node, out) end |
#example_table_attr(node) ⇒ Object
32 33 34 35 36 |
# File 'lib/isodoc/function/blocks_example_note.rb', line 32 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
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/isodoc/function/blocks_example_note.rb', line 41 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 << @key_lbl } end end |
#figure_name_parse(node, div, name) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/isodoc/function/blocks.rb', line 7 def figure_name_parse(node, div, name) return if name.nil? && node.at(ns("./figure")) lbl = @xrefs.anchor(node['id'], :label, false) lbl = nil if labelled_ancestor(node) && node.ancestors("figure").empty? return if lbl.nil? && name.nil? div.p **{ class: "FigureTitle", style: "text-align:center;" } do |p| lbl.nil? or p << l10n("#{@figure_lbl} #{lbl}") name and !lbl.nil? and p << " — " name and name.children.each { |n| parse(n, div) } end end |
#figure_parse(node, out) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 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 @in_figure = false end |
#formula_attrs(node) ⇒ Object
153 154 155 |
# File 'lib/isodoc/function/blocks.rb', line 153 def formula_attrs(node) attr_code(id: node["id"], style: keep_style(node)) end |
#formula_parse(node, out) ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/isodoc/function/blocks.rb', line 157 def formula_parse(node, out) out.div **formula_attrs(node) do |div| formula_parse1(node, div) formula_where(node.at(ns("./dl")), div) node.children.each do |n| next if %w(stem dl).include? n.name parse(n, div) end end end |
#formula_parse1(node, out) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/isodoc/function/blocks.rb', line 140 def formula_parse1(node, out) out.div **attr_code(class: "formula") do |div| div.p do |p| parse(node.at(ns("./stem")), div) lbl = @xrefs.anchor(node['id'], :label, false) unless lbl.nil? insert_tab(div, 1) div << "(#{lbl})" end end end end |
#formula_where(dl, out) ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/isodoc/function/blocks.rb', line 131 def formula_where(dl, out) return unless dl out.p **{ style: "page-break-after:avoid;"} do |p| p << @where_lbl end parse(dl, out) out.parent.at("./dl")["class"] = "formula_dl" end |
#keep_style(node) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# 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 |
#note_attrs(node) ⇒ Object
95 96 97 |
# File 'lib/isodoc/function/blocks_example_note.rb', line 95 def note_attrs(node) attr_code(id: node["id"], class: "Note", style: keep_style(node)) end |
#note_label(node) ⇒ Object
58 59 60 61 62 |
# File 'lib/isodoc/function/blocks_example_note.rb', line 58 def note_label(node) n = @xrefs.get[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
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/isodoc/function/blocks_example_note.rb', line 64 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
99 100 101 102 103 104 105 106 |
# File 'lib/isodoc/function/blocks_example_note.rb', line 99 def note_parse(node, out) @note = true out.div **note_attrs(node) do |div| node.first_element_child.name == "p" ? note_p_parse(node, div) : note_parse1(node, div) end @note = false end |
#note_parse1(node, div) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/isodoc/function/blocks_example_note.rb', line 75 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
175 176 177 178 179 180 181 |
# File 'lib/isodoc/function/blocks.rb', line 175 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
168 169 170 171 172 173 |
# File 'lib/isodoc/function/blocks.rb', line 168 def para_class(_node) classtype = nil classtype = "MsoCommentText" if in_comment classtype = "Sourcecode" if @annotation classtype end |
#para_parse(node, out) ⇒ Object
183 184 185 186 187 188 189 190 191 |
# File 'lib/isodoc/function/blocks.rb', line 183 def para_parse(node, out) out.p **attr_code(para_attrs(node)) do |p| unless @termdomain.empty? p << "<#{@termdomain}> " @termdomain = "" end node.children.each { |n| parse(n, p) } end end |
#passthrough_parse(node, out) ⇒ Object
214 215 216 217 218 |
# File 'lib/isodoc/function/blocks.rb', line 214 def passthrough_parse(node, out) return if node["format"] and !(node["format"].split(/,/).include? @format.to_s) out.passthrough node.text end |
#permission_parse(node, out) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/isodoc/function/reqt.rb', line 87 def (node, out) out.div **reqt_attrs(node, "permission") do |t| recommendation_name(node, t, @permission_lbl) recommendation_attributes(node, out) node.children.each do |n| parse(n, t) unless (n) end end end |
#pre_parse(node, out) ⇒ Object
90 91 92 |
# File 'lib/isodoc/function/blocks.rb', line 90 def pre_parse(node, out) out.pre node.text, **attr_code(id: node["id"]) end |
#pseudocode_attrs(node) ⇒ Object
43 44 45 |
# File 'lib/isodoc/function/blocks.rb', line 43 def pseudocode_attrs(node) attr_code(id: node["id"], class: "pseudocode", style: keep_style(node)) end |
#pseudocode_parse(node, out) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/isodoc/function/blocks.rb', line 47 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
193 194 195 196 197 198 199 200 201 |
# File 'lib/isodoc/function/blocks.rb', line 193 def quote_attribution(node, out) = node.at(ns("./author")) source = node.at(ns("./source")) out.p **{ class: "QuoteAttribution" } do |p| p << "— #{.text}" if p << ", " if && source eref_parse(source, p) if source end end |
#quote_parse(node, out) ⇒ Object
203 204 205 206 207 208 209 210 211 212 |
# File 'lib/isodoc/function/blocks.rb', line 203 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_attr_keyvalue(node, key, value) ⇒ Object
43 44 45 46 47 |
# File 'lib/isodoc/function/reqt.rb', line 43 def recommendation_attr_keyvalue(node, key, value) tag = node.at(ns("./#{key}")) or return nil value = node.at(ns("./#{value}")) or return nil "#{tag.text.capitalize}: #{value.text}" end |
#recommendation_attr_parse(node, label) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/isodoc/function/reqt.rb', line 36 def recommendation_attr_parse(node, label) noko do |xml| xml << "#{label}: " node.children.each { |n| parse(n, xml) } end.join end |
#recommendation_attributes(node, out) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/isodoc/function/reqt.rb', line 49 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/isodoc/function/reqt.rb', line 21 def recommendation_attributes1(node) out = [] oblig = node["obligation"] and out << l10n("#{@labels['obligation']}: #{oblig}") subj = node&.at(ns("./subject"))&.text and out << l10n("#{@labels['subject']}: #{subj}") node.xpath(ns("./inherit")).each do |i| out << recommendation_attr_parse(i, @labels["inherits"]) end node.xpath(ns("./classification")).each do |c| line = recommendation_attr_keyvalue(c, "tag", "value") and out << line 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")), @xrefs.anchor(node['id'], :label, false)] end |
#recommendation_name(node, out, type) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/isodoc/function/reqt.rb', line 8 def recommendation_name(node, out, type) label, title, lbl = recommendation_labels(node) out.p **{ class: "RecommendationTitle" } do |b| 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
67 68 69 70 71 72 73 74 75 |
# File 'lib/isodoc/function/reqt.rb', line 67 def recommendation_parse(node, out) out.div **reqt_attrs(node, "recommend") do |t| recommendation_name(node, t, @recommendation_lbl) recommendation_attributes(node, out) node.children.each do |n| parse(n, t) unless (n) end end end |
#reqt_attrs(node, klass) ⇒ Object
63 64 65 |
# File 'lib/isodoc/function/reqt.rb', line 63 def reqt_attrs(node, klass) attr_code(class: klass, id: node["id"], style: keep_style(node)) end |
#reqt_component_attrs(node) ⇒ Object
97 98 99 100 |
# File 'lib/isodoc/function/reqt.rb', line 97 def reqt_component_attrs(node) attr_code(class: "requirement-" + node.name, style: keep_style(node)) end |
#reqt_metadata_node(n) ⇒ Object
59 60 61 |
# File 'lib/isodoc/function/reqt.rb', line 59 def (n) %w(label title subject classification tag value inherit).include? n.name end |
#requirement_component_parse(node, out) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/isodoc/function/reqt.rb', line 102 def requirement_component_parse(node, out) return if node["exclude"] == "true" out.div **reqt_component_attrs(node) do |div| node.children.each do |n| parse(n, div) end end end |
#requirement_parse(node, out) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/isodoc/function/reqt.rb', line 77 def requirement_parse(node, out) out.div **reqt_attrs(node, "require") do |t| recommendation_name(node, t, @requirement_lbl) recommendation_attributes(node, out) node.children.each do |n| parse(n, t) unless (n) end end end |
#requirement_skip_parse(node, out) ⇒ Object
111 112 |
# File 'lib/isodoc/function/reqt.rb', line 111 def requirement_skip_parse(node, out) end |
#sourcecode_attrs(node) ⇒ Object
76 77 78 |
# File 'lib/isodoc/function/blocks.rb', line 76 def sourcecode_attrs(node) attr_code(id: node["id"], class: "Sourcecode", style: keep_style(node)) end |
#sourcecode_name_parse(node, div, name) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/isodoc/function/blocks.rb', line 57 def sourcecode_name_parse(node, div, name) lbl = @xrefs.anchor(node['id'], :label, false) lbl = nil if labelled_ancestor(node) return if lbl.nil? && name.nil? div.p **{ class: "SourceTitle", style: "text-align:center;" } do |p| if node.ancestors("example").empty? lbl.nil? or p << l10n("#{@figure_lbl} #{lbl}") name and !lbl.nil? and p << " — " end name&.children&.each { |n| parse(n, p) } end end |
#sourcecode_parse(node, out) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/isodoc/function/blocks.rb', line 80 def sourcecode_parse(node, out) name = node.at(ns("./name")) out.p **sourcecode_attrs(node) do |div| @sourcecode = true node.children.each { |n| parse(n, div) unless n.name == "name" } @sourcecode = false end sourcecode_name_parse(node, out, name) end |