Class: IsoDoc::Iso::PresentationXMLConvert

Inherits:
PresentationXMLConvert
  • Object
show all
Includes:
Init
Defined in:
lib/isodoc/iso/presentation_xml_convert.rb

Overview

A Converter implementation that generates HTML output, and a document schema encapsulation of the document for validation

Instance Method Summary collapse

Methods included from Init

#amd, #clausedelim, #i18n_init, #metadata_init

Constructor Details

#initialize(options) ⇒ PresentationXMLConvert

Returns a new instance of PresentationXMLConvert.



11
12
13
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 11

def initialize(options)
  super
end

Instance Method Details

#annex(isoxml) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 23

def annex(isoxml)
  amd(isoxml) and @suppressheadingnumbers = @oldsuppressheadingnumbers
  super
  isoxml.xpath(ns("//annex//clause | //annex//appendix")).each do |f|
    clause1(f)
  end
  amd(isoxml) and @suppressheadingnumbers = true
end

#clause(docxml) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 99

def clause(docxml)
  docxml.xpath(ns("//clause[not(ancestor::annex)] | "\
                  "//terms | //definitions | //references | "\
                  "//preface/introduction[clause]")).
  each do |f|
    clause1(f)
  end
end

#clause1(f) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 91

def clause1(f)
  if !f.at(ns("./title")) &&
      !%w(sections preface bibliography).include?(f.parent.name)
    f["inline-header"] = "true"
  end
  super
end

#convert1(docxml, filename, dir) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 15

def convert1(docxml, filename, dir)
  if amd(docxml)
    @oldsuppressheadingnumbers = @suppressheadingnumbers
    @suppressheadingnumbers = true
  end
  super
end

#eref_localities1(target, type, from, to, delim, lang = "en") ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 63

def eref_localities1(target, type, from, to, delim, lang = "en")
  return "" if type == "anchor"
  subsection = from&.text&.match(/\./)
  type = type.downcase
  lang == "zh" and
    return l10n(eref_localities1_zh(target, type, from, to, delim))
  ret = (delim == ";") ? ";" : (type == "list") ? "" : delim
  loc = @i18n.locality[type] || type.sub(/^locality:/, "").capitalize
  ret += " #{loc}" unless subsection && type == "clause" ||
    type == "list" || target.match(/^IEV$|^IEC 60050-/)
  ret += " #{from.text}" if from
  ret += "–#{to.text}" if to
  ret += ")" if type == "list"
  l10n(ret)
end

#eref_localities1_zh(target, type, from, to, delim) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 51

def eref_localities1_zh(target, type, from, to, delim)
  subsection = from&.text&.match(/\./)
  ret = (delim == ";") ? ";" : (type == "list") ? "" : delim
  ret += "#{from.text}" if from
  ret += "–#{to.text}" if to
  loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize )
  ret += " #{loc}" unless subsection && type == "clause" ||
    type == "list" || target.match(/^IEV$|^IEC 60050-/)
  ret += ")" if type == "list"
  ret
end

#example1(f) ⇒ Object



44
45
46
47
48
49
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 44

def example1(f)
  n = @xrefs.get[f["id"]]
  lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @i18n.example :
    l10n("#{@i18n.example} #{n[:label]}")
  prefix_name(f, " — ", lbl, "name")
end

#example_span_label(node, div, name) ⇒ Object



84
85
86
87
88
89
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 84

def example_span_label(node, div, name)
  return if name.nil?
  div.span **{ class: "example_label" } do |p|
    name.children.each { |n| parse(n, div) }
  end
end

#figure1(f) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 36

def figure1(f)
  return if labelled_ancestor(f) && f.ancestors("figure").empty?
  lbl = @xrefs.anchor(f['id'], :label, false) or return
  figname = f.parent.name == "figure" ? "" : "#{@i18n.figure} "
  connective = f.parent.name == "figure" ? "  " : " — "
  prefix_name(f, connective, l10n("#{figname}#{lbl}"), "name")
end

#prefix_container(container, linkend, target) ⇒ Object



79
80
81
82
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 79

def prefix_container(container, linkend, target)
  delim = @xrefs.anchor(target, :type) == "listitem" ? " " : ", "
  l10n(@xrefs.anchor(container, :xref) + delim + linkend)
end

#xref_init(lang, script, klass, labels, options) ⇒ Object



32
33
34
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 32

def xref_init(lang, script, klass, labels, options)
  @xrefs = Xref.new(lang, script, klass, labels, options)
end