Class: IsoDoc::Plateau::PresentationXMLConvert

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

Instance Method Summary collapse

Methods included from Init

#bibrenderer, #metadata_init, #xref_init

Constructor Details

#initialize(options) ⇒ PresentationXMLConvert

Returns a new instance of PresentationXMLConvert.



7
8
9
10
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 7

def initialize(options)
  @iso = ::IsoDoc::Iso::PresentationXMLConvert.new(options)
  super
end

Instance Method Details

#alt_i18nObject



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

def alt_i18n
  @i18n = @i18n_lg["alt"][:i18n]
  @lang = @i18n_lg["alt"][:lang]
  @script = @i18n_lg["alt"][:script]
end

#alt_i18n_init(i18nyaml) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 18

def alt_i18n_init(i18nyaml)
  @i18n_lg and return
  @i18n_lg = {}
  en = I18n.new("en", "Latn", i18nyaml: i18nyaml || @i18nyaml)
  ja = I18n.new("ja", "Jpan", i18nyaml: i18nyaml || @i18nyaml)
  @i18n_lg["default"] = { i18n: @i18n.dup, lang: @lang, script: @script }
  @i18n_lg["alt"] = if @lang == "ja"
                      { i18n: en, lang: "en", script: "Latn" }
                    else
                      { i18n: ja, lang: "ja", script: "Jpan" }
                    end
end

#anchor_linkend(node, linkend) ⇒ Object



135
136
137
138
139
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 135

def anchor_linkend(node, linkend)
  title_fallback_docid?(node) and
    node["style"] ||= "title"
  super
end

#bibdata_i18n(bib) ⇒ Object



179
180
181
182
183
184
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 179

def bibdata_i18n(bib)
  alt_i18n
  super
  revert_i18n
  super
end

#commentary_title_hdr(elem) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 97

def commentary_title_hdr(elem)
  ret = <<~COMMENTARY
    <p class="CommentaryStandardNumber">#{@meta.get[:docnumber_undated]}
  COMMENTARY
  yr = @meta.get[:docyear] and
    ret += ": <span class='CommentaryEffectiveYear'>#{yr}</span>"
  elem.previous = ret
end

#date_translate(bibdata) ⇒ Object



186
187
188
189
190
191
192
193
194
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 186

def date_translate(bibdata)
  bibdata.xpath(ns("./date[not(@language)]")).each do |d|
    d.next = d.dup
    newdate = date_translate1(d.text)
    d.next.children = newdate
    d.next["language"] = @lang
    @lang == @i18n_lg["default"][:lang] and d.children = newdate
  end
end

#date_translate1(date) ⇒ Object



196
197
198
199
200
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 196

def date_translate1(date)
  if @lang == "en" then date
  else super
  end
end

#dl(docxml) ⇒ Object

Undo JIS encoding of figure and table dl as paragraphs



113
114
115
116
117
118
119
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 113

def dl(docxml)
  docxml.xpath(ns("//dl")).each { |f| dl1(f) }
  docxml.xpath(ns("//table//dl | //figure//dl")).each do |l|
    l.at(ns("./dl")) || l.at("./ancestor::xmlns:dl") and next
    table_key(l)
  end
end

#fmt_origin_cite_full?(elem) ⇒ Boolean

Returns:

  • (Boolean)


172
173
174
175
176
177
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 172

def fmt_origin_cite_full?(elem)
  sem_xml_descendant?(elem) and return
  id = elem["bibitemid"] or return
  @bibitem_lookup[id] or return
  true
end

#i18n_init(lang, script, locale, i18nyaml = nil) ⇒ Object



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

def i18n_init(lang, script, locale, i18nyaml = nil)
  @i18n = super
  alt_i18n_init(i18nyaml)
  @i18n
end

#listsource(elem, ancestor) ⇒ Object



74
75
76
77
78
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 74

def listsource(elem, ancestor)
  source1(elem, ancestor)
  elem.parent or return
  elem.parent.next = elem.remove
end

#middle_title(docxml) ⇒ Object



80
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 80

def middle_title(docxml); end

#ol_depth(node) ⇒ Object

revert to iso



107
108
109
110
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 107

def ol_depth(node)
  depth = node.ancestors("ul, ol").size + 1
  @counter.ol_type(node, depth) # defined in Xref::Counter
end

#parasource(elem) ⇒ Object



67
68
69
70
71
72
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 67

