metanorma-iso 1.10.1 → 1.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ubuntu.yml +1 -1
  3. data/Gemfile +1 -1
  4. data/lib/asciidoctor/iso/base.rb +1 -1
  5. data/lib/asciidoctor/iso/basicdoc.rng +1 -11
  6. data/lib/asciidoctor/iso/biblio.rng +0 -2
  7. data/lib/asciidoctor/iso/front.rb +17 -4
  8. data/lib/asciidoctor/iso/front_id.rb +20 -17
  9. data/lib/asciidoctor/iso/isodoc.rng +61 -19
  10. data/lib/asciidoctor/iso/isostandard-amd.rng +1 -1
  11. data/lib/asciidoctor/iso/isostandard.rng +15 -3
  12. data/lib/asciidoctor/iso/reqt.rng +1 -1
  13. data/lib/asciidoctor/iso/section.rb +1 -1
  14. data/lib/asciidoctor/iso/validate.rb +1 -1
  15. data/lib/asciidoctor/iso/validate_image.rb +1 -1
  16. data/lib/asciidoctor/iso/validate_section.rb +1 -1
  17. data/lib/isodoc/iso/base_convert.rb +14 -31
  18. data/lib/isodoc/iso/html/isodoc.css +0 -1
  19. data/lib/isodoc/iso/html/isodoc.scss +0 -1
  20. data/lib/isodoc/iso/html/style-human.css +40 -9
  21. data/lib/isodoc/iso/html/style-human.scss +36 -9
  22. data/lib/isodoc/iso/html/style-iso.css +35 -6
  23. data/lib/isodoc/iso/html/style-iso.scss +31 -6
  24. data/lib/isodoc/iso/html/wordstyle.css +10 -8
  25. data/lib/isodoc/iso/html/wordstyle.scss +10 -8
  26. data/lib/isodoc/iso/html_convert.rb +81 -22
  27. data/lib/isodoc/iso/index.rb +53 -45
  28. data/lib/isodoc/iso/iso.amendment.xsl +333 -113
  29. data/lib/isodoc/iso/iso.international-standard.xsl +333 -113
  30. data/lib/isodoc/iso/isosts_convert.rb +6 -2
  31. data/lib/isodoc/iso/metadata.rb +27 -22
  32. data/lib/isodoc/iso/presentation_xml_convert.rb +60 -25
  33. data/lib/isodoc/iso/sts_convert.rb +3 -2
  34. data/lib/isodoc/iso/word_convert.rb +0 -2
  35. data/lib/metanorma/iso/processor.rb +2 -2
  36. data/lib/metanorma/iso/version.rb +1 -1
  37. data/metanorma-iso.gemspec +3 -3
  38. data/spec/asciidoctor/base_spec.rb +397 -545
  39. data/spec/asciidoctor/blocks_spec.rb +4 -4
  40. data/spec/asciidoctor/cleanup_spec.rb +15 -12
  41. data/spec/asciidoctor/refs_spec.rb +87 -84
  42. data/spec/isodoc/amd_spec.rb +261 -250
  43. data/spec/isodoc/i18n_spec.rb +7 -7
  44. data/spec/isodoc/inline_spec.rb +242 -216
  45. data/spec/isodoc/iso_spec.rb +3 -1
  46. data/spec/isodoc/postproc_spec.rb +111 -28
  47. data/spec/isodoc/section_spec.rb +3 -3
  48. data/spec/isodoc/terms_spec.rb +34 -41
  49. data/spec/isodoc/xref_spec.rb +3 -3
  50. data/spec/metanorma/processor_spec.rb +110 -14
  51. data/spec/vcr_cassettes/docrels.yml +37 -427
  52. metadata +8 -8
@@ -5,32 +5,36 @@ module IsoDoc
5
5
  %(id="_#{UUIDTools::UUID.random_create}")
6
6
  end
7
7
 
8
- def index(docxml)
9
- unless docxml.at(ns("//index"))
10
- docxml.xpath(ns("//indexsect")).each(&:remove)
11
- return
8
+ def index(xml)
9
+ if xml.at(ns("//index"))
10
+ i = xml.at(ns("//indexsect")) ||
11
+ xml.root.add_child("<indexsect #{add_id}><title>#{@i18n.index}"\
12
+ "</title></indexsect>").first
13
+ index = sort_indexterms(xml.xpath(ns("//index")),
14
+ xml.xpath(ns("//index-xref[@also = 'false']")),
15
+ xml.xpath(ns("//index-xref[@also = 'true']")))
16
+ index1(xml, i, index)
17
+ else xml.xpath(ns("//indexsect")).each(&:remove)
12
18
  end
13
- i = docxml.at(ns("//indexsect")) ||
14
- docxml.root.add_child("<indexsect #{add_id}><title>#{@i18n.index}</title></indexsect>").first
15
- index = sort_indexterms(docxml.xpath(ns("//index")),
16
- docxml.xpath(ns("//index-xref[@also = 'false']")),
17
- docxml.xpath(ns("//index-xref[@also = 'true']")))
18
- index1(docxml, i, index)
19
19
  end
20
20
 
21
- def index1(docxml, i, index)
22
- c = i.add_child("<ul></ul>").first
21
+ def index1(docxml, indexsect, index)
22
+ c = indexsect.add_child("<ul></ul>").first
23
23
  index.keys.sort.each do |k|
24
- # c = i.add_child "<clause #{add_id}><title>#{k}</title><ul></ul></clause>"
25
24
  words = index[k].keys.each_with_object({}) do |w, v|
26
25
  v[sortable(w).downcase] = w
27
26
  end
28
27
  words.keys.localize(@lang.to_sym).sort.to_a.each do |w|
