metanorma-utils 1.2.7 → 1.2.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43530083e199af0abeff8df1b697507ed4f08f5039de4acba24409008c51e534
4
- data.tar.gz: 19a237c0c4134abbf35daeeff19e0aeea715a528c9f55cd6150908460f21bed1
3
+ metadata.gz: 292c59c5af886a4ee9c6536f299fce7f70c8ebe58009bdd317ee438411a1ea0b
4
+ data.tar.gz: '0593b2df3787f376b0369cadd96b277f988cab030a60f90104599ec86f9b481e'
5
5
  SHA512:
6
- metadata.gz: a910ee73c2ee55d26cae92489643cd41b6de237f663910030475f4de1e295b45e6199f0722bc1dd8665007ccb0a3fdd1117fdb6dcb9a1dada1afc3998cd8e346
7
- data.tar.gz: 8942457b7b8a19372a9a559c7db552e5c63675d2f26f24a17d47962c65c4cddd491eadfc56223533b8412f34c52cafbb3f818f16246c24ce76ed8b62810206d9
6
+ metadata.gz: ea0f40979be2bde7c11bf6ee30cf02e67d924928383c6d9bbcef20d67b1db686c4528fdc4a0e8b54b019dcc988e18c405f011e282445290a3638bcfa38737fe5
7
+ data.tar.gz: ec2c9516dc1e4161a7c07d1d7b96cd9c826ee33fff2e1ca322c63eb7ef3163de3ce597e5d19a49eea009bff2fb81e00923e56ee74109b58ff6765b42f3114079
data/lib/utils/image.rb CHANGED
@@ -115,8 +115,10 @@ module Metanorma
115
115
  svg.xpath("//m:style", "m" => SVG_NS).each do |s|
116
116
  c = s.children.to_xml
117
117
  ids.each do |i|
