isodoc 1.5.4 → 1.6.3

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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -4
  3. data/Gemfile +2 -2
  4. data/Rakefile +2 -2
  5. data/bin/rspec +1 -2
  6. data/isodoc.gemspec +11 -11
  7. data/lib/isodoc-yaml/i18n-ar.yaml +152 -0
  8. data/lib/isodoc-yaml/i18n-de.yaml +149 -0
  9. data/lib/isodoc-yaml/i18n-es.yaml +151 -0
  10. data/lib/isodoc-yaml/i18n-ru.yaml +154 -0
  11. data/lib/isodoc/base_style/all.css +7 -0
  12. data/lib/isodoc/base_style/metanorma_word.css +7 -0
  13. data/lib/isodoc/base_style/metanorma_word.scss +8 -0
  14. data/lib/isodoc/base_style/reset.css +7 -0
  15. data/lib/isodoc/base_style/reset.scss +9 -0
  16. data/lib/isodoc/base_style/scripts.html +187 -0
  17. data/lib/isodoc/class_utils.rb +6 -5
  18. data/lib/isodoc/common.rb +2 -0
  19. data/lib/isodoc/convert.rb +30 -17
  20. data/lib/isodoc/css.rb +42 -28
  21. data/lib/isodoc/function/blocks.rb +21 -4
  22. data/lib/isodoc/function/blocks_example_note.rb +2 -2
  23. data/lib/isodoc/function/cleanup.rb +1 -2
  24. data/lib/isodoc/function/form.rb +51 -0
  25. data/lib/isodoc/function/inline.rb +32 -10
  26. data/lib/isodoc/function/references.rb +55 -42
  27. data/lib/isodoc/function/table.rb +1 -0
  28. data/lib/isodoc/function/to_word_html.rb +29 -28
  29. data/lib/isodoc/function/utils.rb +41 -38
  30. data/lib/isodoc/gem_tasks.rb +30 -31
  31. data/lib/isodoc/html_convert.rb +6 -4
  32. data/lib/isodoc/html_function/form.rb +62 -0
  33. data/lib/isodoc/html_function/postprocess.rb +35 -76
  34. data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
  35. data/lib/isodoc/i18n.rb +33 -31
  36. data/lib/isodoc/pdf_convert.rb +1 -3
  37. data/lib/isodoc/presentation_function/bibdata.rb +13 -10
  38. data/lib/isodoc/presentation_function/block.rb +17 -8
  39. data/lib/isodoc/presentation_function/inline.rb +75 -118
  40. data/lib/isodoc/presentation_function/math.rb +84 -0
  41. data/lib/isodoc/presentation_function/section.rb +20 -22
  42. data/lib/isodoc/presentation_xml_convert.rb +2 -1
  43. data/lib/isodoc/sassc_importer.rb +1 -1
  44. data/lib/isodoc/version.rb +1 -1
  45. data/lib/isodoc/word_function/body.rb +28 -24
  46. data/lib/isodoc/word_function/footnotes.rb +22 -15
  47. data/lib/isodoc/word_function/postprocess.rb +16 -6
  48. data/lib/isodoc/xref.rb +10 -11
  49. data/lib/isodoc/xref/xref_counter.rb +32 -17
  50. data/lib/isodoc/xref/xref_gen.rb +45 -32
  51. data/lib/isodoc/xref/xref_sect_gen.rb +33 -31
  52. data/lib/isodoc/xslfo_convert.rb +36 -25
  53. data/spec/assets/html_override.css +1 -0
  54. data/spec/assets/word_override.css +1 -0
  55. data/spec/isodoc/blocks_spec.rb +2518 -2570
  56. data/spec/isodoc/cleanup_spec.rb +1107 -1109
  57. data/spec/isodoc/footnotes_spec.rb +1 -16
  58. data/spec/isodoc/form_spec.rb +156 -0
  59. data/spec/isodoc/i18n_spec.rb +984 -972
  60. data/spec/isodoc/inline_spec.rb +984 -920
  61. data/spec/isodoc/lists_spec.rb +316 -315
  62. data/spec/isodoc/postproc_spec.rb +1692 -1538
  63. data/spec/isodoc/presentation_xml_spec.rb +345 -342
  64. data/spec/isodoc/ref_spec.rb +718 -723
  65. data/spec/isodoc/section_spec.rb +910 -902
  66. data/spec/isodoc/table_spec.rb +566 -556
  67. data/spec/isodoc/terms_spec.rb +252 -256
  68. data/spec/isodoc/xref_spec.rb +3040 -2985
  69. data/spec/isodoc/xslfo_convert_spec.rb +39 -0
  70. data/spec/spec_helper.rb +30 -29
  71. metadata +80 -70
  72. data/.rubocop.ribose.yml +0 -65
  73. data/.rubocop.tb.yml +0 -650
  74. data/lib/twitter-cldr/patch.rb +0 -39