29
- # c.first.at(ns("./ul")).add_child index_entries(words, index[k], w)
30
28
  c.add_child index_entries(words, index[k], w)
31
29
  end
32
30
  end
33
- docxml.xpath(ns("//indexsect//xref")).each { |x| x.children.remove }
31
+ index1_cleanup(docxml)
32
+ end
33
+
34
+ def index1_cleanup(docxml)
35
+ docxml.xpath(ns("//indexsect//xref")).each do |x|
36
+ x.children.remove
37
+ end
34
38
  @xrefs.bookmark_anchor_names(docxml)
35
39
  end
36
40
 
@@ -56,7 +60,7 @@ module IsoDoc
56
60
  end
57
61
  ret += "</ul>"
58
62
  end
59
- ret + "</li>"
63
+ "#{ret}</li>"
60
64
  end
61
65
 
62
66
  def index_entries2(words, index, secondary)
@@ -75,30 +79,29 @@ module IsoDoc
75
79
  end
76
80
  ret += "</ul>"
77
81
  end
78
- ret + "</li>"
82
+ "#{ret}</li>"
79
83
  end
80
84
 
81
85
  def index_entries_head(head, entries, opt)
82
86
  ret = "<li>#{head}"
83
87
  xref = entries&.dig(:xref)&.join(", ")
84
- see_sort = entries&.dig(:see)&.each_with_object({}) do |w, v|
85
- v[sortable(w).downcase] = w
86
- end
87
- see = see_sort&.keys&.localize(@lang.to_sym)&.sort&.to_a&.map do |k|
88
- see_sort[k]
89
- end&.join(", ")
90
- also_sort = entries&.dig(:also)&.each_with_object({}) do |w, v|
91
- v[sortable(w).downcase] = w
92
- end
93
- also = also_sort&.keys&.localize(@lang.to_sym)&.sort&.to_a&.map do |k|
94
- also_sort[k]
95
- end&.join(", ")
88
+ see = index_entries_see(entries, :see)
89
+ also = index_entries_see(entries, :also)
96
90
  ret += "#{opt[:xref_lbl]} #{xref}" if xref
97
91
  ret += "#{opt[:see_lbl]} #{see}" if see
98
92
  ret += "#{opt[:also_lbl]} #{also}" if also
99
93
  ret
100
94
  end
101
95
 
96
+ def index_entries_see(entries, label)
97
+ see_sort = entries&.dig(label)&.each_with_object({}) do |w, v|
98
+ v[sortable(w).downcase] = w
99
+ end
100
+ see_sort&.keys&.localize(@lang.to_sym)&.sort&.to_a&.map do |k|
101
+ see_sort[k]
102
+ end&.join(", ")
103
+ end
104
+
102
105
  def see_lbl
103
106
  @lang == "en" ? @i18n.see : "<em>#{@i18n.see}</em>"
104
107
  end
@@ -119,13 +122,8 @@ module IsoDoc
119
122
 
120
123
  def extract_indexsee(val, terms, label)
121
124
  terms.each_with_object(val) do |t, v|
122
- term = t&.at(ns("./primary"))&.children&.to_xml
123
- term2 = t&.at(ns("./secondary"))&.children&.to_xml
124
- term3 = t&.at(ns("./tertiary"))&.children&.to_xml
125
- v[term] ||= {}
126
- v[term][term2] ||= {}
127
- v[term][term2][term3] ||= {}
128
- v[term][term2][term3][label] ||= []
125
+ term, term2, term3 = extract_indexterms_init(t)
126
+ term_hash_init(v, term, term2, term3, label)
129
127
  v[term][term2][term3][label] << t&.at(ns("./target"))&.children&.to_xml
130
128
  t.remove
131
129
  end
@@ -138,22 +136,32 @@ module IsoDoc
138
136
  end
139
137
  end
140
138
 
141
- # attributes are decoded into UTF-8, elements in extract_indexsee are still in entities
139
+ # attributes are decoded into UTF-8,
140
+ # elements in extract_indexsee are still in entities
142
141
  def extract_indexterms(terms)
143
142
  terms.each_with_object({}) do |t, v|
144
- term = t&.at(ns("./primary"))&.children&.to_xml
145
- term2 = t&.at(ns("./secondary"))&.children&.to_xml
146
- term3 = t&.at(ns("./tertiary"))&.children&.to_xml
143
+ term, term2, term3 = extract_indexterms_init(t)
147
144
  index2bookmark(t)
148
- v[term] ||= {}
149
- v[term][term2] ||= {}
150
- v[term][term2][term3] ||= {}
151
- v[term][term2][term3][:xref] ||= []
145
+ term_hash_init(v, term, term2, term3, :xref)
152
146
  to = t["to"] ? "to='#{t['to']}' " : ""
153
- v[term][term2][term3][:xref] << "<xref target='#{t['id']}' #{to}pagenumber='true'/>"
147
+ v[term][term2][term3][:xref] << "<xref target='#{t['id']}' "\
148
+ "#{to}pagenumber='true'/>"
149
+ end
150
+ end
151
+
152
+ def extract_indexterms_init(term)
153
+ %w(primary secondary tertiary).each_with_object([]) do |x, m|
154
+ m << term&.at(ns("./#{x}"))&.children&.to_xml
154
155
  end
155
156
  end
156
157
 
158
+ def term_hash_init(hash, term, term2, term3, label)
159
+ hash[term] ||= {}
160
+ hash[term][term2] ||= {}
161
+ hash[term][term2][term3] ||= {}
162
+ hash[term][term2][term3][label] ||= []
163
+ end
164
+
157
165
  def index2bookmark(node)
158
166
  node.name = "bookmark"
159
167
  node.children.each(&:remove)