118
- c = c.gsub(%r[##{i}\b], sprintf("#%s_%09d", i, idx))
119
- .gsub(%r(\[id\s*=\s*['"]?#{i}['"]?\]), sprintf("[id='%s_%09d']", i, idx))
118
+ c = c.gsub(%r[##{i}\b],
119
+ sprintf("#%<id>s_%<idx>09d", id: i, idx: idx))
120
+ .gsub(%r(\[id\s*=\s*['"]?#{i}['"]?\]),
121
+ sprintf("[id='%<id>s_%<idx>09d']", id: i, idx: idx))
120
122
  end
121
123
  s.children = c
122
124
  end
data/lib/utils/log.rb CHANGED
@@ -29,7 +29,7 @@ module Metanorma
29
29
  (!node.respond_to?(:level) || node.level.positive?) &&
30
30
  (!node.respond_to?(:context) || node.context != :section)
31
31
  node = node.parent
32
- return "Section: #{node.title}" if node&.respond_to?(:context) &&
32
+ return "Section: #{node.title}" if node.respond_to?(:context) &&
33
33
  node&.context == :section
34
34
  end
35
35
  "??"
@@ -50,13 +50,19 @@ module Metanorma
50
50
  @log.each_key do |key|
51
51
  f.puts "\n\n== #{key}\n\n"
52
52
  @log[key].sort_by { |a| a[:location] }.each do |n|
53
- loc = n[:location] ? "(#{n[:location]}): " : ""
54
- f.puts "#{loc}#{n[:message]}"
55
- n[:context]&.split(/\n/)&.first(5)&.each { |l| f.puts "\t#{l}" }
53
+ write1(f, n)
56
54
  end
57
55
  end
58
56
  end
59
57
  end
58
+
59
+ def write1(file, entry)
60
+ loc = entry[:location] ? "(#{entry[:location]}): " : ""
61
+ file.puts "#{loc}#{entry[:message]}"
62
+ entry[:context]&.split(/\n/)&.first(5)&.each do |l|
63
+ file.puts "\t#{l}"
64
+ end
65
+ end
60
66
  end
61
67
  end
62
68
  end
data/lib/utils/main.rb CHANGED
@@ -68,10 +68,8 @@ module Metanorma
68
68
  def set_nested_value(hash, keys, new_val)
69
69
  key = keys[0]
70
70
  if keys.length == 1
71
- hash[key] = if hash[key].is_a?(Array)
72
- (hash[key] << new_val)
73
- else
74
- hash[key].nil? ? new_val : [hash[key], new_val]
71
+ hash[key] = if hash[key].is_a?(Array) then (hash[key] << new_val)
72
+ else hash[key].nil? ? new_val : [hash[key], new_val]
75
73
  end
76
74
  elsif hash[key].is_a?(Array)
77
75
  hash[key][-1] = {} if !hash[key].empty? && hash[key][-1].nil?
@@ -118,6 +116,26 @@ module Metanorma
118
116
  end
119
117
  end
120
118
 
119
+ def default_script(lang)
120
+ case lang
121
+ when "ar", "fa" then "Arab"
122
+ when "ur" then "Aran"
123
+ when "ru", "bg" then "Cyrl"
124
+ when "hi" then "Deva"
125
+ when "el" then "Grek"
126
+ when "zh" then "Hans"
127
+ when "ko" then "Kore"
128
+ when "he" then "Hebr"
129
+ when "ja" then "Jpan"
130
+ else
131
+ "Latn"
132
+ end
133
+ end
134
+
135
+ def rtl_script?(script)
136
+ %w(Arab Aran Hebr).include? script
137
+ end
138
+
121
139
  # not currently used
122
140
  def flatten_rawtext_lines(node, result)
123
141
  node.lines.each do |x|
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.2.7".freeze
3
+ VERSION = "1.2.8".freeze
4
4
  end
5
5
  end
data/spec/utils_spec.rb CHANGED
@@ -7,8 +7,10 @@ RSpec.describe Metanorma::Utils do
7
7
  end
8
8
 
9
9
  it "capitalises" do
10
- expect(Metanorma::Utils.strict_capitalize_phrase("ABC def gHI")).to eq "ABC Def GHI"
11
- expect(Metanorma::Utils.strict_capitalize_first("aBC def gHI")).to eq "ABC def gHI"
10
+ expect(Metanorma::Utils.strict_capitalize_phrase("ABC def gHI"))
11
+ .to eq "ABC Def GHI"
12
+ expect(Metanorma::Utils.strict_capitalize_first("aBC def gHI"))
13
+ .to eq "ABC def gHI"
12
14
  end
13
15
 
14
16
  it "converts OS-specific external path" do
@@ -29,12 +31,13 @@ RSpec.describe Metanorma::Utils do
29
31
  end
30
32
 
31
33
  it "sets metanorma IDs if not provided" do
34
+ uuid = /^_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
32
35
  expect(Metanorma::Utils.anchor_or_uuid)
33
- .to match (/^_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
36
+ .to match (uuid)
34
37
  expect(Metanorma::Utils.anchor_or_uuid(Dummy.new(nil)))
35
- .to match (/^_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
38
+ .to match (uuid)
36
39
  expect(Metanorma::Utils.anchor_or_uuid(Dummy.new("")))
37
- .to match (/^_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
40
+ .to match (uuid)
38
41
  expect(Metanorma::Utils.anchor_or_uuid(Dummy.new("A"))).to eq "A"
39
42
  end
40
43
 
@@ -55,7 +58,8 @@ RSpec.describe Metanorma::Utils do
55
58
 
56
59
  it "applies smart formatting" do
57
60
  expect(Metanorma::Utils.smartformat("A - B A -- B A--B '80s '80' <A>"))
58
- .to eq "A&#8201;&#8212;&#8201;B A&#8201;&#8212;&#8201;B A&#8212;B ’80s ‘80’ &lt;A&gt;"
61
+ .to eq "A&#8201;&#8212;&#8201;B A&#8201;&#8212;&#8201;B "\
62
+ "A&#8212;B ’80s ‘80’ &lt;A&gt;"
59
63
  end
60
64
 
61
65
  it "applies en-dash normalisation" do
@@ -98,6 +102,14 @@ RSpec.describe Metanorma::Utils do
98
102
  OUTPUT
99
103
  end
100
104
 
105
+ it "maps languages to scripts" do
106
+ expect(Metanorma::Utils.default_script("hi")).to eq "Deva"
107
+ expect(Metanorma::Utils.rtl_script?(Metanorma::Utils.default_script("el")))
108
+ .to eq false
109
+ expect(Metanorma::Utils.rtl_script?(Metanorma::Utils.default_script("fa")))
110
+ .to eq true
111
+ end
112
+
101
113
  it "rewrites SVGs" do
102
114
  FileUtils.cp("spec/fixtures/action_schemaexpg1.svg",
103
115
  "action_schemaexpg1.svg")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-29 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -339,7 +339,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
339
339
  - !ruby/object:Gem::Version
340
340
  version: '0'
341
341
  requirements: []
342
- rubygems_version: 3.2.22
342
+ rubygems_version: 3.2.32
343
343
  signing_key:
344
344
  specification_version: 4
345
345
  summary: metanorma-utils