Module: IsoDoc::Function::Section
- Included in:
- Common
- Defined in:
- lib/isodoc/function/section.rb
Constant Summary collapse
- TERM_CLAUSE =
"//sections/terms | "\ "//sections/clause[descendant::terms]".freeze
Instance Method Summary collapse
- #abstract(isoxml, out) ⇒ Object
- #acknowledgements(isoxml, out) ⇒ Object
- #annex(isoxml, out) ⇒ Object
- #annex_attrs(node) ⇒ Object
- #annex_name(_annex, name, div) ⇒ Object
- #clause(isoxml, out) ⇒ Object
- #clause_attrs(node) ⇒ Object
- #clause_name(_num, title, div, header_class) ⇒ Object
-
#clause_parse(node, out) ⇒ Object
used for subclauses.
-
#clause_parse_title(node, div, title, out, header_class = {}) ⇒ Object
used for subclauses.
- #clausedelim ⇒ Object
- #clausedelimspace(out) ⇒ Object
- #copyright_parse(node, out) ⇒ Object
- #feedback_parse(node, out) ⇒ Object
- #foreword(isoxml, out) ⇒ Object
- #inline_header_title(out, _node, title) ⇒ Object
- #introduction(isoxml, out) ⇒ Object
- #is_clause?(name) ⇒ Boolean
- #legal_parse(node, out) ⇒ Object
- #license_parse(node, out) ⇒ Object
- #preface(isoxml, out) ⇒ Object
- #preface_block(isoxml, out) ⇒ Object
- #scope(isoxml, out, num) ⇒ Object
- #symbols_abbrevs(isoxml, out, num) ⇒ Object
-
#symbols_parse(isoxml, out) ⇒ Object
subclause.
- #terms_defs(isoxml, out, num) ⇒ Object
-
#terms_parse(isoxml, out) ⇒ Object
subclause.
Instance Method Details
#abstract(isoxml, out) ⇒ Object
184 185 186 187 188 189 190 191 |
# File 'lib/isodoc/function/section.rb', line 184 def abstract(isoxml, out) f = isoxml.at(ns("//preface/abstract")) || return page_break(out) out.div **attr_code(id: f["id"]) do |s| clause_name(nil, f.at(ns("./title")), s, { class: "AbstractTitle" }) f.elements.each { |e| parse(e, s) unless e.name == "title" } end end |
#acknowledgements(isoxml, out) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/isodoc/function/section.rb', line 172 def acknowledgements(isoxml, out) f = isoxml.at(ns("//acknowledgements")) || return title_attr = { class: "IntroTitle" } page_break(out) out.div **{ class: "Section3", id: f["id"] } do |div| clause_name(nil, f&.at(ns("./title")), div, title_attr) f.elements.each do |e| parse(e, div) unless e.name == "title" end end end |
#annex(isoxml, out) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/isodoc/function/section.rb', line 86 def annex(isoxml, out) isoxml.xpath(ns("//annex")).each do |c| page_break(out) out.div **attr_code(annex_attrs(c)) do |s| c.elements.each do |c1| if c1.name == "title" then annex_name(c, c1, s) else parse(c1, s) end end end end end |
#annex_attrs(node) ⇒ Object
82 83 84 |
# File 'lib/isodoc/function/section.rb', line 82 def annex_attrs(node) { id: node["id"], class: "Section3" } end |
#annex_name(_annex, name, div) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/isodoc/function/section.rb', line 74 def annex_name(_annex, name, div) return if name.nil? div.h1 **{ class: "Annex" } do |t| name.children.each { |c2| parse(c2, t) } end end |
#clause(isoxml, out) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/isodoc/function/section.rb', line 63 def clause(isoxml, out) isoxml.xpath(ns(middle_clause(isoxml))).each do |c| out.div **attr_code(clause_attrs(c)) do |s| clause_name(nil, c&.at(ns("./title")), s, nil) c.elements.reject { |c1| c1.name == "title" }.each do |c1| parse(c1, s) end end end end |
#clause_attrs(node) ⇒ Object
37 38 39 |
# File 'lib/isodoc/function/section.rb', line 37 def clause_attrs(node) { id: node["id"] } end |
#clause_name(_num, title, div, header_class) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/isodoc/function/section.rb', line 51 def clause_name(_num, title, div, header_class) header_class = {} if header_class.nil? div.h1 **attr_code(header_class) do |h1| if title.is_a?(String) h1 << title else title&.children&.each { |c2| parse(c2, h1) } end end div.parent.at(".//h1") end |
#clause_parse(node, out) ⇒ Object
used for subclauses
42 43 44 45 46 47 48 49 |
# File 'lib/isodoc/function/section.rb', line 42 def clause_parse(node, out) out.div **attr_code(clause_attrs(node)) do |div| clause_parse_title(node, div, node.at(ns("./title")), out) node.children.reject { |c1| c1.name == "title" }.each do |c1| parse(c1, div) end end end |
#clause_parse_title(node, div, title, out, header_class = {}) ⇒ Object
used for subclauses
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/isodoc/function/section.rb', line 21 def clause_parse_title(node, div, title, out, header_class = {}) return if title.nil? if node["inline-header"] == "true" inline_header_title(out, node, title) else depth = if title && title["depth"] then title["depth"] else node.ancestors("clause, annex, terms, references, definitions, "\ "acknowledgements, introduction, foreword").size + 1 end div.send "h#{depth}", **attr_code(header_class) do |h| title&.children&.each { |c2| parse(c2, h) } end end end |
#clausedelim ⇒ Object
3 4 5 |
# File 'lib/isodoc/function/section.rb', line 3 def clausedelim "." end |
#clausedelimspace(out) ⇒ Object
7 8 9 |
# File 'lib/isodoc/function/section.rb', line 7 def clausedelimspace(out) insert_tab(out, 1) end |
#copyright_parse(node, out) ⇒ Object
220 221 222 223 224 225 226 |
# File 'lib/isodoc/function/section.rb', line 220 def copyright_parse(node, out) return if out.div **{ class: "boilerplate-copyright" } do |div| node.children.each { |n| parse(n, div) } end end |
#feedback_parse(node, out) ⇒ Object
244 245 246 247 248 249 250 |
# File 'lib/isodoc/function/section.rb', line 244 def feedback_parse(node, out) return if out.div **{ class: "boilerplate-feedback" } do |div| node.children.each { |n| parse(n, div) } end end |
#foreword(isoxml, out) ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/isodoc/function/section.rb', line 162 def foreword(isoxml, out) f = isoxml.at(ns("//foreword")) || return page_break(out) out.div **attr_code(id: f["id"]) do |s| clause_name(nil, f.at(ns("./title")) || @i18n.foreword, s, { class: "ForewordTitle" }) f.elements.each { |e| parse(e, s) unless e.name == "title" } end end |
#inline_header_title(out, _node, title) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/isodoc/function/section.rb', line 11 def inline_header_title(out, _node, title) out.span **{ class: "zzMoveToFollowing" } do |s| s.b do |b| title&.children&.each { |c2| parse(c2, b) } clausedelimspace(out) if /\S/.match?(title&.text) end end end |
#introduction(isoxml, out) ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/isodoc/function/section.rb', line 151 def introduction(isoxml, out) f = isoxml.at(ns("//introduction")) || return page_break(out) out.div **{ class: "Section3", id: f["id"] } do |div| clause_name(nil, f.at(ns("./title")), div, { class: "IntroTitle" }) f.elements.each do |e| parse(e, div) unless e.name == "title" end end end |
#is_clause?(name) ⇒ Boolean
206 207 208 209 |
# File 'lib/isodoc/function/section.rb', line 206 def is_clause?(name) %w(clause references definitions terms foreword introduction abstract acknowledgements).include? name end |
#legal_parse(node, out) ⇒ Object
236 237 238 239 240 241 242 |
# File 'lib/isodoc/function/section.rb', line 236 def legal_parse(node, out) return if out.div **{ class: "boilerplate-legal" } do |div| node.children.each { |n| parse(n, div) } end end |
#license_parse(node, out) ⇒ Object
228 229 230 231 232 233 234 |
# File 'lib/isodoc/function/section.rb', line 228 def license_parse(node, out) return if out.div **{ class: "boilerplate-license" } do |div| node.children.each { |n| parse(n, div) } end end |
#preface(isoxml, out) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/isodoc/function/section.rb', line 193 def preface(isoxml, out) isoxml.xpath(ns("//preface/clause | //preface/references | "\ "//preface/definitions | //preface/terms")).each do |f| page_break(out) out.div **{ class: "Section3", id: f["id"] } do |div| clause_name(nil, f&.at(ns("./title")), div, { class: "IntroTitle" }) f.elements.each do |e| parse(e, div) unless e.name == "title" end end end end |
#preface_block(isoxml, out) ⇒ Object
211 212 213 214 215 216 217 218 |
# File 'lib/isodoc/function/section.rb', line 211 def preface_block(isoxml, out) p = isoxml.at(ns("//preface")) or return p.elements.each do |e| next if is_clause?(e.name) parse(e, out) end end |
#scope(isoxml, out, num) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/isodoc/function/section.rb', line 100 def scope(isoxml, out, num) f = isoxml.at(ns("//clause[@type = 'scope']")) or return num out.div **attr_code(id: f["id"]) do |div| num = num + 1 clause_name(num, f&.at(ns("./title")), div, nil) f.elements.each do |e| parse(e, div) unless e.name == "title" end end num end |
#symbols_abbrevs(isoxml, out, num) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/isodoc/function/section.rb', line 132 def symbols_abbrevs(isoxml, out, num) f = isoxml.at(ns("//sections/definitions")) or return num out.div **attr_code(id: f["id"], class: "Symbols") do |div| num = num + 1 clause_name(num, f&.at(ns("./title")) || @i18n.symbols, div, nil) f.elements.each do |e| parse(e, div) unless e.name == "title" end end num end |
#symbols_parse(isoxml, out) ⇒ Object
subclause
145 146 147 148 149 |
# File 'lib/isodoc/function/section.rb', line 145 def symbols_parse(isoxml, out) isoxml.at(ns("./title")) or isoxml.children.first.previous = "<title>#{@i18n.symbols}</title>" clause_parse(isoxml, out) end |
#terms_defs(isoxml, out, num) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/isodoc/function/section.rb', line 115 def terms_defs(isoxml, out, num) f = isoxml.at(ns(TERM_CLAUSE)) or return num out.div **attr_code(id: f["id"]) do |div| num = num + 1 clause_name(num, f&.at(ns("./title")), div, nil) f.elements.each do |e| parse(e, div) unless %w{title source}.include? e.name end end num end |
#terms_parse(isoxml, out) ⇒ Object
subclause
128 129 130 |
# File 'lib/isodoc/function/section.rb', line 128 def terms_parse(isoxml, out) clause_parse(isoxml, out) end |