data/lib/isodoc/i18n.rb CHANGED
@@ -5,44 +5,47 @@ module IsoDoc
5
5
  def load_yaml(lang, script, i18nyaml = nil)
6
6
  ret = load_yaml1(lang, script)
7
7
  return normalise_hash(ret.merge(YAML.load_file(i18nyaml))) if i18nyaml
8
+
8
9
  normalise_hash(ret)
9
10
  end
10
11
 
11
12
  def normalise_hash(ret)
12
- if ret.is_a? Hash
13
+ case ret
14
+ when Hash
13
15
  ret.each do |k, v|
14
16
  ret[k] = normalise_hash(v)
15
17
  end
16
18
  ret
17
- elsif ret.is_a? Array then ret.map { |n| normalise_hash(n) }
18
- elsif ret.is_a? String then ret.unicode_normalize(:nfc)
19
- else
20
- ret
19
+ when Array then ret.map { |n| normalise_hash(n) }
20
+ when String then ret.unicode_normalize(:nfc)
21
+ else ret
21
22
  end
22
23
  end
23
24
 
24
25
  def load_yaml1(lang, script)
25
- if lang == "en"
26
- YAML.load_file(File.join(File.dirname(__FILE__),
27
- "../isodoc-yaml/i18n-en.yaml"))
28
- elsif lang == "fr"
29
- YAML.load_file(File.join(File.dirname(__FILE__),
30
- "../isodoc-yaml/i18n-fr.yaml"))
31
- elsif lang == "zh" && script == "Hans"
32
- YAML.load_file(File.join(File.dirname(__FILE__),
33
- "../isodoc-yaml/i18n-zh-Hans.yaml"))
26
+ case lang
27
+ when "en", "fr", "ru", "de", "es", "ar"
28
+ load_yaml2(lang)
29
+ when "zh"
30
+ if script == "Hans" then load_yaml2("zh-Hans")
31
+ else load_yaml2("en")
32
+ end
34
33
  else
35
- YAML.load_file(File.join(File.dirname(__FILE__),
36
- "../isodoc-yaml/i18n-en.yaml"))
34
+ load_yaml2("en")
37
35
  end
38
36
  end
39
37
 
38
+ def load_yaml2(str)
39
+ YAML.load_file(File.join(File.dirname(__FILE__),
40
+ "../isodoc-yaml/i18n-#{str}.yaml"))
41
+ end
42
+
40
43
  def get
41
44
  @labels
42
45
  end
43
46
 
44
- def set(x, y)
45
- @labels[x] = y
47
+ def set(key, val)
48
+ @labels[key] = val
46
49
  end
47
50
 
48
51
  def initialize(lang, script, i18nyaml = nil)
@@ -57,37 +60,36 @@ module IsoDoc
57
60
  end
58
61
  end
59
62
 
60
- def self.l10n(x, lang = @lang, script = @script)
61
- l10n(x, lang, script)
63
+ def self.l10n(text, lang = @lang, script = @script)
64
+ l10n(text, lang, script)
62
65
  end
63
66
 
64
67
  # TODO: move to localization file
65
68
  # function localising spaces and punctuation.
66
69
  # Not clear if period needs to be localised for zh
