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, #requirements_processor, #std_docid_semantic, #std_docid_semantic_full, #xref_init

Methods included from BaseConvert

#admonition_class, #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
  <<~HEAD.freeze
    <link href="https://fonts.googleapis.com/css?family=Space+Mono:400,400i,700,700i&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,900" rel="stylesheet">
  HEAD
end

#html_toc(docxml) ⇒ Object



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

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



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

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
72
73
# File 'lib/isodoc/iso/html_convert.rb', line 60

def html_toc_entry(level, header)
  content = header.at("./following-sibling::p"\
                      "[@class = 'variant-title-toc']") || header
  if level == "h1" &&
      header.parent.at(".//h2#{toc_exclude_class}")
    <<~HDR
      <li class="#{level}"><div class="collapse-group"><a href="##{header['id']}">#{header_strip(content)}</a>
      <div class="collapse-button"></div></div></li>
    HDR
  else
    %(<li class="#{level}"><a href="##{header['id']}">\
#{header_strip(content)}</a></li>)
  end
end

#inject_script(doc) ⇒ Object



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

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

#ol_attrs(node) ⇒ Object



115
116
117
118
# File 'lib/isodoc/iso/html_convert.rb', line 115

def ol_attrs(node)
  ret = super
  ret.merge(class: OL_STYLE.invert[ret[:type]])
end

#table_th_center(docxml) ⇒ Object



109
110
111
112
113
# File 'lib/isodoc/iso/html_convert.rb', line 109

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