isodoc 2.7.1 → 2.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3d420c1f407fc9c61f6b5b35b4b6a2da5348eb80331cf1751e09546ceef5669
4
- data.tar.gz: 8861cbd102660ee74d94b5ff367727607fd23ece4c9bca44a468a68b1756a5c9
3
+ metadata.gz: eb9c5b4a4ae20094a096ef37012c56b2f125a636c0aa426d135f1b8257cbf205
4
+ data.tar.gz: a1f5bbeed6904bd7d958ee0fdaeb4b180f0bf5405a42d556f7e787153247130d
5
5
  SHA512:
6
- metadata.gz: 0b7e7eeb5050180c3b14d958a102ec895196783203ea0fe201996a38f9f0bd9137bdd2402f8260671abcbc5e264443e1847c3b1e6b0e465d7cea11e1ff403871
7
- data.tar.gz: 3b591c4f0a8b1359a318ea753f2d1d77efe2dd5e7e903e0a77cad3d40f7318e79a1416ce0958fbafb1d02a43a48f6c29bfd62f5221b14dd943a1470511fe7007
6
+ metadata.gz: a9aa50e9e6b759064321dbb68b46bbe9ab6d321ac73d584aad19b8ecedb109ee48119d06e72c03f7802910946d73ae72e08b24b502d3495d04e7805141de522a
7
+ data.tar.gz: fb4483cd05281ce5278d745c2ecc7f8b73139e1e47a643700c9112747ce475869c570a1555d836277cb6ed90c7d544b43eda21bc6b81a5f08b7470fb14ad8f73
data/isodoc.gemspec CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  # spec.add_dependency "isodoc-i18n", "~> 1.1.0" # already in relaton-render and mn-requirements
34
34
  spec.add_dependency "emf2svg"
35
35
  spec.add_dependency "liquid", "~> 5"
36
- spec.add_dependency "relaton-cli"
36
+ #spec.add_dependency "relaton-cli"
37
37
  # spec.add_dependency "metanorma-utils", "~> 1.5.0" # already in isodoc-i18n
38
38
  spec.add_dependency "mn2pdf"
39
39
  spec.add_dependency "mn-requirements", "~> 0.3.4"
@@ -136,24 +136,21 @@ module IsoDoc
136
136
  end
137
137
 
138
138
  def html_toc_entries(docxml, path)
139
- xml = html_toc_entries_prep(docxml, path)
139
+ headers = html_toc_entries_prep(docxml, path)
140
140
  path.each_with_index.with_object([]) do |(p, i), m|
141
- xml.xpath(p.join(" | ")).each do |h|
141
+ docxml.xpath(p.join(" | ")).each do |h|
142
142
  m << { entry: html_toc_entry("h#{i + 1}", h),
143
- line: h.line }
143
+ line: headers[h["id"]] }
144
144
  end
145
145
  end.sort_by { |k| k[:line] }
146
146
  end
147
147
 
148
148
  def html_toc_entries_prep(docxml, path)
149
- path.each do |p|
150
- docxml.xpath(p.join(" | ")).each do |h|
149
+ docxml.xpath(path.join(" | "))
150
+ .each_with_index.with_object({}) do |(h, i), m|
151
151
  h["id"] ||= "_#{UUIDTools::UUID.random_create}"
152
+ m[h["id"]] = i
152
153
  end
153
- end
154
- xml = Nokogiri::XML(docxml.to_xml, &:noblanks)
155
- xml.remove_namespaces!
156
- xml
157
154
  end
158
155
 
159
156
  def toc_exclude_class
data/lib/isodoc/i18n.rb CHANGED
@@ -7,23 +7,26 @@ module IsoDoc
7
7
  class I18n
8
8
  Hash.include Metanorma::Utils::Hash
9
9
 
10
- def load_yaml1(lang, script)
10
+ def yaml_lang(lang, script)
11
11
  case lang
12
12
  when "en", "fr", "ru", "de", "es", "ar", "ja"
13
- load_yaml2(lang)
13
+ lang
14
14
  when "zh"
15
- if script == "Hans" then load_yaml2("zh-Hans")
16
- else load_yaml2("en")
17
- end
18
- else
19
- load_yaml2("en")
15
+ "#{lang}-#{script}"
20
16
  end
21
17
  end
22
18
 
19
+ def load_yaml1(lang, script)
20
+ load_yaml2(yaml_lang(lang, script))
21
+ end
22
+
23
23
  def load_yaml2(str)
