metanorma-utils 1.6.4 → 1.6.5

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: 57cdd3eb9d930975ba70e75b1a93fa61b071ad0a84f6d9acb9173f39e4ab9461
4
- data.tar.gz: 7d7db96c6baf145635b80c7538191582c98acde5d47698e0f5743b706e5c9a8b
3
+ metadata.gz: c3f777cb3ba87e217a3b56ee8caf1a2cd8f6948a8664e18900c6eb5494d162f9
4
+ data.tar.gz: 6a758b7d70a52f55c71d8db3562ea32a0f19de514948d17a48bee811850e0b16
5
5
  SHA512:
6
- metadata.gz: f32fd8887a434a77e6f99ad81c5dafb8677096787c7fbae70cf4aeac4d5d264913639a9f216aa0793f8f3b7637ff78303372d7c8ee5072c516ca983436a3c47e
7
- data.tar.gz: d9434cdece35bd9f95f9366a987d11995c19dca2bf2cd348ab1cf877a3fff96c66f69dc137cebc9d548a3b8c7a01ef3f0d196993b3873e62d58cceea9c277a21
6
+ metadata.gz: 2bf9b223b840ea02f05c3fe37cc6d12ab73044da84f5108c5f94323a096a567934deec55ddce269f616382b09e98f2be1bc8d835120b6127549ee3febd00bcaf
7
+ data.tar.gz: 5447a68582a1c245e1d8a1763573b956ae5999e7ed3a4b8f057e57b301cdc16d5cf2db99fa64bcdd6cb9f0047114fb75b812232fca7303c49ee9095a72387646
data/Gemfile CHANGED
@@ -4,8 +4,12 @@ Encoding.default_internal = Encoding::UTF_8
4
4
  source "https://rubygems.org"
5
5
  git_source(:github) { |repo| "https://github.com/#{repo}" }
6
6
 
7
- gemspec
7
+ group :development, :test do
8
+ gem "rspec"
9
+ end
8
10
 
9
11
  if File.exist? "Gemfile.devel"
10
12
  eval File.read("Gemfile.devel"), nil, "Gemfile.devel" # rubocop:disable Security/Eval
11
13
  end
14
+
15
+ gemspec
data/lib/utils/log.rb CHANGED
@@ -11,23 +11,32 @@ module Metanorma
11
11
  @mapid = {}
12
12
  end
13
13
 
14
- def add(category, loc, msg)
14
+ # severity: 0: abort; 1: serious; 2: not serious
15
+ def add(category, loc, msg, severity: 2)
15
16
  @novalid and return
16
17
  @log[category] ||= []
17
- item = create_entry(loc, msg)
18
+ item = create_entry(loc, msg, severity)
18
19
  @log[category] << item
19
20
  loc = loc.nil? ? "" : "(#{current_location(loc)}): "
20
21
  suppress_display?(category, loc, msg) or
21
22
  warn "#{category}: #{loc}#{msg}"
22
23
  end
23
24
 
25
+ def abort_messages
26
+ @log.values.each_with_object([]) do |v, m|
27
+ v.each do |e|
28
+ e[:severity].zero? and m << e[:message]
29
+ end
30
+ end
31
+ end
32
+
24
33
  def suppress_display?(category, _loc, _msg)
25
34
  ["Metanorma XML Syntax"].include?(category)
26
35
  end
27
36
 
28
- def create_entry(loc, msg)
37
+ def create_entry(loc, msg, severity)
29
38
  msg = msg.encode("UTF-8", invalid: :replace, undef: :replace)
30
- item = { location: current_location(loc),
39
+ item = { location: current_location(loc), severity: severity,
31
40
  message: msg, context: context(loc), line: line(loc, msg) }
32
41
  if item[:message].include?(" :: ")
33
42
  a = item[:message].split(" :: ", 2)
@@ -101,7 +110,11 @@ module Metanorma
101
110
  <<~HTML
102
111
  <html><head><title>#{file} errors</title>
103
112
  <meta charset="UTF-8"/>
104
- <style> pre { white-space: pre-wrap; } </style>
113
+ <style> pre { white-space: pre-wrap; }
114
+ thead th { font-weight: bold; background-color: aqua; }
115
+ .severity0 { font-weight: bold; background-color: lightpink }
116
+ .severity1 { font-weight: bold; }
117
+ .severity2 { } </style>
105
118
  </head><body><h1>#{file} errors</h1>
106
119
  HTML
107
120
  end
@@ -118,25 +131,31 @@ module Metanorma
118
131
  def write_key(file, key)
119
132
  file.puts <<~HTML
120
133
  <h2>#{key}</h2>\n<table border="1">
121
- <thead><th width="5%">Line</th><th width="20%">ID</th><th width="30%">Message</th><th width="45%">Context</th></thead>
134
+ <thead><th width="5%">Line</th><th width="20%">ID</th>
135
+ <th width="30%">Message</th><th width="40%">Context</th><th width="5%">Severity</th></thead>
122
136
  <tbody>
123
137
  HTML
124
138
  @log[key].sort_by { |a| [a[:line], a[:location], a[:message]] }
125
139
  .each do |n|
126
- write1(file, n)
140
+ write_entry(file, render_preproc_entry(n))
127
141
  end
128
142
  file.puts "</tbody></table>\n"
129
143
  end
130
144
 
131
- def write1(file, entry)
132
- line = entry[:line]
133
- line = nil if line == "000000"
134
- loc = loc_link(entry)
135
- msg = break_up_long_str(entry[:message], 10, 2)
145
+ def render_preproc_entry(entry)
146
+ ret = entry.dup
147
+ ret[:line] = nil if ret[:line] == "000000"
148
+ ret[:location] = loc_link(entry)
149
+ ret[:message] = break_up_long_str(entry[:message], 10, 2)
136
150
  .gsub(/`([^`]+)`/, "<code>\\1</code>")
137
- entry[:context] and context = entry[:context].split("\n").first(5)
151
+ ret[:context] = context_render(entry)
152
+ ret.compact
153
+ end
154
+
155
+ def context_render(entry)
156
+ entry[:context] or return nil
157
+ entry[:context].split("\n").first(5)
138
158
  .join("\n").gsub("><", "> <")
139
- write_entry(file, line, loc, msg, context)
140
159
  end
141
160
 
142
161
  def mapid(old, new)
@@ -160,10 +179,12 @@ module Metanorma
160
179
  Metanorma::Utils.break_up_long_str(str, threshold, punct)
161
180
  end
162
181
 
163
- def write_entry(file, line, loc, msg, context)
164
- context &&= @c.encode(break_up_long_str(context, 40, 2))
182
+ def write_entry(file, entry)
183
+ entry[:context] &&= @c.encode(break_up_long_str(entry[:context], 40, 2))
165
184
  file.print <<~HTML
166
- <tr><td>#{line}</td><th><code>#{loc}</code></th><td>#{msg}</td><td><pre>#{context}</pre></td></tr>
185
+ <tr class="severity#{entry[:severity]}">
186
+ <td>#{entry[:line]}</td><th><code>#{entry[:location]}</code></th>
187
+ <td>#{entry[:message]}</td><td><pre>#{entry[:context]}</pre></td><td>#{entry[:severity]}</td></tr>
167
188
  HTML
168
189
  end
169
190
  end
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.6.4".freeze
3
+ VERSION = "1.6.5".freeze
4
4
  end
5
5
  end
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.6.4
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-20 00:00:00.000000000 Z
11
+ date: 2023-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor