isodoc 2.0.6.1 → 2.0.7

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: c32b98e8156bdafb3ad6549d179b6607cc7811bf67191cf0ee736b6c72d5360f
4
- data.tar.gz: 63236257e5e7f511e6cfe2ea9ff5c7a12dd2059be3bc588c50f15c8946e4a01d
3
+ metadata.gz: e038a4b4f203a16e86b716deffc9602d005c305312aebedbaf88231cfe263a60
4
+ data.tar.gz: 0f873f9ce5847c0a33296714a60917d3112a95ef04f3b2ea7052b18f0fcdab8c
5
5
  SHA512:
6
- metadata.gz: 58a629b21dee494368d7ad6c9f25fc3ac01ccb5f70b82674843cefdcb0959c484f770174ccb9ce75e52f4d4f906918fe1f390405dafd91119c945bade6ff716b
7
- data.tar.gz: 11332100db734b1fd700ecfe164fb80ae0fd4be9843c6e48ffac4ea2c0d2d1ef4c417cb9e78c1a5d9cbae68294acac7f98fcb8365c10808a38153fae1f1dd2dd
6
+ metadata.gz: 8c146a97d03c932fe72755edf96a9ad26806daf7c7de07814f8afd93714e1a88193b476e972bed1c17820eeca3f9216c6e07931d8fe56e6d036f857d9537339d
7
+ data.tar.gz: c081e93e7e29fd600f5968550a51a81c29f5663c6d5fb45c6f0a853978a3fdc1bc07d06a4b4e3161a4c67c78c3de7cd3ecc2e5b18999e25fec2d88ce010d9998
data/isodoc.gemspec CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency "asciimath"
32
32
  spec.add_dependency "html2doc", "~> 1.3.0"
33
33
  spec.add_dependency "htmlentities", "~> 4.3.4"
34
+ spec.add_dependency "isodoc-i18n", "~> 1.0.0"
34
35
  spec.add_dependency "liquid", "~> 4"
35
36
  # spec.add_dependency "metanorma", ">= 1.2.0"
36
37
  spec.add_dependency "emf2svg", "~> 1"
data/lib/isodoc/i18n.rb CHANGED
@@ -1,28 +1,9 @@
1
1
  require "yaml"
2
+ require "isodoc-i18n"
2
3
  require_relative "function/utils"
3
4
 
4
5
  module IsoDoc
5
6
  class I18n
6
- def load_yaml(lang, script, i18nyaml = nil)
7
- ret = load_yaml1(lang, script)
8
- return normalise_hash(ret.merge(YAML.load_file(i18nyaml))) if i18nyaml
9
-
10
- normalise_hash(ret)
11
- end
12
-
13
- def normalise_hash(ret)
14
- case ret
15
- when Hash
16
- ret.each do |k, v|
17
- ret[k] = normalise_hash(v)
18
- end
19
- ret
20
- when Array then ret.map { |n| normalise_hash(n) }
21
- when String then cleanup_entities(ret.unicode_normalize(:nfc))
22
- else ret
23
- end
24
- end
25
-
26
7
  def load_yaml1(lang, script)
27
8
  case lang
28
9
  when "en", "fr", "ru", "de", "es", "ar"
@@ -40,93 +21,5 @@ module IsoDoc
40
21
  YAML.load_file(File.join(File.dirname(__FILE__),
41
22
  "../isodoc-yaml/i18n-#{str}.yaml"))
42
23
  end
43
-
44
- def get
45
- @labels
46
- end
47
-
48
- def set(key, val)
49
- @labels[key] = val
50
- end
51
-
52
- def initialize(lang, script, i18nyaml = nil)
53
- @lang = lang
54
- @script = script
55
- y = load_yaml(lang, script, i18nyaml)
56
- @labels = y
57
- @labels["language"] = @lang
58
- @labels["script"] = @script
59
- @labels.each do |k, _v|
60
- self.class.send(:define_method, k.downcase) { get[k] }
61
- end
62
- end
63
-
64
- def self.l10n(text, lang = @lang, script = @script)
65
- l10n(text, lang, script)
66
- end
67
-
68
- # TODO: move to localization file
69
- # function localising spaces and punctuation.
70
- # Not clear if period needs to be localised for zh
71
- def l10n(text, lang = @lang, script = @script)
72
- if lang == "zh" && script == "Hans" then l10n_zh(text)
73
- else bidiwrap(text, lang, script)
74
- end
75
- end
76
-
77
- def bidiwrap(text, lang, script)
78
- my_script, my_rtl, outer_rtl = bidiwrap_vars(lang, script)
79
- if my_rtl && !outer_rtl
80
- mark = %w(Arab Aran).include?(my_script) ? "؜" : "‏"
81
- "#{mark}#{text}#{mark}"
82
- elsif !my_rtl && outer_rtl then "‎#{text}‎"
83
- else text
84
- end
85
- end
86
-
87
- def bidiwrap_vars(lang, script)
88
- my_script = script || Metanorma::Utils.default_script(lang)
89
- [my_script,
90
- Metanorma::Utils.rtl_script?(my_script),
91
- Metanorma::Utils.rtl_script?(@script || Metanorma::Utils
92
- .default_script(@lang))]
93
- end
94
-
95
- def l10n_zh(text)
96
- xml = Nokogiri::HTML::DocumentFragment.parse(text)
97
- xml.traverse do |n|
98
- next unless n.text?
99
-
100
- n.replace(cleanup_entities(n.text.gsub(/ /, "").gsub(/:/, ":")
101
- .gsub(/,/, "、").gsub(/\(/, "(").gsub(/\)/, ")")
102
- .gsub(/\[/, "【").gsub(/\]/, "】"), is_xml: false))
103
- end
104
- xml.to_xml.gsub(/<b>/, "").gsub("</b>", "").gsub(/<\?[^>]+>/, "")
105
- end
106
-
107
- def boolean_conj(list, conn)
108
- case list.size
109
- when 0 then ""
110
- when 1 then list.first
111
- when 2 then @labels["binary_#{conn}"].sub(/%1/, list[0])
112
- .sub(/%2/, list[1])
113
- else
114
- @labels["multiple_#{conn}"]
115
- .sub(/%1/, l10n(list[0..-2].join(", "), @lang, @script))
116
- .sub(/%2/, list[-1])
117
- end
118
- end
119
-
120
- # def multiple_and(names, andword)
121
- # return "" if names.empty?
122
- # return names[0] if names.length == 1
123
- #
124
- # (names.length == 2) &&
125
- # (return l10n("#{names[0]} #{andword} #{names[1]}", @lang, @script))
126
- # l10n(names[0..-2].join(", ") + " #{andword} #{names[-1]}", @lang, @script)
127
- # end
128
-
129
- include Function::Utils
130
- # module_function :l10n
131
24
  end