67
- def l10n(x, lang = @lang, script = @script)
70
+ def l10n(text, lang = @lang, script = @script)
68
71
  if lang == "zh" && script == "Hans"
69
- xml = Nokogiri::HTML::DocumentFragment.parse(x)
72
+ xml = Nokogiri::HTML::DocumentFragment.parse(text)
70
73
  xml.traverse do |n|
71
74
  next unless n.text?
72
- n.replace(n.text.gsub(/ /, "").gsub(/:/, ":").gsub(/,/, "、").
73
- gsub(/\(/, "").gsub(/\)/, "").
74
- gsub(/\[/, "【").gsub(/\]/, "】"))
75
+
76
+ n.replace(n.text.gsub(/ /, "").gsub(/:/, ":").gsub(/,/, "")
77
+ .gsub(/\(/, "(").gsub(/\)/, ")").gsub(/\[/, "【").gsub(/\]/, "】"))
75
78
  end
76
79
  xml.to_xml.gsub(/<b>/, "").gsub("</b>", "").gsub(/<\?[^>]+>/, "")
77
- else
78
- x
80
+ else text
79
81
  end
80
82
  end
81
83
 
82
84
  def multiple_and(names, andword)
83
- return '' if names.empty?
85
+ return "" if names.empty?
84
86
  return names[0] if names.length == 1
87
+
85
88
  (names.length == 2) &&
86
89
  (return l10n("#{names[0]} #{andword} #{names[1]}", @lang, @script))
87
- l10n(names[0..-2].join(', ') + " #{andword} #{names[-1]}", @lang, @script)
90
+ l10n(names[0..-2].join(", ") + " #{andword} #{names[-1]}", @lang, @script)
88
91
  end
89
92
 
90
- #module_function :l10n
91
-
93
+ # module_function :l10n
92
94
  end
93
95
  end
@@ -42,9 +42,7 @@ module IsoDoc
42
42
  end
43
43
 
44
44
  def xref_parse(node, out)
45
- target = /#/.match(node["target"]) ? node["target"].sub(/#/, ".pdf#") :
46
- "##{node["target"]}"
47
- out.a(**{ "href": target }) { |l| l << get_linkend(node) }
45
+ out.a(**{ "href": target_pdf(node) }) { |l| l << get_linkend(node) }
48
46
  end
49
47
  end
50
48
  end
@@ -4,7 +4,7 @@ module IsoDoc
4
4
  a = bibdata_current(docxml) or return
5
5
  bibdata_i18n(a)
6
6
  a.next =
7
- "<localized-strings>#{i8n_name(trim_hash(@i18n.get), "").join("")}"\
7
+ "<localized-strings>#{i8n_name(trim_hash(@i18n.get), '').join('')}"\
8
8
  "</localized-strings>"
9
9
  end
10
10
 
@@ -19,10 +19,10 @@ module IsoDoc
19
19
  a
20
20
  end
21
21
 
22
- def bibdata_i18n(b)
23
- hash_translate(b, @i18n.get["doctype_dict"], "./ext/doctype")
24
- hash_translate(b, @i18n.get["stage_dict"], "./status/stage")
25
- hash_translate(b, @i18n.get["substage_dict"], "./status/substage")
22
+ def bibdata_i18n(bib)
23
+ hash_translate(bib, @i18n.get["doctype_dict"], "./ext/doctype")
24
+ hash_translate(bib, @i18n.get["stage_dict"], "./status/stage")
25
+ hash_translate(bib, @i18n.get["substage_dict"], "./status/substage")
26
26
  end
27
27
 
28
28
  def hash_translate(bibdata, hash, xpath, lang = @lang)
@@ -46,8 +46,8 @@ module IsoDoc
46
46
  def i8n_name(h, pref)
47
47
  if h.is_a? Hash then i8n_name1(h, pref)
48
48
  elsif h.is_a? Array
49
- h.reject { |a| blank?(a) }.each_with_object([]).
50
- with_index do |(v1, g), i|
49
+ h.reject { |a| blank?(a) }.each_with_object([])
50
+ .with_index do |(v1, g), i|
51
51
  i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
