metanorma-utils 1.6.3 → 1.6.5

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: cbe101c56bac70e6543c03f11abc88c0a1ea7645220c0b4f375f679956d507ae
4
- data.tar.gz: f9d7c68df7145fa585c6af6a253ccc1e587b841cbdc619fe4ace584026723623
3
+ metadata.gz: c3f777cb3ba87e217a3b56ee8caf1a2cd8f6948a8664e18900c6eb5494d162f9
4
+ data.tar.gz: 6a758b7d70a52f55c71d8db3562ea32a0f19de514948d17a48bee811850e0b16
5
5
  SHA512:
6
- metadata.gz: 5c2cf454f5fdf77753856c0e353b265b0f113a5adfd69cf17d654c774045c0a3623f34fb12255603da238f04448a68160d6c28a87c9ee4f0b2202a4ea4d7a01a
7
- data.tar.gz: d851a8005f82a55211329bce7fe957e126a8e913d249919a542a525bbb8119fae9fdb34d243364530db174e7e256dc2286f7c66f112bd274b3648e496e84c5d4
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,22 +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
- suppress_display?(category, loc, msg) or warn "#{category}: #{loc}#{msg}"
21
+ suppress_display?(category, loc, msg) or
22
+ warn "#{category}: #{loc}#{msg}"
21
23
  end
22
24
 
23
- def suppress_display?(category, loc, msg)
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
+
33
+ def suppress_display?(category, _loc, _msg)
24
34
  ["Metanorma XML Syntax"].include?(category)
25
35
  end
26
36
 
27
- def create_entry(loc, msg)
37
+ def create_entry(loc, msg, severity)
28
38
  msg = msg.encode("UTF-8", invalid: :replace, undef: :replace)
29
- item = { location: current_location(loc),
39
+ item = { location: current_location(loc), severity: severity,
30
40
  message: msg, context: context(loc), line: line(loc, msg) }
31
41
  if item[:message].include?(" :: ")
32
42
  a = item[:message].split(" :: ", 2)
@@ -99,7 +109,12 @@ module Metanorma
99
109
  def log_hdr(file)
100
110
  <<~HTML
101
111
  <html><head><title>#{file} errors</title>
102
- <style> pre { white-space: pre-wrap; } </style>
112
+ <meta charset="UTF-8"/>
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>
103
118
  </head><body><h1>#{file} errors</h1>
104
119
  HTML
105
120
  end
@@ -116,25 +131,31 @@ module Metanorma
116
131
  def write_key(file, key)
117
132
  file.puts <<~HTML
118
133
  <h2>#{key}</h2>\n<table border="1">
119
- <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>
120
136
  <tbody>
121
137
  HTML
122
138
  @log[key].sort_by { |a| [a[:line], a[:location], a[:message]] }
123
139
  .each do |n|
124
- write1(file, n)
140
+ write_entry(file, render_preproc_entry(n))
125
141
  end
126
142
  file.puts "</tbody></table>\n"
127
143
  end
128
144
 
129
- def write1(file, entry)
130
- line = entry[:line]
131
- line = nil if line == "000000"
132
- loc = loc_link(entry)
133
- 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)
134
150
  .gsub(/`([^`]+)`/, "<code>\\1</code>")
135
- 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)
136
158
  .join("\n").gsub("><", "> <")
137
- write_entry(file, line, loc, msg, context)
138
159
  end
139
160
 
140
161
  def mapid(old, new)
@@ -158,10 +179,12 @@ module Metanorma
158
179
  Metanorma::Utils.break_up_long_str(str, threshold, punct)
159
180
  end
160
181
 
161
- def write_entry(file, line, loc, msg, context)
162
- 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))
163
184
  file.print <<~HTML
164
- <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>
165
188
  HTML
166
189
  end
167
190
  end
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.6.3".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.3
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-10 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