132
25
  end
@@ -76,16 +76,25 @@ module IsoDoc
76
76
  def bibliography_bibitem_number(docxml)
77
77
  i = 0
78
78
  docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
79
- next if bibliography_bibitem_number_skip(b)
80
-
81
- i += 1
82
- id = b.at(ns(".//docidentifier"))
83
- id.previous =
84
- "<docidentifier type='metanorma-ordinal'>[#{i}]</docidentifier>"
79
+ i = bibliography_bibitem_number1(b, i)
85
80
  end
86
81
  @xrefs.references docxml
87
82
  end
88
83
 
84
+ def bibliography_bibitem_number1(bibitem, idx)
85
+ if mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']"))
86
+ /^\[?\d\]?$/.match?(mn&.text) and
87
+ idx = mn.text.sub(/^\[/, "").sub(/\]$/, "").to_i
88
+ end
89
+ unless bibliography_bibitem_number_skip(bibitem)
90
+
91
+ idx += 1
92
+ bibitem.at(ns(".//docidentifier")).previous =
93
+ "<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
94
+ end
95
+ idx
96
+ end
97
+
89
98
  def docid_prefixes(docxml)
90
99
  docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
91
100
  i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.0.6.1".freeze
2
+ VERSION = "2.0.7".freeze
3
3
  end
@@ -854,4 +854,52 @@ RSpec.describe IsoDoc do
854
854
  .to be_equivalent_to xmlpp(presxml)
855
855
  end
856
856
 
857
+ it "enforces consistent metanorma-ordinal numbering" do
858
+ input = <<~INPUT
859
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
860
+ <bibdata>
861
+ <language>en</language>
862
+ </bibdata>
863
+ <bibliography><references id="_normative_references" obligation="informative" normative="false"><title>Bibliography</title>
864
+ <bibitem id="ref1" type="standard">
865
+ <title format="text/plain">Cereals or cereal products</title>
866
+ <docidentifier type="IEC">IEC 217</docidentifier>
867
+ </bibitem>
868
+ <bibitem id="ref2" type="standard">
869
+ <title format="text/plain">Cereals or cereal products</title>
870
+ <docidentifier type="metanorma">[3]</docidentifier>
871
+ </bibitem>
872
+ <bibitem id="ref3" type="standard">
873
+ <title format="text/plain">Cereals or cereal products</title>
874
+ <docidentifier>ABC</docidentifier>
875
+ </bibitem>
876
+ </references></bibliography></iso-standard>
877
+ INPUT
878
+ presxml = <<~PRESXML
879
+ <bibliography>
880
+ <references id='_normative_references' obligation='informative' normative='false' displayorder='1'>
881
+ <title depth='1'>Bibliography</title>
882
+ <bibitem id='ref1' type='standard'>
883
+ <title format='text/plain'>Cereals or cereal products</title>
884
+ <docidentifier type='metanorma-ordinal'>[1]</docidentifier>
885
+ <docidentifier type='IEC'>IEC 217</docidentifier>
886
+ </bibitem>
887
+ <bibitem id='ref2' type='standard'>
888
+ <title format='text/plain'>Cereals or cereal products</title>
889
+ <docidentifier type='metanorma'>[3]</docidentifier>
890
+ </bibitem>
891
+ <bibitem id='ref3' type='standard'>
892
+ <title format='text/plain'>Cereals or cereal products</title>
893
+ <docidentifier type='metanorma-ordinal'>[4]</docidentifier>
894
+ <docidentifier>ABC</docidentifier>
895
+ </bibitem>
896
+ </references>
897
+ </bibliography>
898
+ PRESXML
899
+ expect(xmlpp(Nokogiri::XML(
900
+ IsoDoc::PresentationXMLConvert.new({})
901
+ .convert("test", input, true),
902
+ ).at("//xmlns:bibliography").to_xml))
903
+ .to be_equivalent_to xmlpp(presxml)
904
+ end
857
905
  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.0.6.1
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-22 00:00:00.000000000 Z
11
+ date: 2022-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 4.3.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: isodoc-i18n
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: liquid
57
71
  requirement: !ruby/object:Gem::Requirement