52
52
  end
53
53
  else [i18n_tag(pref, h)]
@@ -62,12 +62,12 @@ module IsoDoc
62
62
  i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
63
63
  end
64
64
  else
65
- g << i18n_tag("#{pref}#{pref.empty? ? "" : "."}#{i18n_safe(k)}", v)
65
+ g << i18n_tag("#{pref}#{pref.empty? ? '' : '.'}#{i18n_safe(k)}", v)
66
66
  end
67
67
  end
68
68
  end
69
69
 
70
- #https://stackoverflow.com/a/31822406
70
+ # https://stackoverflow.com/a/31822406
71
71
  def blank?(v)
72
72
  v.nil? || v.respond_to?(:empty?) && v.empty?
73
73
  end
@@ -76,14 +76,17 @@ module IsoDoc
76
76
  loop do
77
77
  h_new = trim_hash1(h)
78
78
  break h if h==h_new
79
+
79
80
  h = h_new
80
81
  end
81
82
  end
82
83
 
83
84
  def trim_hash1(h)
84
85
  return h unless h.is_a? Hash
85
- h.each_with_object({}) do |(k,v), g|
86
+
87
+ h.each_with_object({}) do |(k, v), g|
86
88
  next if blank?(v)
89
+
87
90
  g[k] = if v.is_a? Hash then trim_hash1(h[k])
88
91
  elsif v.is_a? Array
89
92
  h[k].map { |a| trim_hash1(a) }.reject { |a| blank?(a) }
@@ -3,7 +3,8 @@ require "base64"
3
3
  module IsoDoc
4
4
  class PresentationXMLConvert < ::IsoDoc::Convert
5
5
  def lower2cap(s)
6
- return s if /^[[:upper:]][[:upper:]]/.match(s)
6
+ return s if /^[[:upper:]][[:upper:]]/.match?(s)
7
+
7
8
  s.capitalize
8
9
  end
9
10
 
@@ -19,8 +20,10 @@ module IsoDoc
19
20
  end
20
21
 
21
22
  def svg_extract(f)
22
- return unless %r{^data:image/svg\+xml;base64,}.match(f["src"])
23
- svg = Base64.strict_decode64(f["src"].sub(%r{^data:image/svg\+xml;base64,}, ""))
23
+ return unless %r{^data:image/svg\+xml;base64,}.match?(f["src"])
24
+
25
+ svg = Base64.strict_decode64(f["src"]
26
+ .sub(%r{^data:image/svg\+xml;base64,}, ""))
24
27
  f.replace(svg.sub(/<\?xml[^>]*>/, ""))
25
28
  end
26
29
 
@@ -28,12 +31,15 @@ module IsoDoc
28
31
  return sourcecode1(f) if f["class"] == "pseudocode" || f["type"] == "pseudocode"
29
32
  return if labelled_ancestor(f) && f.ancestors("figure").empty?
30
33
  return if f.at(ns("./figure")) and !f.at(ns("./name"))
34
+
31
35
  lbl = @xrefs.anchor(f['id'], :label, false) or return