def parasource(elem)
  source1(elem, :para)
  # if we haven't already removed it...
  elem.parent or return
  elem.parent.next = elem.remove
end

#preface_init_insert_pt(docxml) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 50

def preface_init_insert_pt(docxml)
  ret = docxml.at(ns("//preface")) ||
    docxml.at(ns("//sections | //annex | //bibliography"))
      &.add_previous_sibling("<preface> </preface>")&.first
  ret.nil? and return nil
  ret.children.empty? and ret << " "
  ret
end

#rearrange_clauses(docxml) ⇒ Object



82
83
84
85
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 82

def rearrange_clauses(docxml)
  super
  revhistory(docxml)
end

#revert_i18nObject



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

def revert_i18n
  @i18n = @i18n_lg["default"][:i18n]
  @lang = @i18n_lg["default"][:lang]
  @script = @i18n_lg["default"][:script]
end

#revhistory(docxml) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 87

def revhistory(docxml)
  a = docxml.at(ns("//clause[@type = 'revhistory']"))&.remove or return
  pref = preface_init_insert_pt(docxml) or return nil
  ins = if b = pref.at(ns("./abstract[last()]"))
          b.after(" ").next
        else pref.children.first
        end
  ins.previous = a
end

#short_style_origin(docxml) ⇒ Object



165
166
167
168
169
170
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 165

def short_style_origin(docxml)
  docxml.xpath(ns("//fmt-origin")).each do |o|
    xref_empty?(o) or next
    fmt_origin_cite_full?(o) and o["style"] ||= "reference-tag"
  end
end

#source_join_delim(_elem) ⇒ Object



157
158
159
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 157

def source_join_delim(_elem)
  @lang == "ja" ? "" : "/"
end

#source_types(docxml) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 59

def source_types(docxml)
  super
  docxml.xpath(ns("//p/fmt-source")).each { |f| parasource(f) }
  docxml.xpath(ns("//ul/fmt-source")).each { |f| listsource(f, :ul) }
  docxml.xpath(ns("//ol/fmt-source")).each { |f| listsource(f, :ol) }
  docxml.xpath(ns("//dl/fmt-source")).each { |f| listsource(f, :dl) }
end

#table_key(node) ⇒ Object

Insert localised colon at start of dd in table and figure key, replacing JIS Word

<p class='dl' id='#{dt['id']}'>#{term}: #{bkmk}#{defn}</p>

with

<dt>{term}</dt> <dd>: {defn}<dd>

Space should be stripped and the colon double-width for Japanese text



127
128
129
130
131
132
133
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 127

def table_key(node)
  node.xpath(ns(".//dd")).each do |dd|
    text_node = dd.xpath(".//text()[normalize-space()]").first or next
    colon = %w(zh ja ko).include?(@lang) ? "" : ": "
    text_node.previous = "<span class='fmt-dt-delim'>#{colon}</span>"
  end
end

#termsource_join_delim(_elem) ⇒ Object



153
154
155
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 153

def termsource_join_delim(_elem)
  @lang == "ja" ? "" : "/"
end

#termsource_mod_text_delim(_elem) ⇒ Object



161
162
163
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 161

def termsource_mod_text_delim(_elem)
  @lang == "ja" ? "" : ", "
end

#title_fallback_docid?(elem) ⇒ Boolean

if we are falling back to a title identifier for citation, cite title-style, which gives us title marks

Returns:

  • (Boolean)


143
144
145
146
147
148
149
150
151
# File 'lib/isodoc/plateau/presentation_xml_convert.rb', line 143

def title_fallback_docid?(elem)
  sem_xml_descendant?(elem) and return
  id = elem["bibitemid"] or return
  b = @bibitem_lookup[id] or return
  x = <<~XPATH
    ./docidentifier[not(#{SERIAL_NUM_DOCID} or @scope = 'biblio-tag' or @type = 'metanorma' or @type = 'metanorma-ordinal' or @type='title')]
  XPATH
  !b.at(ns(x)) && b.at(ns("./docidentifier[@type='title']"))
end

#toc_title_insert_pt(docxml) ⇒ Object



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

def toc_title_insert_pt(docxml)
  i = preface_init_insert_pt(docxml) or return nil
  a = i.at(ns("./abstract[last()] | ./clause[@type = 'revhistory']")) and
    return a.after(" ").next
  i.children.first
end