Class: IsoDoc::Iho::PresentationXMLConvert

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

Constant Summary collapse

UPDATE_RELATIONS =
<<~XPATH.freeze
  //bibdata/relation[@type = 'updatedBy' or @type = 'merges' or @type = 'splits' or @type = 'hasDraft']/bibitem
XPATH

Instance Method Summary collapse

Methods included from Init

#bibrenderer, #i18n_init, #info, #metadata_init, #xref_init

Instance Method Details

#biblio_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn, _bib) ⇒ Object



13
14
15
16
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 13

def biblio_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn,
_bib)
  "[#{ordinal}]<tab/>"
end

#bibliography_bibitem_tag1(ref, idx, norm) ⇒ Object



153
154
155
156
157
158
159
160
161
162
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 153

def bibliography_bibitem_tag1(ref, idx, norm)
  ref.xpath(ns("./bibitem")).each do |b|
    implicit_reference(b) and next
    # display ordinal biblio tags whatever the supress-identifier status
    # b["suppress_identifier"] == "true" and next
    idx += 1 unless b["hidden"]
    insert_biblio_tag(b, idx, !norm, standard?(b))
  end
  idx
end

#clausedelimObject



145
146
147
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 145

def clausedelim
  ""
end

#collapse_term(docxml) ⇒ Object



134
135
136
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 134

def collapse_term(docxml)
  docxml.xpath(ns("//term")).each { |t| collapse_term1(t) }
end

#collapse_term1(term) ⇒ Object



138
139
140
141
142
143
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 138

def collapse_term1(term)
  defn = term.at(ns("./fmt-definition")) or return
  source = term.at(ns("./fmt-termsource")) or return
  defn.elements.last << source.children
  source.remove
end

#ddMMMyyyy(isodate) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 100

def ddMMMyyyy(isodate)
  isodate.nil? and return nil
  arr = isodate.split("-")
  if arr.size == 1 && (/^\d+$/.match isodate)
    Date.new(*arr.map(&:to_i)).strftime("%Y")
  elsif arr.size == 2
    Date.new(*arr.map(&:to_i)).strftime("%B %Y")
  else
    Date.parse(isodate).strftime("%d %B %Y")
  end
end

#dochistory(docxml) ⇒ Object



30
31
32
33
34
35
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 30

def dochistory(docxml)
  updates = docxml.xpath(ns(UPDATE_RELATIONS))
  updates.empty? and return
  pref = preface_insert_point(docxml)
  generate_dochistory(updates, pref)
end

#dochistory_contributor(contrib) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 78

def dochistory_contributor(contrib)
  ret = contrib.at(ns("./organization/abbreviation")) ||
    contrib.at(ns("./organization/subdivision")) ||
    contrib.at(ns("./organization/name")) ||
    contrib.at(ns("./person/name/abbreviation")) ||
    contrib.at(ns("./person/name/completename"))
  ret and return ret.text
  format_personalname(contrib)
end

#dochistory_contributors(item) ⇒ Object



72
73
74
75
76
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 72

def dochistory_contributors(item)
  item.xpath(ns("./contributor")).map do |c|
    dochistory_contributor(c)
  end.join(", ")
end

#dochistory_date(item) ⇒ Object



65
66
67
68
69
70
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 65

def dochistory_date(item)
  d = item.at(ns("./date[@type = 'updated']")) ||
    item.at(ns("./date[@type = 'published']")) ||
    item.at(ns("./date[@type = 'issued']")) or return ""
  ddMMMyyyy(d.text.strip)
end

#dochistory_description(item) ⇒ Object



94
95
96
97
98
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 94

def dochistory_description(item)
  d = item.xpath(ns("./amend/description"))
  d.empty? and return ""
  d.map { |d1| semx_fmt_dup(d1).to_xml }.join("\n")
end

#format_personalname(contrib) ⇒ Object



88
89
90
91
92
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 88

def format_personalname(contrib)
  Relaton::Render::General.new(template: { book: "{{ creatornames }}" })
    .render("<bibitem type='book'>#{contrib.to_xml}</bibitem>",
            embedded: true)
end

#generate_dochistory(updates, pref) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 42

def generate_dochistory(updates, pref)
  ret = updates.map { |u| generate_dochistory_row(u) }.flatten.join("\n")
  pref << <<~XML
    <clause #{add_id_text}>
    <title #{add_id_text}>#{@i18n.dochistory}</title>
    <table #{add_id_text} unnumbered="true"><thead>
    <tr #{add_id_text}><th #{add_id_text}>Version Number</th><th #{add_id_text}>Date</th><th #{add_id_text}>Author</th><th #{add_id_text}>Description</th></tr>
    </thead><tbody>
    #{ret}
    </tbody></table></clause>
  XML
end

#generate_dochistory_row(item) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 55

def generate_dochistory_row(item)
  e = item.at(ns("./edition"))&.text
  date = dochistory_date(item)
  c = dochistory_contributors(item)
  desc = dochistory_description(item)
  <<~XML
    <tr #{add_id_text}><td #{add_id_text}>#{e}</td><td #{add_id_text}>#{date}</td><td #{add_id_text}>#{c}</td><td #{add_id_text}>#{desc}</td></tr>
  XML
end

#middle_title(docxml) ⇒ Object



18
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 18

def middle_title(docxml); end

#norm_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn, _bib) ⇒ Object



9
10
11
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 9

def norm_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn, _bib)
  "[#{ordinal}]<tab/>"
end

#omit_docid_prefix(prefix) ⇒ Object



112
113
114
115
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 112

def omit_docid_prefix(prefix)
  prefix == "IHO" and return true
  super
end

#preface_insert_point(docxml) ⇒ Object



37
38
39
40
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 37

def preface_insert_point(docxml)
  docxml.at(ns("//preface")) || docxml.at(ns("//sections"))
    .add_previous_sibling("<preface> </preface>").first
end

#section(docxml) ⇒ Object



20
21
22
23
24
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 20

def section(docxml)
  dochistory(docxml)
  @xrefs.parse docxml
  super
end

#term1(elem) ⇒ Object



117
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 117

def term1(elem); end

#termcleanup(docxml) ⇒ Object



129
130
131
132
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 129

def termcleanup(docxml)
  collapse_term docxml
  super
end

#termsource1(elem) ⇒ Object



119
120
121
122
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 119

def termsource1(elem)
  elem.parent.nil? and return
  super
end

#termsource_label(elem, sources) ⇒ Object



124
125
126
127
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 124

def termsource_label(elem, sources)
  elem.at("./ancestor::xmlns:term") or return
  elem.replace(l10n("[#{sources}]"))
end

#ul_label_list(_elem) ⇒ Object



149
150
151
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 149

def ul_label_list(_elem)
  %w(&#x2022; &#x2014; &#x6f;)
end