Class: IsoDoc::Iso::PresentationXMLConvert
- Inherits:
-
PresentationXMLConvert
- Object
- PresentationXMLConvert
- IsoDoc::Iso::PresentationXMLConvert
show all
- Includes:
- Init
- Defined in:
- lib/isodoc/iso/index.rb,
lib/isodoc/iso/presentation_xref.rb,
lib/isodoc/iso/presentation_terms.rb,
lib/isodoc/iso/presentation_bibdata.rb,
lib/isodoc/iso/presentation_xml_convert.rb
Constant Summary
collapse
- LOCALITY2SPAN =
ISO has not bothered to communicate to us what most of these span classes mean
{
annex: "citeapp",
dunno: "citebase",
dunno2: "citebib",
dunno3: "citebox",
dunno4: "citeen",
dunno5: "citeeq",
figure: "citefig",
dunno6: "citefn",
clause: "citesec",
dunno7: "citesection",
table: "citetbl",
dunno8: "citetfn",
}.freeze
Instance Method Summary
collapse
-
#add_id ⇒ Object
-
#admonition1(elem) ⇒ Object
-
#admonition_name(xml) ⇒ Object
-
#also_lbl ⇒ Object
-
#anchor_linkend1(node) ⇒ Object
-
#anchor_value(id) ⇒ Object
-
#annex(isoxml) ⇒ Object
-
#bibdata(docxml) ⇒ Object
-
#bibdata_i18n(bib) ⇒ Object
-
#bibdata_i18n_stage(bib, stage, type, lang: @lang, i18n: @i18n) ⇒ Object
-
#bibrender_formattedref(formattedref, xml) ⇒ Object
-
#bibrenderer ⇒ Object
-
#block(docxml) ⇒ Object
-
#can_conflate_eref_rendering?(refs) ⇒ Boolean
-
#clause(docxml) ⇒ Object
-
#clause1(node) ⇒ Object
-
#concept(docxml) ⇒ Object
-
#concept1(node) ⇒ Object
-
#concept1_ref_content(ref) ⇒ Object
-
#concept_term(docxml) ⇒ Object
-
#concept_term1(node, seen) ⇒ Object
-
#convert1(docxml, filename, dir) ⇒ Object
-
#display_order(docxml) ⇒ Object
we’re assuming terms and clauses in the right place for display, to cope with multiple terms sections.
-
#editorialgroup_identifier(docxml) ⇒ Object
-
#editorialgroup_identifier1(group) ⇒ Object
-
#editorialgroup_identifier2(group, level) ⇒ Object
-
#eref_delim(delim, type) ⇒ Object
-
#eref_localities1(opt) ⇒ Object
-
#eref_localities1_zh(opt) ⇒ Object
-
#eref_localities_conflated(refs, target, node) ⇒ Object
-
#example1(node) ⇒ Object
-
#example_span_label(_node, div, name) ⇒ Object
-
#expand_citeas(text) ⇒ Object
-
#extract_indexsee(val, terms, label) ⇒ Object
-
#extract_indexterms(terms) ⇒ Object
attributes are decoded into UTF-8, elements in extract_indexsee are still in entities.
-
#extract_indexterms_init(term) ⇒ Object
-
#figure1(node) ⇒ Object
-
#formula_where(dlist) ⇒ Object
-
#formula_where_one(dlist) ⇒ Object
-
#index(xml) ⇒ Object
-
#index1(docxml, indexsect, index) ⇒ Object
-
#index1_cleanup(docxml) ⇒ Object
-
#index2bookmark(node) ⇒ Object
-
#index_entries(words, index, primary) ⇒ Object
-
#index_entries2(words, index, secondary) ⇒ Object
-
#index_entries_head(head, entries, opt) ⇒ Object
-
#index_entries_opt ⇒ Object
-
#index_entries_see(entries, label) ⇒ Object
-
#insertall_after_here(node, insert, name) ⇒ Object
-
#locality_delimiter(loc) ⇒ Object
-
#locality_span_wrap(ret, type) ⇒ Object
-
#note1(elem) ⇒ Object
-
#ol_depth(node) ⇒ Object
-
#prefix_clause(target, loc) ⇒ Object
-
#prefix_container(container, linkend, node, target) ⇒ Object
-
#prefix_domain_to_definition(elem) ⇒ Object
-
#related1(node) ⇒ Object
-
#see_lbl ⇒ Object
-
#sort_indexterms(terms, see, also) ⇒ Object
-
#sortable(str) ⇒ Object
-
#subclause?(target, type, from) ⇒ Boolean
-
#term_hash_init(hash, term, term2, term3, label) ⇒ Object
-
#termdefinition1(elem) ⇒ Object
-
#termexamples_before_termnotes(node) ⇒ Object
-
#terms(docxml) ⇒ Object
-
#termsource_status(status) ⇒ Object
-
#toc_title(docxml) ⇒ Object
-
#warning_for_missing_metadata(docxml) ⇒ Object
-
#warning_for_missing_metadata_create(docxml) ⇒ Object
-
#warning_for_missing_metadata_post(docxml, ret) ⇒ Object
-
#xml_encode_attr(str) ⇒ Object
-
#xref_init(lang, script, klass, labels, options) ⇒ Object
Methods included from Init
#amd, #clausedelim, #i18n_init, #metadata_init, #requirements_processor, #std_docid_semantic, #std_docid_semantic1, #std_docid_semantic_full
Instance Method Details
#add_id ⇒ Object
4
5
6
|
# File 'lib/isodoc/iso/index.rb', line 4
def add_id
%(id="_#{UUIDTools::UUID.random_create}")
end
|
#admonition1(elem) ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 105
def admonition1(elem)
super
n = elem.at(ns("./name")) or return
if (p = n.next_element) && p&.name == "p"
p.children.first.previous = admonition_name(to_xml(n.remove.children))
end
end
|
#admonition_name(xml) ⇒ Object
113
114
115
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 113
def admonition_name(xml)
"#{xml} — "
end
|
#also_lbl ⇒ Object
112
113
114
|
# File 'lib/isodoc/iso/index.rb', line 112
def also_lbl
@lang == "en" ? @i18n.see_also : "<em>#{@i18n.see_also}</em>"
end
|
#anchor_linkend1(node) ⇒ Object
131
132
133
134
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 131
def anchor_linkend1(node)
locality_span_wrap(super, @xrefs.anchor(node["target"], :subtype) ||
@xrefs.anchor(node["target"], :type))
end
|
#anchor_value(id) ⇒ Object
126
127
128
129
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 126
def anchor_value(id)
locality_span_wrap(super, @xrefs.anchor(id, :subtype) ||
@xrefs.anchor(id, :type))
end
|
#annex(isoxml) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 40
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
|
#bibdata(docxml) ⇒ Object
4
5
6
7
8
|
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 4
def bibdata(docxml)
super
editorialgroup_identifier(docxml)
warning_for_missing_metadata(docxml)
end
|
#bibdata_i18n(bib) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 64
def bibdata_i18n(bib)
hash_translate(bib, @i18n.get["doctype_dict"], "./ext/doctype")
bibdata_i18n_stage(bib, bib.at(ns("./status/stage")),
bib.at(ns("./ext/doctype")))
hash_translate(bib, @i18n.get["substage_dict"],
"./status/substage")
edition_translate(bib)
end
|
#bibdata_i18n_stage(bib, stage, type, lang: @lang, i18n: @i18n) ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 73
def bibdata_i18n_stage(bib, stage, type, lang: @lang, i18n: @i18n)
return unless stage
i18n.get["stage_dict"][stage.text].is_a?(Hash) or
return hash_translate(bib, i18n.get["stage_dict"],
"./status/stage", lang)
stagetype = i18n.get["stage_dict"][stage.text][type&.text] and
tag_translate(stage, lang, stagetype)
end
|
122
123
124
125
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 122
def bibrender_formattedref(formattedref, xml)
%w(techreport standard).include? xml["type"] and return
super
end
|
#bibrenderer ⇒ Object
117
118
119
120
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 117
def bibrenderer
::Relaton::Render::Iso::General.new(language: @lang,
i18nhash: @i18n.get)
end
|
#block(docxml) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 21
def block(docxml)
amend docxml
figure docxml
sourcecode docxml
formula docxml
admonition docxml
source docxml
ol docxml
permission docxml
requirement docxml
recommendation docxml
requirement_render docxml
@xrefs.anchors_previous = @xrefs.anchors.dup @xrefs.parse docxml
table docxml example docxml
note docxml
end
|
#can_conflate_eref_rendering?(refs) ⇒ Boolean
14
15
16
17
18
19
20
21
22
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 14
def can_conflate_eref_rendering?(refs)
super or return false
first = subclause?(nil, refs.first.at(ns("./locality/@type"))&.text,
refs.first.at(ns("./locality/referenceFrom"))&.text)
refs.all? do |r|
subclause?(nil, r.at(ns("./locality/@type"))&.text,
r.at(ns("./locality/referenceFrom"))&.text) == first
end
end
|
#clause(docxml) ⇒ Object
80
81
82
83
84
85
86
87
88
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 80
def clause(docxml)
docxml.xpath(ns("//clause[not(ancestor::annex)] | " \
"//terms | //definitions | //references | " \
"//preface/introduction[clause]")).each do |f|
f.parent.name == "annex" &&
@xrefs.klass.single_term_clause?(f.parent) and next
clause1(f)
end
end
|
#clause1(node) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 72
def clause1(node)
if !node.at(ns("./title")) &&
!%w(sections preface bibliography).include?(node.parent.name)
node["inline-header"] = "true"
end
super
end
|
#concept(docxml) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 11
def concept(docxml)
concept_term(docxml)
docxml.xpath(ns("//concept")).each do |node|
concept_render(node, ital: "false", ref: "false",
linkref: "true", linkmention: "false")
end
end
|
#concept1(node) ⇒ Object
49
50
51
52
53
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 49
def concept1(node)
node.replace(node&.at(ns("./renderterm"))&.children ||
node&.at(ns("./refterm"))&.children ||
node.children)
end
|
#concept1_ref_content(ref) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 39
def concept1_ref_content(ref)
prev = "("
foll = ")"
if ref.name == "termref"
prev, foll = @i18n.term_defined_in.split("%")
end
ref.previous = prev
ref.next = foll
end
|
#concept_term(docxml) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 19
def concept_term(docxml)
docxml.xpath(ns("//term")).each do |f|
m = {}
(f.xpath(ns(".//concept")) - f.xpath(ns(".//term//concept")))
.each { |c| concept_term1(c, m) }
end
end
|
#concept_term1(node, seen) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 27
def concept_term1(node, seen)
term = to_xml(node.at(ns("./refterm")))
if term && seen[term]
concept_render(node, ital: "false", ref: "false",
linkref: "true", linkmention: "false")
else concept_render(node, ital: "true", ref: "true",
linkref: "true", linkmention: "false")
end
seen[term] = true if term
seen
end
|
#convert1(docxml, filename, dir) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 12
def convert1(docxml, filename, dir)
@iso_class = instance_of?(IsoDoc::Iso::PresentationXMLConvert)
if amd(docxml)
@oldsuppressheadingnumbers = @suppressheadingnumbers
@suppressheadingnumbers = true
end
super
end
|
#display_order(docxml) ⇒ Object
we’re assuming terms and clauses in the right place for display, to cope with multiple terms sections
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 92
def display_order(docxml)
i = 0
i = display_order_xpath(docxml, "//preface/*", i)
i = display_order_at(docxml, "//clause[@type = 'scope']", i)
i = display_order_at(docxml, @xrefs.klass.norm_ref_xpath, i)
i = display_order_xpath(docxml,
"//sections/clause[not(@type = 'scope')] | " \
"//sections/terms | //sections/definitions", i)
i = display_order_xpath(docxml, "//annex", i)
i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
display_order_xpath(docxml, "//indexsect", i)
end
|
#editorialgroup_identifier(docxml) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 40
def editorialgroup_identifier(docxml)
%w(editorialgroup approvalgroup).each do |v|
docxml.xpath(ns("//bibdata/ext/#{v}")).each do |a|
editorialgroup_identifier1(a)
end
end
end
|
#editorialgroup_identifier1(group) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 48
def editorialgroup_identifier1(group)
agency = group.xpath(ns("./agency"))&.map(&:text)
ret = %w(technical-committee subcommittee workgroup)
.each_with_object([]) do |v, m|
m << editorialgroup_identifier2(group, v)
end
group["identifier"] = (agency + ret.compact).join("/")
end
|
#editorialgroup_identifier2(group, level) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 57
def editorialgroup_identifier2(group, level)
a = group.at(ns("./#{level}")) or return nil
type = a["type"]
type&.casecmp("other")&.zero? and type = ""
"#{type} #{a['number']}".strip
end
|
#eref_delim(delim, type) ⇒ Object
8
9
10
11
12
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 8
def eref_delim(delim, type)
if delim == ";" then ";"
else type == "list" ? " " : delim
end
end
|
#eref_localities1(opt) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 92
def eref_localities1(opt)
return nil if opt[:type] == "anchor"
opt[:type] = opt[:type].downcase
opt[:lang] == "zh" and return l10n(eref_localities1_zh(opt))
ret = ""
opt[:node]["droploc"] != "true" &&
!subclause?(opt[:target], opt[:type], opt[:from]) and
ret = eref_locality_populate(opt[:type], opt[:node], opt[:number])
ret += " #{opt[:from]}" if opt[:from]
ret += "–#{opt[:upto]}" if opt[:upto]
ret += ")" if opt[:type] == "list"
ret = l10n(ret)
locality_span_wrap(ret, opt[:type])
end
|
#eref_localities1_zh(opt) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 82
def eref_localities1_zh(opt)
ret = " 第#{opt[:from]}" if opt[:from]
ret += "–#{opt[:upto]}" if opt[:upto]
opt[:node]["droploc"] != "true" &&
!subclause?(opt[:target], opt[:type], opt[:from]) and
ret += eref_locality_populate(opt[:type], opt[:node], "sg")
ret += ")" if opt[:type] == "list"
locality_span_wrap(ret, opt[:type])
end
|
#eref_localities_conflated(refs, target, node) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 29
def eref_localities_conflated(refs, target, node)
droploc = node["droploc"]
node["droploc"] = true
ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
node))
node["droploc"] = droploc
eref_localities1({ target: target, number: "pl",
type: prefix_clause(target, refs.first.at(ns("./locality"))),
from: l10n(ret[1..-1].join),
node: node, lang: @lang })
end
|
#example1(node) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 56
def example1(node)
n = @xrefs.get[node["id"]]
lbl = if n.nil? || blank?(n[:label]) then @i18n.example
else l10n("#{@i18n.example} #{n[:label]}")
end
prefix_name(node, block_delim, lbl, "name")
end
|
#example_span_label(_node, div, name) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 64
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
|
#expand_citeas(text) ⇒ Object
122
123
124
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 122
def expand_citeas(text)
std_docid_semantic(super)
end
|
126
127
128
129
130
131
132
133
|
# File 'lib/isodoc/iso/index.rb', line 126
def (val, terms, label)
terms.each_with_object(val) do |t, v|
term, term2, term3 = (t)
term_hash_init(v, term, term2, term3, label)
v[term][term2][term3][label] << to_xml(t.at(ns("./target"))&.children)
t.remove
end
end
|
attributes are decoded into UTF-8, elements in extract_indexsee are still in entities
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/isodoc/iso/index.rb', line 144
def (terms)
terms.each_with_object({}) do |t, v|
term, term2, term3 = (t)
index2bookmark(t)
term_hash_init(v, term, term2, term3, :xref)
to = t["to"] ? "to='#{t['to']}' " : ""
v[term][term2][term3][:xref] << "<xref target='#{t['id']}' "\
"#{to}pagenumber='true'/>"
end
end
|
155
156
157
158
159
|
# File 'lib/isodoc/iso/index.rb', line 155
def (term)
%w(primary secondary tertiary).each_with_object([]) do |x, m|
m << to_xml(term.at(ns("./#{x}"))&.children)
end
end
|
49
50
51
52
53
54
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 49
def figure1(node)
lbl = @xrefs.anchor(node["id"], :label, false) or return
figname = node.parent.name == "figure" ? "" : "#{@i18n.figure} "
connective = node.parent.name == "figure" ? "  " : " — "
prefix_name(node, connective, l10n("#{figname}#{lbl}"), "name")
end
|
142
143
144
145
146
147
148
149
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 142
def formula_where(dlist)
dlist.nil? and return
return super unless dlist.xpath(ns("./dt")).size == 1 &&
dlist.at(ns("./dd"))&.elements&.size == 1 &&
dlist.at(ns("./dd/p"))
formula_where_one(dlist)
end
|
151
152
153
154
155
156
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 151
def formula_where_one(dlist)
dt = to_xml(dlist.at(ns("./dt")).children)
dd = to_xml(dlist.at(ns("./dd/p")).children)
dlist.previous = "<p>#{@i18n.where_one} #{dt} #{dd}</p>"
dlist.remove
end
|
#index(xml) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/isodoc/iso/index.rb', line 8
def index(xml)
if xml.at(ns("//index"))
i = xml.at(ns("//indexsect")) ||
xml.root.add_child("<indexsect #{add_id}><title>#{@i18n.index}"\
"</title></indexsect>").first
index = sort_indexterms(xml.xpath(ns("//index")),
xml.xpath(ns("//index-xref[@also = 'false']")),
xml.xpath(ns("//index-xref[@also = 'true']")))
index1(xml, i, index)
else xml.xpath(ns("//indexsect")).each(&:remove)
end
end
|
#index1(docxml, indexsect, index) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/isodoc/iso/index.rb', line 21
def index1(docxml, indexsect, index)
c = indexsect.add_child("<ul></ul>").first
index.keys.sort.each do |k|
words = index[k].keys.each_with_object({}) do |w, v|
v[sortable(w).downcase] = w
end
words.keys.localize(@lang.to_sym).sort.to_a.each do |w|
c.add_child index_entries(words, index[k], w)
end
end
index1_cleanup(docxml)
end
|
#index1_cleanup(docxml) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/isodoc/iso/index.rb', line 34
def index1_cleanup(docxml)
docxml.xpath(ns("//indexsect//xref")).each do |x|
x.children.remove
end
@xrefs.bookmark_anchor_names(docxml)
end
|
#index2bookmark(node) ⇒ Object
168
169
170
171
172
|
# File 'lib/isodoc/iso/index.rb', line 168
def index2bookmark(node)
node.name = "bookmark"
node.children.each(&:remove)
node["id"] = "_#{UUIDTools::UUID.random_create}"
end
|
#index_entries(words, index, primary) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/isodoc/iso/index.rb', line 49
def index_entries(words, index, primary)
ret = index_entries_head(words[primary],
index.dig(words[primary], nil, nil),
index_entries_opt)
words2 = index[words[primary]]&.keys&.reject do |k|
k.nil?
end&.each_with_object({}) { |w, v| v[w.downcase] = w }
unless words2.empty?
ret += "<ul>"
words2.keys.localize(@lang.to_sym).sort.to_a.each do |w|
ret += index_entries2(words2, index[words[primary]], w)
end
ret += "</ul>"
end
"#{ret}</li>"
end
|
#index_entries2(words, index, secondary) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/isodoc/iso/index.rb', line 66
def index_entries2(words, index, secondary)
ret = index_entries_head(words[secondary],
index.dig(words[secondary], nil),
index_entries_opt)
words3 = index[words[secondary]]&.keys&.reject do |k|
k.nil?
end&.each_with_object({}) { |w, v| v[w.downcase] = w }
unless words3.empty?
ret += "<ul>"
words3.keys.localize(@lang.to_sym).sort.to_a.each do |w|
ret += (index_entries_head(words3[w],
index[words[secondary]][words3[w]],
index_entries_opt) + "</li>")
end
ret += "</ul>"
end
"#{ret}</li>"
end
|
#index_entries_head(head, entries, opt) ⇒ Object
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/isodoc/iso/index.rb', line 85
def index_entries_head(head, entries, opt)
ret = "<li>#{head}"
xref = entries&.dig(:xref)&.join(", ")
see = index_entries_see(entries, :see)
also = index_entries_see(entries, :also)
ret += "#{opt[:xref_lbl]} #{xref}" if xref
ret += "#{opt[:see_lbl]} #{see}" if see
ret += "#{opt[:also_lbl]} #{also}" if also
ret
end
|
#index_entries_opt ⇒ Object
45
46
47
|
# File 'lib/isodoc/iso/index.rb', line 45
def index_entries_opt
{ xref_lbl: ", ", see_lbl: ", #{see_lbl}", also_lbl: ", #{also_lbl}" }
end
|
#index_entries_see(entries, label) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/isodoc/iso/index.rb', line 96
def index_entries_see(entries, label)
see_sort = entries&.dig(label) or return nil
x = see_sort.each_with_object({}) do |w, v|
v[sortable(w).downcase] = w
end
x.keys.localize(@lang.to_sym).sort.to_a.map do |k|
x[k]
end.join(", ")
end
|
#insertall_after_here(node, insert, name) ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 68
def insertall_after_here(node, insert, name)
node.children.each do |n|
n.name == name or next
insert.next = n.remove
insert = n
end
insert
end
|
#locality_delimiter(loc) ⇒ Object
24
25
26
27
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 24
def locality_delimiter(loc)
loc&.next_element&.attribute("type")&.text == "list" and return " "
super
end
|
#locality_span_wrap(ret, type) ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 73
def locality_span_wrap(ret, type)
type or return ret
m = /^(\s*)(.+?)(\s*)$/.match(ret) or return ret
ret = [m[1], m[2], m[3]]
spanclass = LOCALITY2SPAN[type.to_sym] and
ret[1] = "<span class='#{spanclass}'>#{ret[1]}</span>"
ret.join
end
|
#note1(elem) ⇒ Object
137
138
139
140
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 137
def note1(elem)
elem["type"] == "units" and return
super
end
|
#ol_depth(node) ⇒ Object
127
128
129
130
131
132
133
134
135
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 127
def ol_depth(node)
depth = node.ancestors(@iso_class ? "ol" : "ul, ol").size + 1
type = :alphabet
type = :arabic if [2, 7].include? depth
type = :roman if [3, 8].include? depth
type = :alphabet_upper if [4, 9].include? depth
type = :roman_upper if [5, 10].include? depth
type
end
|
#prefix_clause(target, loc) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 41
def prefix_clause(target, loc)
loc["type"] == "clause" or return loc["type"]
if subclause?(target, loc["type"],
loc&.at(ns("./referenceFrom"))&.text)
""
else "clause"
end
end
|
#prefix_container(container, linkend, node, target) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 108
def prefix_container(container, linkend, node, target)
delim = ", "
ref = if @xrefs.anchor(target, :type) == "listitem" &&
!@xrefs.anchor(target, :refer_list)
delim = " "
@xrefs.anchor(container, :label)
else anchor_xref(node, container)
end
ref and linkend = ref + delim + linkend
l10n(linkend)
end
|
#prefix_domain_to_definition(elem) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 60
def prefix_domain_to_definition(elem)
((d = elem.at(ns("./domain"))) &&
(v = elem.at(ns("./definition/verbal-definition"))) &&
v.elements.first.name == "p") or return
v.elements.first.children.first.previous =
"<#{to_xml(d.remove.children)}> "
end
|
90
91
92
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 90
def related1(node)
node.remove
end
|
#see_lbl ⇒ Object
108
109
110
|
# File 'lib/isodoc/iso/index.rb', line 108
def see_lbl
@lang == "en" ? @i18n.see : "<em>#{@i18n.see}</em>"
end
|
#sort_indexterms(terms, see, also) ⇒ Object
116
117
118
119
120
121
122
123
124
|
# File 'lib/isodoc/iso/index.rb', line 116
def sort_indexterms(terms, see, also)
index = (terms)
index = (index, see, :see)
index = (index, also, :also)
index.keys.sort.each_with_object({}) do |k, v|
v[sortable(k)[0].upcase.transliterate] ||= {}
v[sortable(k)[0].upcase.transliterate][k] = index[k]
end
end
|
#sortable(str) ⇒ Object
41
42
43
|
# File 'lib/isodoc/iso/index.rb', line 41
def sortable(str)
HTMLEntities.new.decode(Nokogiri::XML.fragment(str).text)
end
|
#subclause?(target, type, from) ⇒ Boolean
51
52
53
54
55
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 51
def subclause?(target, type, from)
(from&.match?(/\./) && type == "clause") ||
type == "list" ||
target&.gsub(/<[^>]+>/, "")&.match(/^IEV$|^IEC 60050-/)
end
|
#term_hash_init(hash, term, term2, term3, label) ⇒ Object
161
162
163
164
165
166
|
# File 'lib/isodoc/iso/index.rb', line 161
def term_hash_init(hash, term, term2, term3, label)
hash[term] ||= {}
hash[term][term2] ||= {}
hash[term][term2][term3] ||= {}
hash[term][term2][term3][label] ||= []
end
|
#termdefinition1(elem) ⇒ Object
55
56
57
58
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 55
def termdefinition1(elem)
prefix_domain_to_definition(elem)
super
end
|
#termexamples_before_termnotes(node) ⇒ Object
77
78
79
80
81
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 77
def termexamples_before_termnotes(node)
insert = node.at(ns("./definition")) or return
insert = insertall_after_here(node, insert, "termexample")
insertall_after_here(node, insert, "termnote")
end
|
#terms(docxml) ⇒ Object
83
84
85
86
87
88
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 83
def terms(docxml)
docxml.xpath(ns("//term[termnote][termexample]")).each do |node|
termexamples_before_termnotes(node)
end
super
end
|
#termsource_status(status) ⇒ Object
94
95
96
97
98
99
|
# File 'lib/isodoc/iso/presentation_terms.rb', line 94
def termsource_status(status)
case status
when "modified", "adapted"
@i18n.modified
end
end
|
#toc_title(docxml) ⇒ Object
158
159
160
161
162
|
# File 'lib/isodoc/iso/presentation_xml_convert.rb', line 158
def toc_title(docxml)
doctype = docxml.at(ns("//bibdata/ext/doctype"))&.text
%w(amendment technical-corrigendum).include?(doctype) and return
super
end
|
10
11
12
13
14
15
16
17
|
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 10
def warning_for_missing_metadata(docxml)
return unless @meta.get[:unpublished]
ret = warning_for_missing_metadata_create(docxml)
return if ret.empty?
warning_for_missing_metadata_post(docxml, ret)
end
|
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 19
def warning_for_missing_metadata_create(docxml)
ret = ""
docxml.at(ns("//bibdata/ext//secretariat")) or
ret += "<p>Secretariat is missing.</p>"
docxml.at(ns("//bibdata/ext//editorialgroup")) or
ret += "<p>Editorial groups are missing.</p>"
docxml.at(ns("//bibdata/date[@type = 'published' or @type = 'issued' " \
"or @type = 'created']")) ||
docxml.at(ns("//bibdata/version/revision-date")) or
ret += "<p>Document date is missing.</p>"
ret
end
|
#warning_for_missing_metadata_post(docxml, ret) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/isodoc/iso/presentation_bibdata.rb', line 32
def warning_for_missing_metadata_post(docxml, ret)
id = UUIDTools::UUID.random_create
ret = "<review date='#{Date.today}' reviewer='Metanorma' id='_#{id}'>" \
"<p><strong>Metadata warnings:<strong></p> #{ret}</review>"
ins = docxml.at(ns("//sections//title")) or return
ins.children.first.previous = ret
end
|
#xml_encode_attr(str) ⇒ Object
135
136
137
138
139
140
|
# File 'lib/isodoc/iso/index.rb', line 135
def xml_encode_attr(str)
HTMLEntities.new.encode(str, :basic, :hexadecimal)
.gsub(/&#x([^;]+);/) do |_x|
"&#x#{$1.upcase};"
end
end
|
#xref_init(lang, script, klass, labels, options) ⇒ Object
4
5
6
|
# File 'lib/isodoc/iso/presentation_xref.rb', line 4
def xref_init(lang, script, klass, labels, options)
@xrefs = Xref.new(lang, script, klass, labels, options)
end
|