32
- prefix_name(f, "&nbsp;&mdash; ", l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
36
+ prefix_name(f, "&nbsp;&mdash; ",
37
+ l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
33
38
  end
34
39
 
35
40
  def prefix_name(f, delim, number, elem)
36
41
  return if number.nil? || number.empty?
42
+
37
43
  unless name = f.at(ns("./#{elem}"))
38
44
  f.children.empty? and f.add_child("<#{elem}></#{elem}>") or
39
45
  f.children.first.previous = "<#{elem}></#{elem}>"
@@ -52,6 +58,7 @@ module IsoDoc
52
58
  def sourcecode1(f)
53
59
  return if labelled_ancestor(f)
54
60
  return unless f.ancestors("example").empty?
61
+
55
62
  lbl = @xrefs.anchor(f['id'], :label, false) or return
56
63
  prefix_name(f, "&nbsp;&mdash; ", l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
57
64
  end
@@ -96,6 +103,7 @@ module IsoDoc
96
103
  # introduce name element
97
104
  def note1(f)
98
105
  return if f.parent.name == "bibitem"
106
+
99
107
  n = @xrefs.get[f["id"]]
100
108
  lbl = (@i18n.note if n.nil? || n[:label].nil? || n[:label].empty?) ?
101
109
  @i18n.note: l10n("#{@i18n.note} #{n[:label]}")
@@ -110,7 +118,7 @@ module IsoDoc
110
118
 
111
119
  # introduce name element
112
120
  def termnote1(f)
113
- lbl = l10n(@xrefs.anchor(f['id'], :label) || '???')
121
+ lbl = l10n(@xrefs.anchor(f["id"], :label) || "???")
114
122
  prefix_name(f, "", lower2cap(lbl), "name")
115
123
  end
116
124
 
@@ -134,7 +142,7 @@ module IsoDoc
134
142
 
135
143
  # introduce name element
136
144
  def recommendation1(f, type)
137
- n = @xrefs.anchor(f['id'], :label, false)
145
+ n = @xrefs.anchor(f["id"], :label, false)
138
146
  lbl = (n.nil? ? type : l10n("#{type} #{n}"))
139
147
  prefix_name(f, "", lbl, "name")
140
148
  end
@@ -148,7 +156,8 @@ module IsoDoc
148
156
  def table1(f)
149
157
  return if labelled_ancestor(f)
150
158
  return if f["unnumbered"] && !f.at(ns("./name"))
151
- n = @xrefs.anchor(f['id'], :label, false)
159
+
160
+ n = @xrefs.anchor(f["id"], :label, false)
152
161
  prefix_name(f, "&nbsp;&mdash; ", l10n("#{lower2cap @i18n.table} #{n}"), "name")
153
162
  end
154
163
 
@@ -160,7 +169,7 @@ module IsoDoc
160
169
  end
161
170
 
162
171
  def amend1(f)
163
- f.xpath(ns("./autonumber")).each { |a| a.remove }
172
+ f.xpath(ns("./autonumber")).each(&:remove)
164
173
  f.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
165
174
  f.xpath(ns("./description")).each { |a| a.replace(a.children) }
166
175
  f.replace(f.children)
@@ -1,29 +1,28 @@
1
- require "twitter_cldr"
2
- require "bigdecimal"
3
- require_relative "../../twitter-cldr/patch"
4
-
5
1
  module IsoDoc
6
2
  class PresentationXMLConvert < ::IsoDoc::Convert
7
3
  def prefix_container(container, linkend, _target)
8
- l10n(@xrefs.anchor(container, :xref) + ", " + linkend)
4
+ l10n("#{@xrefs.anchor(container, :xref)}, #{linkend}")
9
5
  end
10
6
 
11
7
  def anchor_linkend(node, linkend)
12
8
  if node["citeas"].nil? && node["bibitemid"]
13
- return @xrefs.anchor(node["bibitemid"] ,:xref) || "???"
9
+ return @xrefs.anchor(node["bibitemid"], :xref) || "???"
14
10
  elsif node["target"] && node["droploc"]
15
- return @xrefs.anchor(node["target"], :value) || @xrefs.anchor(node["target"], :label) ||
11
+ return @xrefs.anchor(node["target"], :value) ||
12
+ @xrefs.anchor(node["target"], :label) ||
16
13
  @xrefs.anchor(node["target"], :xref) || "???"
17
14
  elsif node["target"] && !/.#./.match(node["target"])
18
15
  linkend = anchor_linkend1(node)
19
16
  end
17
+
20
18
  linkend || "???"
21
19
  end
22
20
 
23
21
  def anchor_linkend1(node)
24
22
  linkend = @xrefs.anchor(node["target"], :xref)
25
23
  container = @xrefs.anchor(node["target"], :container, false)
26
- (container && get_note_container_id(node) != container && @xrefs.get[node["target"]]) &&
24
+ (container && get_note_container_id(node) != container &&
25
+ @xrefs.get[node["target"]]) and
27
26
  linkend = prefix_container(container, linkend, node["target"])
28
27
  capitalise_xref(node, linkend)
29
28
  end
@@ -32,86 +31,108 @@ module IsoDoc
32
31
  return linkend unless %w(Latn Cyrl Grek).include? @script
33
32
  return linkend&.capitalize if node["case"] == "capital"
34
33
  return linkend&.downcase if node["case"] == "lowercase"
35
- return linkend if linkend[0,1].match(/\p{Upper}/)
34
+ return linkend if linkend[0, 1].match?(/\p{Upper}/)
35
+
36
36
  prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
37
37
  node.xpath("./preceding::text()")
38
- (prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map { |p| p.text }.join)) ? linkend&.capitalize : linkend
38
+ if prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map(&:text).join)
39
+ linkend&.capitalize
40
+ else linkend
41
+ end
39
42
  end
40
43
 
41
44
  def nearest_block_parent(node)
42
- until %w(p title td th name formula li dt dd sourcecode pre).include?(node.name)
43
- node = node.parent
45
+ until %w(p title td th name formula li dt dd sourcecode pre)
46
+ .include?(node.name)
47
+ node = node.parent
44
48
  end
45
49
  node
46
50
  end
47
51
 
48
52
  def non_locality_elems(node)
49
- node.children.select do |c|
50
- !%w{locality localityStack}.include? c.name
53
+ node.children.reject do |c|
54
+ %w{locality localityStack}.include? c.name
51
55
  end
52
56
  end
53
57
 
54
- def get_linkend(n)
55
- contents = non_locality_elems(n).select { |c| !c.text? || /\S/.match(c) }
56
- return unless contents.empty?
57
- link = anchor_linkend(n, docid_l10n(n["target"] || n["citeas"]))
58
- link += eref_localities(n.xpath(ns("./locality | ./localityStack")), link)
59
- non_locality_elems(n).each { |n| n.remove }
60
- n.add_child(link)
58
+ def get_linkend(node)
59
+ c1 = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
60
+ return unless c1.empty?
61
+
62
+ link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
63
+ link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
64
+ link, node)
65
+ non_locality_elems(node).each(&:remove)
66
+ node.add_child(link)
61
67
  end
