Module: IsoDoc::Function::Section
- Included in:
- Common
- Defined in:
- lib/isodoc/function/section.rb,
lib/isodoc/function/section_titles.rb
Constant Summary collapse
- TERM_CLAUSE =
"//sections/terms | " \ "//sections/clause[descendant::terms]".freeze
Instance Method Summary collapse
- #abstract(clause, out) ⇒ Object
- #acknowledgements(clause, out) ⇒ Object
- #annex(node, out) ⇒ Object
- #annex_attrs(node) ⇒ Object
- #annex_name(_annex, name, div) ⇒ Object
- #clause(node, out) ⇒ Object
- #clause_attrs(node) ⇒ Object
-
#clause_name(_node, title, div, header_class) ⇒ Object
top level clause names.
-
#clause_parse(node, out) ⇒ Object
used for subclauses.
- #clause_parse_subtitle(title, heading) ⇒ Object
-
#clause_parse_title(node, div, title, out, header_class = {}) ⇒ Object
used for subclauses.
- #clause_parse_title1(node, div, title, _out, header_class = {}) ⇒ Object
- #clause_title_depth(node, title) ⇒ Object
- #clausedelim ⇒ Object
- #clausedelimspace(_node, out) ⇒ Object
- #colophon(node, out) ⇒ Object
- #copyright_parse(node, out) ⇒ Object
- #executivesummary(clause, out) ⇒ Object
- #feedback_parse(node, out) ⇒ Object
- #foreword(clause, out) ⇒ Object
- #freestanding_title(node, out) ⇒ Object
- #indexsect(node, out) ⇒ Object
- #inline_header_title(out, node, title) ⇒ Object
- #introduction(clause, out) ⇒ Object
- #is_clause?(name) ⇒ Boolean
- #legal_parse(node, out) ⇒ Object
- #license_parse(node, out) ⇒ Object
- #preface(clause, out) ⇒ Object
- #preface_attrs(node) ⇒ Object
-
#preface_block(block, out) ⇒ Object
block, e.g.
- #preface_normal(clause, out) ⇒ Object
- #scope(node, out) ⇒ Object
- #sections_names ⇒ Object
- #single_term_clause?(elem) ⇒ Boolean
- #symbols_abbrevs(node, out) ⇒ Object
-
#symbols_parse(isoxml, out) ⇒ Object
subclause.
- #table_of_contents(clause, out) ⇒ Object
- #terms_defs(node, out) ⇒ Object
-
#terms_parse(isoxml, out) ⇒ Object
subclause.
- #variant_title(node, out) ⇒ Object
Instance Method Details
#abstract(clause, out) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/isodoc/function/section.rb', line 119 def abstract(clause, out) page_break(out) out.div **attr_code(id: clause["id"]) do |s| clause_name(clause, clause.at(ns("./fmt-title")), s, { class: "AbstractTitle" }) clause.elements.each { |e| parse(e, s) unless e.name == "fmt-title" } end end |
#acknowledgements(clause, out) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/isodoc/function/section.rb', line 108 def acknowledgements(clause, out) title_attr = { class: "IntroTitle" } page_break(out) out.div class: "Section3", id: clause["id"] do |div| clause_name(clause, clause.at(ns("./fmt-title")), div, title_attr) clause.elements.each do |e| parse(e, div) unless e.name == "fmt-title" end end end |
#annex(node, out) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/isodoc/function/section.rb', line 33 def annex(node, out) page_break(out) out.div **attr_code(annex_attrs(node)) do |s| node.elements.each do |c1| if c1.name == "fmt-title" then annex_name(node, c1, s) else parse(c1, s) end end end end |
#annex_attrs(node) ⇒ Object
29 30 31 |
# File 'lib/isodoc/function/section.rb', line 29 def annex_attrs(node) { id: node["id"], class: "Section3" } end |
#annex_name(_annex, name, div) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/isodoc/function/section_titles.rb', line 82 def annex_name(_annex, name, div) name.nil? and return div.h1 class: "Annex" do |t| name.children.each { |c2| parse(c2, t) } clause_parse_subtitle(name, t) end end |
#clause(node, out) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/isodoc/function/section.rb', line 20 def clause(node, out) out.div **attr_code(clause_attrs(node)) do |s| clause_name(node, node.at(ns("./fmt-title")), s, nil) node.elements.reject { |c1| c1.name == "fmt-title" }.each do |c1| parse(c1, s) end end end |
#clause_attrs(node) ⇒ Object
6 7 8 |
# File 'lib/isodoc/function/section.rb', line 6 def clause_attrs(node) { id: node["id"] } end |
#clause_name(_node, title, div, header_class) ⇒ Object
top level clause names
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/isodoc/function/section_titles.rb', line 70 def clause_name(_node, title, div, header_class) header_class = {} if header_class.nil? div.h1 **attr_code(header_class) do |h1| if title.is_a?(String) then h1 << title elsif title children_parse(title, h1) clause_parse_subtitle(title, h1) end end div.parent.at(".//h1") end |
#clause_parse(node, out) ⇒ Object
used for subclauses
11 12 13 14 15 16 17 18 |
# File 'lib/isodoc/function/section.rb', line 11 def clause_parse(node, out) out.div **attr_code(clause_attrs(node)) do |div| clause_parse_title(node, div, node.at(ns("./fmt-title")), out) node.children.reject { |c1| c1.name == "fmt-title" }.each do |c1| parse(c1, div) end end end |
#clause_parse_subtitle(title, heading) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/isodoc/function/section_titles.rb', line 60 def clause_parse_subtitle(title, heading) if var = title&.at("./following-sibling::xmlns:variant-title" \ "[@type = 'sub']")&.remove heading.br nil heading.br nil var.children.each { |c2| parse(c2, heading) } end end |
#clause_parse_title(node, div, title, out, header_class = {}) ⇒ Object
used for subclauses
37 38 39 40 41 42 43 44 |
# File 'lib/isodoc/function/section_titles.rb', line 37 def clause_parse_title(node, div, title, out, header_class = {}) title.nil? and return if node["inline-header"] == "true" inline_header_title(out, node, title) else clause_parse_title1(node, div, title, out, header_class) end end |
#clause_parse_title1(node, div, title, _out, header_class = {}) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/isodoc/function/section_titles.rb', line 46 def clause_parse_title1(node, div, title, _out, header_class = {}) depth = clause_title_depth(node, title) div.send "h#{depth}", **attr_code(header_class) do |h| title&.children&.each { |c2| parse(c2, h) } clause_parse_subtitle(title, h) end end |
#clause_title_depth(node, title) ⇒ Object
54 55 56 57 58 |
# File 'lib/isodoc/function/section_titles.rb', line 54 def clause_title_depth(node, title) depth = node.ancestors(sections_names.join(", ")).size + 1 depth = title["depth"] if title && title["depth"] depth end |
#clausedelim ⇒ Object
4 5 6 |
# File 'lib/isodoc/function/section_titles.rb', line 4 def clausedelim "." end |
#clausedelimspace(_node, out) ⇒ Object
8 9 10 |
# File 'lib/isodoc/function/section_titles.rb', line 8 def clausedelimspace(_node, out) insert_tab(out, 1) end |
#colophon(node, out) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/isodoc/function/section.rb', line 164 def colophon(node, out) @seen_colophon or page_break(out) @seen_colophon = true out.div class: "Section3", id: node["id"] do |div| clause_name(node, node.at(ns("./fmt-title")), div, { class: "IntroTitle" }) node.elements.each do |e| parse(e, div) unless e.name == "fmt-title" end end end |
#copyright_parse(node, out) ⇒ Object
195 196 197 198 199 200 |
# File 'lib/isodoc/function/section.rb', line 195 def copyright_parse(node, out) @bare and return out.div class: "boilerplate-copyright" do |div| node.children.each { |n| parse(n, div) } end end |
#executivesummary(clause, out) ⇒ Object
186 187 188 |
# File 'lib/isodoc/function/section.rb', line 186 def executivesummary(clause, out) introduction clause, out end |
#feedback_parse(node, out) ⇒ Object
216 217 218 219 220 221 |
# File 'lib/isodoc/function/section.rb', line 216 def feedback_parse(node, out) @bare and return out.div class: "boilerplate-feedback" do |div| node.children.each { |n| parse(n, div) } end end |
#foreword(clause, out) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/isodoc/function/section.rb', line 99 def foreword(clause, out) page_break(out) out.div **attr_code(id: clause["id"]) do |s| clause_name(clause, clause.at(ns("./fmt-title")), s, { class: "ForewordTitle" }) clause.elements.each { |e| parse(e, s) unless e.name == "fmt-title" } end end |
#freestanding_title(node, out) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/isodoc/function/section_titles.rb', line 26 def freestanding_title(node, out) # node.parent.at(ns("./fmt-title[@source = '#{node['id']}']")) and # return # this title is already being rendered as fmt-title # For testing convenience, let's just go by parent sections_names.include?(node.parent.name) and return parents = node.ancestors(sections_names.join(", ")) clause_parse_title(parents.empty? ? node : parents.first, out, node, out) end |
#indexsect(node, out) ⇒ Object
44 45 46 |
# File 'lib/isodoc/function/section.rb', line 44 def indexsect(node, out) clause_parse(node, out) end |
#inline_header_title(out, node, title) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/isodoc/function/section_titles.rb', line 12 def inline_header_title(out, node, title) out.span class: "zzMoveToFollowing inline-header" do |s| s.b do |b| title&.children&.each { |c2| parse(c2, b) } clausedelimspace(node, out) if /\S/.match?(title&.text) end end end |
#introduction(clause, out) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/isodoc/function/section.rb', line 88 def introduction(clause, out) page_break(out) out.div class: "Section3", id: clause["id"] do |div| clause_name(clause, clause.at(ns("./fmt-title")), div, { class: "IntroTitle" }) clause.elements.each do |e| parse(e, div) unless e.name == "fmt-title" end end end |
#is_clause?(name) ⇒ Boolean
176 177 178 179 |
# File 'lib/isodoc/function/section.rb', line 176 def is_clause?(name) %w(clause references definitions terms foreword introduction abstract acknowledgements).include? name end |
#legal_parse(node, out) ⇒ Object
209 210 211 212 213 214 |
# File 'lib/isodoc/function/section.rb', line 209 def legal_parse(node, out) @bare and return out.div class: "boilerplate-legal" do |div| node.children.each { |n| parse(n, div) } end end |
#license_parse(node, out) ⇒ Object
202 203 204 205 206 207 |
# File 'lib/isodoc/function/section.rb', line 202 def license_parse(node, out) @bare and return out.div class: "boilerplate-license" do |div| node.children.each { |n| parse(n, div) } end end |
#preface(clause, out) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/isodoc/function/section.rb', line 133 def preface(clause, out) if clause["type"] == "toc" table_of_contents(clause, out) else preface_normal(clause, out) end end |
#preface_attrs(node) ⇒ Object
128 129 130 131 |
# File 'lib/isodoc/function/section.rb', line 128 def preface_attrs(node) { id: node["id"], class: node["type"] == "toc" ? "TOC" : "Section3" } end |
#preface_block(block, out) ⇒ Object
block, e.g. note, admonition
191 192 193 |
# File 'lib/isodoc/function/section.rb', line 191 def preface_block(block, out) parse(block, out) end |
#preface_normal(clause, out) ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/isodoc/function/section.rb', line 141 def preface_normal(clause, out) page_break(out) out.div **attr_code(preface_attrs(clause)) do |div| clause_name(clause, clause.at(ns("./fmt-title")), div, { class: "IntroTitle" }) clause.elements.each do |e| parse(e, div) unless e.name == "fmt-title" end end end |
#scope(node, out) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/isodoc/function/section.rb', line 48 def scope(node, out) out.div **attr_code(id: node["id"]) do |div| clause_name(node, node.at(ns("./fmt-title")), div, nil) node.elements.each do |e| parse(e, div) unless e.name == "fmt-title" end end end |
#sections_names ⇒ Object
21 22 23 24 |
# File 'lib/isodoc/function/section_titles.rb', line 21 def sections_names %w[clause annex terms references definitions acknowledgements introduction abstract foreword appendix] end |
#single_term_clause?(elem) ⇒ Boolean
181 182 183 184 |
# File 'lib/isodoc/function/section.rb', line 181 def single_term_clause?(elem) t = elem.xpath(ns("./clause | ./terms | ./definitions | ./references")) t.size == 1 && %w(terms definitions references).include?(t[0].name) end |
#symbols_abbrevs(node, out) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/isodoc/function/section.rb', line 74 def symbols_abbrevs(node, out) out.div **attr_code(id: node["id"], class: "Symbols") do |div| clause_name(node, node.at(ns("./fmt-title")), div, nil) node.elements.each do |e| parse(e, div) unless e.name == "fmt-title" end end end |
#symbols_parse(isoxml, out) ⇒ Object
subclause
84 85 86 |
# File 'lib/isodoc/function/section.rb', line 84 def symbols_parse(isoxml, out) clause_parse(isoxml, out) end |
#table_of_contents(clause, out) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/isodoc/function/section.rb', line 152 def table_of_contents(clause, out) @bare and return page_break(out) out.div **attr_code(preface_attrs(clause)) do |div| clause_name(clause, clause.at(ns("./fmt-title")), div, { class: "IntroTitle" }) clause.elements.each do |e| parse(e, div) unless e.name == "fmt-title" end end end |
#terms_defs(node, out) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/isodoc/function/section.rb', line 60 def terms_defs(node, out) out.div **attr_code(id: node["id"]) do |div| clause_name(node, node.at(ns("./fmt-title")), div, nil) node.elements.each do |e| parse(e, div) unless %w{fmt-title source}.include? e.name end end end |
#terms_parse(isoxml, out) ⇒ Object
subclause
70 71 72 |
# File 'lib/isodoc/function/section.rb', line 70 def terms_parse(isoxml, out) clause_parse(isoxml, out) end |
#variant_title(node, out) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/isodoc/function/section_titles.rb', line 90 def variant_title(node, out) out.p **attr_code(style: "display:none;", class: "variant-title-#{node['type']}") do |p| node.children.each { |c| parse(c, p) } end end |