metanorma-utils 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/utils/image.rb +4 -2
- data/lib/utils/log.rb +10 -4
- data/lib/utils/main.rb +22 -4
- data/lib/utils/version.rb +1 -1
- data/spec/utils_spec.rb +18 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 292c59c5af886a4ee9c6536f299fce7f70c8ebe58009bdd317ee438411a1ea0b
|
4
|
+
data.tar.gz: '0593b2df3787f376b0369cadd96b277f988cab030a60f90104599ec86f9b481e'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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],
|
119
|
-
|
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
|
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
|
-
|
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
|
-
|
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
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"))
|
11
|
-
|
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 (
|
36
|
+
.to match (uuid)
|
34
37
|
expect(Metanorma::Utils.anchor_or_uuid(Dummy.new(nil)))
|
35
|
-
.to match (
|
38
|
+
.to match (uuid)
|
36
39
|
expect(Metanorma::Utils.anchor_or_uuid(Dummy.new("")))
|
37
|
-
.to match (
|
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 — B A — B
|
61
|
+
.to eq "A — B A — B "\
|
62
|
+
"A—B ’80s ‘80’ <A>"
|
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.
|
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
|
+
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.
|
342
|
+
rubygems_version: 3.2.32
|
343
343
|
signing_key:
|
344
344
|
specification_version: 4
|
345
345
|
summary: metanorma-utils
|