Class: IsoDoc::Iso::HtmlConvert

Inherits:
HtmlConvert
  • Object
show all
Includes:
BaseConvert, Init
Defined in:
lib/isodoc/iso/html_convert.rb

Instance Method Summary collapse

Methods included from Init

#amd, #clausedelim, #i18n_init, #metadata_init, #xref_init

Methods included from BaseConvert

#admonition_name_parse, #admonition_p_parse, #admonition_parse, #admonition_parse1, #annex, #clause_etc, #clause_etc1, #cleanup, #convert1, #error_parse, #example_p_parse, #example_parse, #example_parse1, #example_span_label, #figure_name_parse, #foreword, #formula_where, #implicit_reference, #indexsect, #introduction, #middle, #middle_title, #middle_title_amd, #middle_title_main, #node_begins_with_para

Constructor Details

#initialize(options) ⇒ HtmlConvert

Returns a new instance of HtmlConvert.



8
9
10
11
# File 'lib/isodoc/iso/html_convert.rb', line 8

def initialize(options)
  @libdir = File.dirname(__FILE__)
  super
end

Instance Method Details

#default_file_locations(options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/isodoc/iso/html_convert.rb', line 44

def default_file_locations(options)
  {
    htmlstylesheet: (if options[:alt]
                       html_doc_path("style-human.scss")
                     else
                       html_doc_path("style-iso.scss")
                     end),
    htmlcoverpage: html_doc_path("html_iso_titlepage.html"),
    htmlintropage: html_doc_path("html_iso_intro.html"),
  }
end

#default_fonts(options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/isodoc/iso/html_convert.rb', line 20

def default_fonts(options)
  {
    bodyfont: (if options[:script] == "Hans"
                 '"Source Han Sans",serif'
               else
                 options[:alt] ? '"Lato",sans-serif' : '"Cambria",serif'
               end),
    headerfont: (if options[:script] == "Hans"
                   '"Source Han Sans",sans-serif'
                 else
                   options[:alt] ? '"Lato",sans-serif' : '"Cambria",serif'
                 end),
    monospacefont: (if options[:alt]
                      '"Space Mono",monospace'
                    else
                      '"Courier New",monospace'
                    end),
    normalfontsize: "1.0em",
    smallerfontsize: "0.9em",
    footnotefontsize: "0.9em",
    monospacefontsize: "0.8em",
  }
end

#footnote_reference_format(link) ⇒ Object



56
57
58
# File 'lib/isodoc/iso/html_convert.rb', line 56

def footnote_reference_format(link)
  link.content += ")"
end

#googlefontsObject



13
14
15
16
17
18
# File 'lib/isodoc/iso/html_convert.rb', line 13

def googlefonts
  "    <link href=\"https://fonts.googleapis.com/css?family=Space+Mono:400,400i,700,700i&display=swap\" rel=\"stylesheet\">\n    <link href=\"https://fonts.googleapis.com/css?family=Lato:400,400i,700,900\" rel=\"stylesheet\">\n  HEAD\nend\n".freeze

#html_toc(docxml) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/isodoc/iso/html_convert.rb', line 73

def html_toc(docxml)
  super
  docxml.xpath("//div[@id = 'toc']/ul[li[@class = 'h2']]").each do |u|
    html_toc1(u)
  end
  docxml
end

#html_toc1(ulist) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/isodoc/iso/html_convert.rb', line 81

def html_toc1(ulist)
  u2 = nil
  ulist.xpath("./li").each do |l|
    if l["class"] != "h2"
      u2 = nil
    elsif u2 then u2.add_child(l.remove)
    else
      u2 = l.replace("<ul class='content collapse'>#{l}</ul>").first
      p = u2.previous_element and p << u2
    end
  end
end

#html_toc_entry(level, header) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/isodoc/iso/html_convert.rb', line 60

def html_toc_entry(level, header)
  if level == "h1" && header.parent.at(".//h2[not(@class = 'TermNum')]"\
                                       "[not(@class = 'noTOC')][text()]")
    "      <li class=\"\#{level}\"><div class=\"collapse-group\"><a href=\"#\#{header['id']}\">\#{header_strip(header)}</a></li>\n      <div class=\"collapse-button\"></div></div>\n    HDR\n  else\n    %(<li class=\"\#{level}\"><a href=\"#\#{header['id']}\">\\\n\#{header_strip(header)}</a></li>)\n  end\nend\n"

#inject_script(doc) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/isodoc/iso/html_convert.rb', line 94

def inject_script(doc)
  scr = "    <script>\n    $(\".collapse-button\").click(function () {\n    $(this).toggleClass('expand'); // expand: the class to change the collapse button shape\n    // collapse: the class to collapse/expand the li elements with the h2 class\n    $(this).closest('li').children(\".content\").toggleClass('collapse');})\n    </script>\n  HEAD\n  a = super.split(%r{</body>})\n  \"\#{a[0]}\#{scr}</body>\#{a[1]}\"\nend\n".freeze

#table_th_center(docxml) ⇒ Object



107
108
109
110
111
# File 'lib/isodoc/iso/html_convert.rb', line 107

def table_th_center(docxml)
  docxml.xpath("//thead//th | //thead//td").each do |th|
    th["style"] += ";text-align:center;vertical-align:middle;"
  end
end