62
68
  # so not <origin bibitemid="ISO7301" citeas="ISO 7301">
63
69
  # <locality type="section"><reference>3.1</reference></locality></origin>
64
70
 
65
- def eref_localities(refs, target)
71
+ def eref_localities(refs, target, node)
66
72
  ret = ""
67
73
  refs.each_with_index do |r, i|
68
74
  delim = ","
69
- delim = ";" if r.name == "localityStack" && i>0
70
- ret = eref_locality_stack(r, i, target, delim, ret)
75
+ delim = ";" if r.name == "localityStack" && i.positive?
76
+ ret = eref_locality_stack(r, i, target, delim, ret, node)
71
77
  end
72
78
  ret
73
79
  end
74
80
 
75
- def eref_locality_stack(r, i, target, delim, ret)
76
- if r.name == "localityStack"
77
- r.elements.each_with_index do |rr, j|
78
- ret += eref_localities0(rr, j, target, delim)
81
+ def eref_locality_stack(ref, idx, target, delim, ret, node)
82
+ if ref.name == "localityStack"
83
+ ref.elements.each_with_index do |rr, j|
84
+ ret += eref_localities0(rr, j, target, delim, node)
79
85
  delim = ","
80
86
  end
81
87
  else
82
- ret += eref_localities0(r, i, target, delim)
88
+ ret += eref_localities0(ref, idx, target, delim, node)
83
89
  end
84
90
  ret
85
91
  end
86
92
 
87
- def eref_localities0(r, i, target, delim)
88
- if r["type"] == "whole" then l10n("#{delim} #{@i18n.wholeoftext}")
93
+ def eref_localities0(ref, _i, target, delim, node)
94
+ if ref["type"] == "whole" then l10n("#{delim} #{@i18n.wholeoftext}")
89
95
  else
