Class: IsoDoc::Csand::HtmlConvert
- Inherits:
-
HtmlConvert
- Object
- HtmlConvert
- IsoDoc::Csand::HtmlConvert
- Defined in:
- lib/isodoc/csand/csandconvert.rb
Overview
A Converter implementation that generates CSAND output, and a document schema encapsulation of the document for validation
Instance Method Summary collapse
- #annex_name(annex, name, div) ⇒ Object
- #annex_name_lbl(clause, num) ⇒ Object
- #cleanup(docxml) ⇒ Object
- #default_fonts(options) ⇒ Object
- #error_parse(node, out) ⇒ Object
- #html_doc_path(file) ⇒ Object
- #html_head ⇒ Object
- #html_toc(docxml) ⇒ Object
- #i18n_init(lang, script) ⇒ Object
-
#initialize(options) ⇒ HtmlConvert
constructor
A new instance of HtmlConvert.
- #make_body(xml, docxml) ⇒ Object
- #metadata_init(lang, script, labels) ⇒ Object
- #pre_parse(node, out) ⇒ Object
- #term_cleanup(docxml) ⇒ Object
- #term_defs_boilerplate(div, source, term, preface) ⇒ Object
Constructor Details
#initialize(options) ⇒ HtmlConvert
Returns a new instance of HtmlConvert.
13 14 15 16 17 18 19 20 |
# File 'lib/isodoc/csand/csandconvert.rb', line 13 def initialize() super @htmlstylesheet = generate_css(html_doc_path("htmlstyle.scss"), true, default_fonts()) # @standardstylesheet = generate_css(html_doc_path("csd.scss"), true, default_fonts(options)) @htmlcoverpage = html_doc_path("html_csand_titlepage.html") @htmlintropage = html_doc_path("html_csand_intro.html") @scripts = html_doc_path("scripts.html") end |
Instance Method Details
#annex_name(annex, name, div) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/isodoc/csand/csandconvert.rb', line 37 def annex_name(annex, name, div) div.h1 **{ class: "Annex" } do |t| t << "#{get_anchors[annex['id']][:label]} " t << "<b>#{name.text}</b>" end end |
#annex_name_lbl(clause, num) ⇒ Object
44 45 46 47 48 |
# File 'lib/isodoc/csand/csandconvert.rb', line 44 def annex_name_lbl(clause, num) obl = l10n("(#{@inform_annex_lbl})") obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative" l10n("<b>#{@annex_lbl} #{num}</b> #{obl}") end |
#cleanup(docxml) ⇒ Object
112 113 114 115 |
# File 'lib/isodoc/csand/csandconvert.rb', line 112 def cleanup(docxml) super term_cleanup(docxml) end |
#default_fonts(options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/isodoc/csand/csandconvert.rb', line 22 def default_fonts() b = [:bodyfont] || ([:script] == "Hans" ? '"SimSun",serif' : '"Source Sans Pro",sans-serif') h = [:headerfont] || ([:script] == "Hans" ? '"SimHei",sans-serif' : '"Source Sans Pro",sans-serif') m = [:monospacefont] || '"Space Mono",monospace' "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n" end |
#error_parse(node, out) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/isodoc/csand/csandconvert.rb', line 67 def error_parse(node, out) # catch elements not defined in ISO case node.name when "pre" pre_parse(node, out) when "keyword" out.span node.text, **{ class: "keyword" } else super end end |
#html_doc_path(file) ⇒ Object
9 10 11 |
# File 'lib/isodoc/csand/csandconvert.rb', line 9 def html_doc_path(file) File.join(File.dirname(__FILE__), File.join("html", file)) end |
#html_head ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/isodoc/csand/csandconvert.rb', line 79 def html_head() " <script type=\"text/javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>\n\n <!--TOC script import-->\n <script type=\"text/javascript\" src=\"https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js\"></script>\n\n <!--Google fonts-->\n <link href=\"https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700\" rel=\"stylesheet\">\n <link href=\"https://fonts.googleapis.com/css?family=Rubik:300,300i,500\" rel=\"stylesheet\">\n <link href=\"https://fonts.googleapis.com/css?family=Overpass:100,300,300i,600,900\" rel=\"stylesheet\">\n\n <link href=\"https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300i,400,700,900\" rel=\"stylesheet\">\n <!--Font awesome import for the link icon-->\n <link rel=\"stylesheet\" href=\"https://use.fontawesome.com/releases/v5.0.8/css/solid.css\" integrity=\"sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk\" crossorigin=\"anonymous\">\n <link rel=\"stylesheet\" href=\"https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css\" integrity=\"sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P\" crossorigin=\"anonymous\">\n<style class=\"anchorjs\"></style>\n HEAD\nend\n".freeze |
#html_toc(docxml) ⇒ Object
108 109 110 |
# File 'lib/isodoc/csand/csandconvert.rb', line 108 def html_toc(docxml) docxml end |
#i18n_init(lang, script) ⇒ Object
62 63 64 65 |
# File 'lib/isodoc/csand/csandconvert.rb', line 62 def i18n_init(lang, script) super @annex_lbl = "Appendix" end |
#make_body(xml, docxml) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/isodoc/csand/csandconvert.rb', line 99 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 |
#metadata_init(lang, script, labels) ⇒ Object
33 34 35 |
# File 'lib/isodoc/csand/csandconvert.rb', line 33 def (lang, script, labels) = Metadata.new(lang, script, labels) end |
#pre_parse(node, out) ⇒ Object
50 51 52 |
# File 'lib/isodoc/csand/csandconvert.rb', line 50 def pre_parse(node, out) out.pre node.text # content.gsub(/</, "<").gsub(/>/, ">") end |
#term_cleanup(docxml) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/isodoc/csand/csandconvert.rb', line 117 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
54 55 56 57 58 59 60 |
# File 'lib/isodoc/csand/csandconvert.rb', line 54 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 |