24
- YAML.load_file(File.join(File.dirname(__FILE__),
25
- "../isodoc-yaml/i18n-#{str}.yaml"))
24
+ f = File.join(File.dirname(__FILE__),
25
+ "../isodoc-yaml/i18n-#{str}.yaml")
26
+ File.exist?(f) or
27
+ f = File.join(File.dirname(__FILE__),
28
+ "../isodoc-yaml/i18n-en.yaml")
29
+ YAML.load_file(f)
26
30
  end
27
31
  end
28
32
  end
29
-
@@ -15,16 +15,22 @@ module IsoDoc
15
15
  "</localized-strings>"
16
16
  end
17
17
 
18
- def extension_insert(docxml, path = [])
19
- ins = docxml.at(ns("//metanorma-extension")) ||
20
- docxml.at(ns("//bibdata"))&.after("<metanorma-extension/>")&.next_element ||
21
- docxml.root.elements.first.before("<metanorma-extension/>").previous_element
18
+ def extension_insert(xml, path = [])
19
+ ins = extension_insert_pt(xml)
22
20
  path.each do |n|
23
21
  ins = ins.at(ns("./#{n}")) || ins.add_child("<#{n}/>").first
24
22
  end
25
23
  ins
26
24
  end
27
25
 
26
+ def extension_insert_pt(xml)
27
+ xml.at(ns("//metanorma-extension")) ||
28
+ xml.at(ns("//bibdata"))&.after("<metanorma-extension/>")
29
+ &.next_element ||
30
+ xml.root.elements.first.before("<metanorma-extension/>")
31
+ .previous_element
32
+ end
33
+
28
34
  def preprocess_xslt_insert(docxml)
29
35
  content = ""
30
36
  p = passthrough_xslt and content += p
@@ -39,24 +45,23 @@ module IsoDoc
39
45
  @output_formats.empty? and return nil
40
46
  @output_formats.each_key.with_object([]) do |k, m|
41
47
  m << <<~XSLT
42
- <preprocess-xslt format="#{k}">
43
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
44
- <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
45
- <xsl:strip-space elements="*"/>
46
- <xsl:template match="@* | node()">
47
- <xsl:copy>
48
- <xsl:apply-templates select="@* | node()"/>
49
- </xsl:copy>
50
- </xsl:template>
51
- <xsl:template match="*[local-name() = 'passthrough']">
52
- <xsl:if test="contains(@formats,',#{k},')"> <!-- delimited -->
53
- <xsl:copy>
54
- <xsl:apply-templates select="@* | node()"/>
55
- </xsl:copy>
56
- </xsl:if>
57
- </xsl:template>
58
- </xsl:stylesheet>
59
- </preprocess-xslt>
48
+ <preprocess-xslt format="#{k}">
49
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
50
+ <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
51
+ <xsl:template match="@* | node()">
52
+ <xsl:copy>
53
+ <xsl:apply-templates select="@* | node()"/>
54
+ </xsl:copy>
55
+ </xsl:template>
56
+ <xsl:template match="*[local-name() = 'passthrough']">
57
+ <xsl:if test="contains(@formats,',#{k},')"> <!-- delimited -->
58
+ <xsl:copy>
59
+ <xsl:apply-templates select="@* | node()"/>
60
+ </xsl:copy>
61
+ </xsl:if>
62
+ </xsl:template>
63
+ </xsl:stylesheet>
64
+ </preprocess-xslt>
60
65
  XSLT
61
66
  end.join("\n")
62
67
  end
@@ -67,8 +72,7 @@ module IsoDoc
67
72
  end
68
73
 
69
74
  def toc_metadata(docxml)
70
- return unless @tocfigures || @toctables || @tocrecommendations
71
-
75
+ @tocfigures || @toctables || @tocrecommendations or return
72
76
  ins = extension_insert(docxml)
73
77
  @tocfigures and
74
78
  ins << "<toc type='figure'><title>#{@i18n.toc_figures}</title></toc>"
@@ -89,17 +93,20 @@ module IsoDoc
89
93
  end
90
94
 
91
95
  def fonts_metadata(xmldoc)
92
- return unless @fontist_fonts
93
-
94
- ins = xmldoc.at(ns("//presentation-metadata")) ||
95
- xmldoc.at(ns("//metanorma-extension")) || xmldoc.at(ns("//bibdata"))
96
- CSV.parse_line(@fontist_fonts, col_sep: ";").map(&:strip).each do |f|
96
+ ins = presmeta_insert_pt(xmldoc)
97
+ @fontist_fonts and CSV.parse_line(@fontist_fonts, col_sep: ";")
98
+ .map(&:strip).reverse.each do |f|
97
99
  ins.next = presmeta("fonts", f)