90
- eref_localities1(target, r["type"], r.at(ns("./referenceFrom")), r.at(ns("./referenceTo")), delim, @lang)
96
+ eref_localities1(target, ref["type"], ref.at(ns("./referenceFrom")),
97
+ ref.at(ns("./referenceTo")), delim, node, @lang)
91
98
  end
92
99
  end
93
100
 
94
101
  # TODO: move to localization file
95
- def eref_localities1_zh(target, type, from, to, delim)
102
+ def eref_localities1_zh(_target, type, from, to, node, delim)
96
103
  ret = "#{delim} 第#{from.text}" if from
97
104
  ret += "&ndash;#{to.text}" if to
98
- loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize )
99
- ret += " #{loc}"
105
+ loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize)
106
+ ret += " #{loc}" unless node["droploc"] == "true"
100
107
  ret
101
108
  end
102
109
 
103
110
  # TODO: move to localization file
104
- def eref_localities1(target, type, from, to, delim, lang = "en")
111
+ def eref_localities1(target, type, from, to, delim, node, lang = "en")
105
112
  return "" if type == "anchor"
106
- lang == "zh" and return l10n(eref_localities1_zh(target, type, from, to, delim))
113
+
114
+ lang == "zh" and
115
+ return l10n(eref_localities1_zh(target, type, from, to, node, delim))
107
116
  ret = delim
108
- loc = @i18n.locality[type] || type.sub(/^locality:/, "").capitalize
109
- ret += " #{loc}"
117
+ ret += eref_locality_populate(type, node)
110
118
  ret += " #{from.text}" if from
111
119
  ret += "&ndash;#{to.text}" if to
112
120
  l10n(ret)
113
121
  end
114
122
 
123
+ def eref_locality_populate(type, node)
124
+ return "" if node["droploc"] == "true"
125
+
126
+ loc = @i18n.locality[type] || type.sub(/^locality:/, "")
127
+ loc = case node["case"]
128
+ when "capital" then loc.capitalize
129
+ when "lowercase" then loc.downcase
130
+ else
131
+ loc.capitalize
132
+ end
133
+ " #{loc}"
134
+ end
135
+
115
136
  def xref(docxml)
116
137
  docxml.xpath(ns("//xref")).each { |f| xref1(f) }
117
138
  end
@@ -128,8 +149,8 @@ module IsoDoc
128
149
  docxml.xpath(ns("//quote/source")).each { |f| xref1(f) }
129
150
  end
130
151
 
131
- def xref1(f)
132
- get_linkend(f)
152
+ def xref1(node)
153
+ get_linkend(node)
133
154
  end
134
155
 
135
156
  def concept(docxml)
@@ -137,108 +158,44 @@ module IsoDoc
137
158
  end
138
159
 
139
160
  def concept1(node)
140
- content = node.first_element_child.children.select do |c|
141
- !%w{locality localityStack}.include? c.name
161
+ content = node.first_element_child.children.reject do |c|
162
+ %w{locality localityStack}.include? c.name
142
163
  end.select { |c| !c.text? || /\S/.match(c) }
