Class: IsoDoc::Ogc::PdfConvert
- Inherits:
-
PdfConvert
- Object
- PdfConvert
- IsoDoc::Ogc::PdfConvert
- Defined in:
- lib/isodoc/ogc/pdf_convert.rb
Overview
A Converter implementation that generates PDF HTML output, and a document schema encapsulation of the document for validation
Constant Summary collapse
- SUBMITTINGORGS =
"//bibdata/contributor[role/@type = 'author']/organization/name".freeze
- REQ_TBL_ATTR =
{ valign: "top", class: "example_label", style: "width:100.0pt;padding:0 0 0 1em;margin-left:0pt" }.freeze
Instance Method Summary collapse
- #abstract(isoxml, out) ⇒ Object
- #anchor_names(docxml) ⇒ Object
- #annex_name(annex, name, div) ⇒ Object
- #cleanup(docxml) ⇒ Object
- #default_file_locations(_options) ⇒ Object
- #default_fonts(options) ⇒ Object
- #error_parse(node, out) ⇒ Object
- #example_parse(node, out) ⇒ Object
- #fileloc(loc) ⇒ Object
- #foreword(isoxml, out) ⇒ Object
- #html_head ⇒ Object
- #html_toc(docxml) ⇒ Object
- #info(isoxml, out) ⇒ Object
- #initial_anchor_names(d) ⇒ Object
-
#initialize(options) ⇒ PdfConvert
constructor
A new instance of PdfConvert.
- #keywords(_docxml, out) ⇒ Object
- #load_yaml(lang, script) ⇒ Object
- #make_body(xml, docxml) ⇒ Object
- #make_body3(body, docxml) ⇒ Object
- #metadata_init(lang, script, labels) ⇒ Object
- #permission_anchor_names(docxml) ⇒ Object
- #permission_label(node) ⇒ Object
- #permission_parse(node, out) ⇒ Object
- #preface_names(clause) ⇒ Object
- #recommend_name_parse(node, div) ⇒ Object
- #recommend_table_attr(node) ⇒ Object
- #recommendation_anchor_names(docxml) ⇒ Object
- #recommendation_label(node) ⇒ Object
- #recommendation_parse(node, out) ⇒ Object
- #requirement_anchor_names(docxml) ⇒ Object
- #requirement_label(node) ⇒ Object
- #requirement_parse(node, out) ⇒ Object
- #submitters(docxml, out) ⇒ Object
- #submittingorgs(docxml, out) ⇒ Object
- #term_cleanup(docxml) ⇒ Object
- #term_defs_boilerplate(div, source, term, preface) ⇒ Object
Constructor Details
#initialize(options) ⇒ PdfConvert
Returns a new instance of PdfConvert.
10 11 12 13 14 15 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 10 def initialize() @libdir = File.dirname(__FILE__) super #FileUtils.cp html_doc_path('logo.jpg'), "logo.jpg" #@files_to_delete << "logo.jpg" end |
Instance Method Details
#abstract(isoxml, out) ⇒ Object
184 185 186 187 188 189 190 191 192 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 184 def abstract(isoxml, out) f = isoxml.at(ns("//preface/abstract")) || return @prefacenum += 1 page_break(out) out.div **attr_code(id: f["id"]) do |s| clause_name(get_anchors[f["id"]][:label], @abstract_lbl, s, class: "AbstractTitle") f.elements.each { |e| parse(e, s) unless e.name == "title" } end end |
#anchor_names(docxml) ⇒ Object
229 230 231 232 233 234 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 229 def anchor_names(docxml) super recommendation_anchor_names(docxml) requirement_anchor_names(docxml) (docxml) end |
#annex_name(annex, name, div) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 69 def annex_name(annex, name, div) div.h1 **{ class: "Annex" } do |t| t << "#{get_anchors[annex['id']][:label]} " t.br t.b do |b| name&.children&.each { |c2| parse(c2, b) } end end end |
#cleanup(docxml) ⇒ Object
91 92 93 94 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 91 def cleanup(docxml) super term_cleanup(docxml) end |
#default_file_locations(_options) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 25 def default_file_locations() { htmlstylesheet: html_doc_path("htmlstyle.scss"), htmlcoverpage: html_doc_path("html_ogc_titlepage.html"), htmlintropage: html_doc_path("html_ogc_intro.html"), scripts_pdf: html_doc_path("scripts.pdf.html"), } end |
#default_fonts(options) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 17 def default_fonts() { bodyfont: ([:script] == "Hans" ? '"SimSun",serif' : '"Overpass",sans-serif'), headerfont: ([:script] == "Hans" ? '"SimHei",sans-serif' : '"Overpass",sans-serif'), monospacefont: '"Space Mono",monospace' } end |
#error_parse(node, out) ⇒ Object
219 220 221 222 223 224 225 226 227 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 219 def error_parse(node, out) case node.name when "recommendation" then recommendation_parse(node, out) when "requirement" then requirement_parse(node, out) when "permission" then (node, out) else super end end |
#example_parse(node, out) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 204 def example_parse(node, out) name = node.at(ns("./name")) sourcecode_name_parse(node, out, name) if name 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 **{ valign: "top", class: "example" } do |td| node.children.each { |n| parse(n, td) unless n.name == "name" } end end end end |
#fileloc(loc) ⇒ Object
87 88 89 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 87 def fileloc(loc) File.join(File.dirname(__FILE__), loc) end |
#foreword(isoxml, out) ⇒ Object
194 195 196 197 198 199 200 201 202 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 194 def foreword(isoxml, out) f = isoxml.at(ns("//foreword")) || return @prefacenum += 1 page_break(out) out.div **attr_code(id: f["id"]) do |s| clause_name(get_anchors[f["id"]][:label], @foreword_lbl, s, class: "ForewordTitle") f.elements.each { |e| parse(e, s) unless e.name == "title" } end end |
#html_head ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 38 def html_head() <<~HEAD.freeze <title>{{ doctitle }}</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <!--TOC script import--> <script type="text/javascript" src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"></script> <!--Google fonts--> <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet"> <!--Font awesome import for the link icon--> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/solid.css" integrity="sha384-rdyFrfAIC05c5ph7BKz3l5NG5yEottvO/DQ0dCrwD8gzeQDjYBHNr1ucUpQuljos" crossorigin="anonymous"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/fontawesome.css" integrity="sha384-u5J7JghGz0qUrmEsWzBQkfvc8nK3fUT7DCaQzNQ+q4oEXhGSx+P2OqjWsfIRB8QT" crossorigin="anonymous"> <style class="anchorjs"></style> HEAD end |
#html_toc(docxml) ⇒ Object
65 66 67 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 65 def html_toc(docxml) docxml end |
#info(isoxml, out) ⇒ Object
105 106 107 108 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 105 def info(isoxml, out) @meta.keywords isoxml, out super end |
#initial_anchor_names(d) ⇒ Object
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 332 def initial_anchor_names(d) @prefacenum = 0 preface_names(d.at(ns("//preface/abstract"))) @prefacenum += 1 if d.at(ns("//keyword")) preface_names(d.at(ns("//foreword"))) #preface_names(d.at(ns("//introduction"))) @prefacenum += 1 if d.at(ns(SUBMITTINGORGS)) preface_names(d.at(ns("//submitters"))) sequential_asset_names(d.xpath(ns("//preface/abstract | //foreword | //introduction | //submitters"))) n = section_names(d.at(ns("//clause[title = 'Scope']")), 0, 1) n = section_names(d.at(ns("//clause[title = 'Conformance']")), n, 1) n = section_names(d.at(ns( "//references[title = 'Normative References' or title = 'Normative references']")), n, 1) n = section_names(d.at(ns("//sections/terms | "\ "//sections/clause[descendant::terms]")), n, 1) n = section_names(d.at(ns("//sections/definitions")), n, 1) middle_section_asset_names(d) clause_names(d, n) termnote_anchor_names(d) termexample_anchor_names(d) end |
#keywords(_docxml, out) ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 121 def keywords(_docxml, out) kw = @meta.get[:keywords] kw.empty? and return @prefacenum += 1 out.div **{ class: "Section3" } do |div| clause_name(RomanNumerals.to_roman(@prefacenum).downcase, "Keywords", div, class: "IntroTitle") div.p "The following are keywords to be used by search engines and document catalogues." div.p kw.join(", ") end end |
#load_yaml(lang, script) ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 110 def load_yaml(lang, script) y = if @i18nyaml then YAML.load_file(@i18nyaml) elsif lang == "en" YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml")) else YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml")) end super.merge(y) end |
#make_body(xml, docxml) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 56 def make_body(xml, docxml) body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" } xml.body **body_attr do |body| make_body1(body, docxml) make_body2(body, docxml) make_body3(body, docxml) end end |
#make_body3(body, docxml) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 159 def make_body3(body, docxml) body.div **{ class: "main-section" } do |div3| @prefacenum = 0 abstract docxml, div3 keywords docxml, div3 foreword docxml, div3 submittingorgs docxml, div3 submitters docxml, div3 middle docxml, div3 footnotes div3 comments div3 end end |
#metadata_init(lang, script, labels) ⇒ Object
34 35 36 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 34 def (lang, script, labels) @meta = Metadata.new(lang, script, labels) end |
#permission_anchor_names(docxml) ⇒ Object
248 249 250 251 252 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 248 def (docxml) docxml.xpath(ns("//permission")).each_with_index do |x, i| @anchors[x["id"]] = anchor_struct(i+1, nil, "Permission", "permission") end end |
#permission_label(node) ⇒ Object
325 326 327 328 329 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 325 def (node) n = get_anchors[node["id"]] return "Permission" if n.nil? || n[:label].empty? l10n("#{"Permission"} #{n[:label]}") end |
#permission_parse(node, out) ⇒ Object
311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 311 def (node, out) out.table **recommend_table_attr(node) do |t| t.tr do |tr| tr.td **REQ_TBL_ATTR do |td| td << (node) end tr.td **{ valign: "top", class: "recommend" } do |td| recommend_name_parse(node, td) node.children.each { |n| parse(n, td) unless n.name == "name" } end end end end |
#preface_names(clause) ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 173 def preface_names(clause) return if clause.nil? @prefacenum += 1 @anchors[clause["id"]] = { label: RomanNumerals.to_roman(@prefacenum).downcase, level: 1, xref: preface_clause_name(clause), type: "clause" } clause.xpath(ns("./clause | ./terms | ./term | ./definitions")).each_with_index do |c, i| section_names1(c, "#{@prefacenum}.#{i + 1}", 2) end end |
#recommend_name_parse(node, div) ⇒ Object
264 265 266 267 268 269 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 264 def recommend_name_parse(node, div) name = node&.at(ns("./name"))&.text or return div.p do |p| p.b name end end |
#recommend_table_attr(node) ⇒ Object
254 255 256 257 258 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 254 def recommend_table_attr(node) attr_code(id: node["id"], class: "recommend", cellspacing: 0, cellpadding: 0, style: "border-collapse:collapse" ) end |
#recommendation_anchor_names(docxml) ⇒ Object
236 237 238 239 240 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 236 def recommendation_anchor_names(docxml) docxml.xpath(ns("//recommendation")).each_with_index do |x, i| @anchors[x["id"]] = anchor_struct(i+1, nil, "Recommendation", "recommendation") end end |
#recommendation_label(node) ⇒ Object
285 286 287 288 289 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 285 def recommendation_label(node) n = get_anchors[node["id"]] return "Recommendation" if n.nil? || n[:label].empty? l10n("#{"Recommendation"} #{n[:label]}") end |
#recommendation_parse(node, out) ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 271 def recommendation_parse(node, out) out.table **recommend_table_attr(node) do |t| t.tr do |tr| tr.td **REQ_TBL_ATTR do |td| td << recommendation_label(node) end tr.td **{ valign: "top", class: "recommend" } do |td| recommend_name_parse(node, td) node.children.each { |n| parse(n, td) unless n.name == "name" } end end end end |
#requirement_anchor_names(docxml) ⇒ Object
242 243 244 245 246 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 242 def requirement_anchor_names(docxml) docxml.xpath(ns("//requirement")).each_with_index do |x, i| @anchors[x["id"]] = anchor_struct(i+1, nil, "Requirement", "requirement") end end |
#requirement_label(node) ⇒ Object
305 306 307 308 309 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 305 def requirement_label(node) n = get_anchors[node["id"]] return "Requirement" if n.nil? || n[:label].empty? l10n("#{"Requirement"} #{n[:label]}") end |
#requirement_parse(node, out) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 291 def requirement_parse(node, out) out.table **recommend_table_attr(node) do |t| t.tr do |tr| tr.td **REQ_TBL_ATTR do |td| td << requirement_label(node) end tr.td **{ valign: "top", class: "recommend" } do |td| recommend_name_parse(node, td) node.children.each { |n| parse(n, td) unless n.name == "name" } end end end end |
#submitters(docxml, out) ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 151 def submitters(docxml, out) f = docxml.at(ns("//submitters")) || return out.div **{ class: "Section3" } do |div| clause_name(get_anchors[f['id']][:label], "Submitters", div, class: "IntroTitle") f.elements.each { |e| parse(e, div) unless e.name == "title" } end end |
#submittingorgs(docxml, out) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 135 def submittingorgs(docxml, out) orgs = [] docxml.xpath(ns(SUBMITTINGORGS)).each { |org| orgs << org.text } return if orgs.empty? @prefacenum += 1 out.div **{ class: "Section3" } do |div| clause_name(RomanNumerals.to_roman(@prefacenum).downcase, "Submitting Organizations", div, class: "IntroTitle") div.p "The following organizations submitted this Document to the Open Geospatial Consortium (OGC):" div.ul do |ul| orgs.each do |org| ul.li org end end end end |
#term_cleanup(docxml) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 96 def term_cleanup(docxml) docxml.xpath("//p[@class = 'Terms']").each do |d| h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]") h2.add_child(" ") h2.add_child(d.remove) end docxml end |
#term_defs_boilerplate(div, source, term, preface) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/isodoc/ogc/pdf_convert.rb', line 79 def term_defs_boilerplate(div, source, term, preface) if source.empty? && term.nil? div << @no_terms_boilerplate else div << term_defs_boilerplate_cont(source, term) end end |