98
100
  end
99
101
  @fontlicenseagreement and
100
102
  ins.next = presmeta("font-license-agreement", @fontlicenseagreement)
101
103
  end
102
104
 
105
+ def presmeta_insert_pt(xmldoc)
106
+ xmldoc.at(ns("//presentation-metadata")) ||
107
+ xmldoc.at(ns("//metanorma-extension")) || xmldoc.at(ns("//bibdata"))
108
+ end
109
+
103
110
  def presmeta(name, value)
104
111
  "<presentation-metadata><name>#{name}</name><value>#{value}</value>" \
105
112
  "</presentation-metadata>"
@@ -140,13 +147,15 @@ module IsoDoc
140
147
  tag_translate(x, lang, hash[x.text])
141
148
  end
142
149
 
143
- # does not allow %Spellout and %Ordinal in the ordinal expression to be mixed
150
+ # does not allow %Spellout and %Ordinal in the ordinal expression
151
+ # to be mixed
144
152
  def edition_translate(bibdata)
145
153
  x = bibdata.at(ns("./edition")) or return
146
154
  /^\d+$/.match?(x.text) or return
155
+ @i18n.edition_ordinal or return
156
+ edn = edition_translate1(x.text.to_i) or return
147
157
  tag_translate(x, @lang,
148
- @i18n.edition_ordinal.sub(/%(Spellout|Ordinal)?/,
149
- edition_translate1(x.text.to_i)))
158
+ @i18n.edition_ordinal.sub(/%(Spellout|Ordinal)?/, edn))
150
159
  end
151
160
 
152
161
  def edition_translate1(num)
@@ -218,11 +227,9 @@ module IsoDoc
218
227
  end
219
228
 
220
229
  def trim_hash1(hash)
221
- return hash unless hash.is_a? Hash
222
-
230
+ hash.is_a?(Hash) or return hash
223
231
  hash.each_with_object({}) do |(k, v), g|
224
- next if blank?(v)
225
-
232
+ blank?(v) and next
226
233
  g[k] = case v
227
234
  when Hash then trim_hash1(hash[k])
228
235
  when Array
@@ -1,4 +1,5 @@
1
1
  require "metanorma-utils"
2
+ require "csv"
2
3
 
3
4
  module IsoDoc
4
5
  class PresentationXMLConvert < ::IsoDoc::Convert
@@ -126,16 +127,18 @@ module IsoDoc
126
127
  elem["formats"] = ",#{elem['formats']},"
127
128
  end
128
129
 
129
- private
130
-
131
130
  def extract_custom_charsets(docxml)
132
- docxml.xpath(ns("//presentation-metadata/custom-charset-font")).
133
- each_with_object({}) do |x, m|
134
- kv = x.text.split(":", 2)
131
+ docxml.xpath(ns("//presentation-metadata/custom-charset-font"))
132
+ .each_with_object({}) do |line, m|
133
+ line.text.split(",").map(&:strip).each do |x|
134
+ kv = x.split(":", 2)
135
135
  m[kv[0]] = kv[1]
136
136
  end
137
+ end
137
138
  end
138
139
 
140
+ private
141
+
139
142
  def found_matching_variant_sibling(node)
140
143
  prev = node.xpath("./preceding-sibling::xmlns:variant")
141
144
  foll = node.xpath("./following-sibling::xmlns:variant")
@@ -1,7 +1,12 @@
1
1
  module IsoDoc
2
2
  class PresentationXMLConvert < ::IsoDoc::Convert
3
- def prefix_container(container, linkend, node, _target)
4
- l10n(@i18n.nested_xref.sub("%1", anchor_xref(node, container))
3
+ def prefix_container(container, linkend, node, target)
4
+ prefix_container?(container, node) or return linkend
5
+ container_container = @xrefs.anchor(container, :container, false)
6
+ container_label =
7
+ prefix_container(container_container, anchor_xref(node, container),
8
+ node, target)
9
+ l10n(@i18n.nested_xref.sub("%1", container_label)
5
10
  .sub("%2", linkend))
6
11
  end
7
12
 
@@ -31,8 +36,7 @@ module IsoDoc
31
36
  def anchor_linkend1(node)
32
37
  linkend = anchor_xref(node, node["target"])
33
38
  container = @xrefs.anchor(node["target"], :container, false)
34
- prefix_container?(container, node) and
35
- linkend = prefix_container(container, linkend, node, node["target"])
39
+ linkend = prefix_container(container, linkend, node, node["target"])
36
40
  capitalise_xref(node, linkend, anchor_value(node["target"]))
37
41
  end
38
42
 
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.7.1".freeze
2
+ VERSION = "2.7.3".freeze
3
3
  end
@@ -24,24 +24,25 @@ module IsoDoc
24
24
  .//figure[not(@class)] | .//figure[@class = 'pseudocode'] | .//sourcecode[not(ancestor::example)]
25
25
  XPATH
26
26
 
27
- def sequential_figure_names(clause)
27
+ def sequential_figure_names(clause, container: false)
28
28
  c = Counter.new
29
29
  j = 0
30
30
  clause.xpath(ns(FIGURE_NO_CLASS)).noblank.each do |t|
31
31
  j = subfigure_increment(j, c, t)
32
- sequential_figure_body(j, c, t, "figure")
32
+ sequential_figure_body(j, c, t, "figure", container: container)
33
33
  end
34
- sequential_figure_class_names(clause)
34
+ sequential_figure_class_names(clause, container: container)
35
35
  end
36
36
 
37
- def sequential_figure_class_names(clause)
37
+ def sequential_figure_class_names(clause, container: false)
38
38
  c = {}
39
39
  j = 0
40
40
  clause.xpath(ns(".//figure[@class][not(@class = 'pseudocode')]"))
41
41
  .each do |t|
42
42
  c[t["class"]] ||= Counter.new
43
43
  j = subfigure_increment(j, c[t["class"]], t)
44
- sequential_figure_body(j, c[t["class"]], t, t["class"])
44
+ sequential_figure_body(j, c[t["class"]], t, t["class"],
45
+ container: container)
45
46
  end
46
47
  end
47
48
 
@@ -50,27 +51,28 @@ module IsoDoc
50
51
  "-#{subfignum}"
51
52
  end
52
53
 
53
- def sequential_figure_body(subfignum, counter, block, klass)
54
+ def sequential_figure_body(subfig, counter, elem, klass, container: false)
54
55
  label = counter.print
55
- label &&= label + subfigure_label(subfignum)
56
- @anchors[block["id"]] = anchor_struct(
57
- label, nil, @labels[klass] || klass.capitalize, klass,
58
- block["unnumbered"]
56
+ label &&= label + subfigure_label(subfig)
57
+ @anchors[elem["id"]] = anchor_struct(
58
+ label, container ? elem : nil,
59
+ @labels[klass] || klass.capitalize, klass,
60
+ elem["unnumbered"]
59
61
  )
60
62
  end
61
63
 
62
- def sequential_table_names(clause)
64
+ def sequential_table_names(clause, container: false)
63
65
  c = Counter.new
64
66
  clause.xpath(ns(".//table")).noblank.each do |t|
65
67
  labelled_ancestor(t) and next
66
68
  @anchors[t["id"]] = anchor_struct(
67
- c.increment(t).print, nil,
69
+ c.increment(t).print, container ? t : nil,
68
70
  @labels["table"], "table", t["unnumbered"]
69
71
  )
70
72
  end
71
73
  end
72
74
 
73
- def sequential_formula_names(clause)
75
+ def sequential_formula_names(clause, container: false)
74
76
  c = Counter.new
75
77
  clause.xpath(ns(".//formula")).noblank.each do |t|
76
78
  @anchors[t["id"]] = anchor_struct(
@@ -91,60 +93,63 @@ module IsoDoc
91
93
  ./permission | ./requirement | ./recommendation
92
94
  XPATH
93
95
 
94
- def sequential_permission_names(clause)
96
+ def sequential_permission_names(clause, container: false)
95
97
  c = ReqCounter.new
96
98
  clause.xpath(ns(FIRST_LVL_REQ)).noblank.each do |t|
97
99
  m = @reqt_models.model(t["model"])
98
100
  klass, label = reqt2class_label(t, m)
99
101
  id = c.increment(label, t).print
100
- sequential_permission_body(id, t, label, klass, m)
101
- sequential_permission_children(t, id)
102
+ sequential_permission_body(id, t, label, klass, m,
103
+ container: container)
104
+ sequential_permission_children(t, id, container: container)
102
105
  end
103
106
  end
104
107
 
105
- def sequential_permission_children(block, lbl)
108
+ def sequential_permission_children(elem, lbl, container: false)
106
109
  c = ReqCounter.new
107
- block.xpath(ns(REQ_CHILDREN)).noblank.each do |t|
110
+ elem.xpath(ns(REQ_CHILDREN)).noblank.each do |t|
108
111
  m = @reqt_models.model(t["model"])
109
112
  klass, label = reqt2class_nested_label(t, m)
110
113
  id = "#{lbl}#{hierfigsep}#{c.increment(label, t).print}"
111
- sequential_permission_body(id, t, label, klass, m)
112
- sequential_permission_children(t, id)
114
+ sequential_permission_body(id, t, label, klass, m,
115
+ container: container)
116
+ sequential_permission_children(t, id, container: container)
113
117
  end
114
118
  end
115
119
 
116
- def sequential_permission_body(id, block, label, klass, model)
117
- @anchors[block["id"]] = model.postprocess_anchor_struct(
118
- block, anchor_struct(id, block,
119
- label, klass, block["unnumbered"])
120
+ def sequential_permission_body(id, elem, label, klass, model, container: false)
121
+ @anchors[elem["id"]] = model.postprocess_anchor_struct(
122
+ elem, anchor_struct(id, elem,
123
+ label, klass, elem["unnumbered"])
120
124
  )
121
- model.permission_parts(block, id, label, klass).each do |n|
125
+ model.permission_parts(elem, id, label, klass).each do |n|
122
126
  @anchors[n[:id]] = anchor_struct(n[:number], n[:elem], n[:label],
123
127
  n[:klass], false)
124
128
  end
125
129
  end
126
130
 
127
- def reqt2class_label(block, model)
131
+ def reqt2class_label(elem, model)
128
132
  model.req_class_paths.each do |n|
129
133
  v1 = ns("/#{n[:xpath]}").sub(%r{^/}, "")
130
- block.at("./self::#{v1}") and return [n[:klass], n[:label]]
134
+ elem.at("./self::#{v1}") and return [n[:klass], n[:label]]
131
135
  end
132
136
  [nil, nil]
133
137
  end
134
138
 
135
- def reqt2class_nested_label(block, model)
139
+ def reqt2class_nested_label(elem, model)
136
140
  model.req_nested_class_paths.each do |n|
137
141
  v1 = ns("/#{n[:xpath]}").sub(%r{^/}, "")
138
- block.at("./self::#{v1}") and return [n[:klass], n[:label]]
142
+ elem.at("./self::#{v1}") and return [n[:klass], n[:label]]
139
143
  end
140
144
  [nil, nil]
141
145
  end
142
146
 
143
- def sequential_asset_names(clause)
144
- sequential_table_names(clause)
145
- sequential_figure_names(clause)
146
- sequential_formula_names(clause)
147
- sequential_permission_names(clause)
147
+ # container makes numbering be prefixed with the parent clause reference
148
+ def sequential_asset_names(clause, container: false)
149
+ sequential_table_names(clause, container: container)
150
+ sequential_figure_names(clause, container: container)
151
+ sequential_formula_names(clause, container: container)
152
+ sequential_permission_names(clause, container: container)
148
153
  end
149
154
 
150
155
  def hierarchical_figure_names(clause, num)
@@ -129,6 +129,10 @@ module IsoDoc
129
129
 
130
130
  def back_names(clause)
131
131
  unnumbered_names(clause)
132
+ sequential_asset_names(
133
+ Nokogiri::XML::NodeSet.new(clause.document, [clause]),
134
+ container: true,
135
+ )
132
136
  end
133
137
 
134
138
  def unnumbered_names(clause)
@@ -237,8 +241,8 @@ module IsoDoc
237
241
  def reference_names(ref)
238
242
  ids = @klass.bibitem_ref_code(ref)
239
243
  identifiers = @klass.render_identifier(ids)
240
- reference = @klass.
241
- docid_l10n(identifiers[:metanorma] || identifiers[:sdo] ||
244
+ reference = @klass
245
+ .docid_l10n(identifiers[:metanorma] || identifiers[:sdo] ||
242
246
  identifiers[:ordinal] || identifiers[:doi])
243
247
  @anchors[ref["id"]] = { xref: reference }
244
248
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-27 00:00:00.000000000 Z
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html2doc
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5'
69
- - !ruby/object:Gem::Dependency
70
- name: relaton-cli
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: mn2pdf
85
71
  requirement: !ruby/object:Gem::Requirement