143
- node.replace content.empty? ?
144
- @i18n.term_defined_in.sub(/%/, node.first_element_child.to_xml) :
145
- "<em>#{node.children.to_xml}</em>"
146
- end
147
-
148
-
149
- MATHML = { "m" => "http://www.w3.org/1998/Math/MathML" }.freeze
150
-
151
- def mathml(docxml)
152
- locale = twitter_cldr_localiser()
153
- docxml.xpath("//m:math", MATHML).each do |f|
154
- mathml1(f, locale)
155
- end
156
- end
157
-
158
- # symbols is merged into
159
- # TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols
160
- def localize_maths(f, locale)
161
- f.xpath(".//m:mn", MATHML).each do |x|
162
- num = BigDecimal(x.text)
163
- precision = /\./.match(x.text) ? x.text.sub(/^.*\./, "").size : 0
164
- x.children = localized_number(num, locale, precision)
165
- end
166
- end
167
-
168
- # By itself twitter-cldr does not support fraction part digits grouping
169
- # and custom delimeter, will decorate fraction part manually
170
- def localized_number(num, locale, precision)
171
- TwitterCldr::Localized::LocalizedNumber.localize(BigDecimal)
172
- localized = (precision == 0) ? num.localize(locale).to_s :
173
- num.localize(locale).to_decimal.to_s(:precision => precision)
174
- twitter_cldr_reader_symbols = twitter_cldr_reader(locale)
175
- return localized unless twitter_cldr_reader_symbols[:decimal]
176
- integer, fraction = localized.split(twitter_cldr_reader_symbols[:decimal])
177
- return localized if fraction.nil? || fraction.length.zero?
178
- [integer, decorate_fraction_part(fraction, locale)].join(twitter_cldr_reader_symbols[:decimal])
179
- end
180
-
181
- def decorate_fraction_part(fract, locale)
182
- result = []
183
- twitter_cldr_reader_symbols = twitter_cldr_reader(locale)
184
- fract = fract.slice(0..(twitter_cldr_reader_symbols[:precision] || -1))
185
- fr_group_digits = twitter_cldr_reader_symbols[:fraction_group_digits] || 1
186
- until fract.empty?
187
- result.push(fract.slice!(0, fr_group_digits))
188
- end
189
- result.join(twitter_cldr_reader_symbols[:fraction_group].to_s)
190
- end
191
-
192
- def twitter_cldr_localiser_symbols
193
- {}
194
- end
195
-
196
- def twitter_cldr_reader(locale)
197
- num = TwitterCldr::DataReaders::NumberDataReader.new(locale)
198
- num.symbols.merge!(twitter_cldr_localiser_symbols)
199
- end
200
-
201
- def twitter_cldr_localiser()
202
- locale = TwitterCldr.supported_locale?(@lang.to_sym) ? @lang.to_sym : :en
203
- twitter_cldr_reader(locale)
204
- locale
205
- end
206
-
207
- def mathml1(f, locale)
208
- localize_maths(f, locale)
209
- return unless f.elements.size == 1 && f.elements.first.name == "mn"
210
- if f.parent.name == "stem"
211
- f.parent.replace(f.at("./m:mn", MATHML).children)
164
+ if node.replace content.empty?
165
+ @i18n.term_defined_in.sub(/%/, node.first_element_child.to_xml)
212
166
  else
213
- f.replace(f.at("./m:mn", MATHML).children)
167
+ "<em>#{node.children.to_xml}</em>"
214
168
  end
215
169
  end
216
170
 
217
171
  def variant(docxml)
218
172
  docxml.xpath(ns("//variant")).each { |f| variant1(f) }
219
- docxml.xpath(ns("//variant[@remove = 'true']")).each { |f| f.remove }
173
+ docxml.xpath(ns("//variant[@remove = 'true']")).each(&:remove)
220
174
  docxml.xpath(ns("//variant")).each do |v|
221
175
  next unless v&.next&.name == "variant"
176
+
222
177
  v.next = "/"
223
178
  end
224
179
  docxml.xpath(ns("//variant")).each { |f| f.replace(f.children) }
225
180
  end
226
181
 
227
182
  def variant1(node)
228
- if (!node["lang"] || node["lang"] == @lang) && (!node["script"] || node["script"] == @script)
183
+ if (!node["lang"] || node["lang"] == @lang) &&
184
+ (!node["script"] || node["script"] == @script)
229
185
  elsif found_matching_variant_sibling(node)
230
186
  node["remove"] = "true"
231
- else
232
- #return unless !node.at("./preceding-sibling::xmlns:variant")
233
187
  end
234
188
  end
235
189
 
190
+ private
191
+
236
192
  def found_matching_variant_sibling(node)
237
193
  prev = node.xpath("./preceding-sibling::xmlns:variant")
238
194
  foll = node.xpath("./following-sibling::xmlns:variant")
239
195
  found = false
240
196
  (prev + foll).each do |n|
241
- found = true if n["lang"] == @lang && (!n["script"] || n["script"] == @script)
197
+ found = true if n["lang"] == @lang &&
198
+ (!n["script"] || n["script"] == @script)
242
199
  end
243
200
  found
244
201
  end