metanorma-plugin-lutaml 0.7.75 → 0.7.77

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: 2c7e7d819b2ac13a739ff836919a7605cf177a3977c126e6419da014221e5853
4
- data.tar.gz: 533e8319e90f2d9f6a2339c5e2b3866b9bae26003c2be394fda9b2d9b2c337a0
3
+ metadata.gz: 6fd6252359c80c97f0826f2adec96194db94183aee821b9f47bbe6ca4b508ede
4
+ data.tar.gz: 8b7758d447ace366ed495552b9b6ed8f272a0ae3440066a102dd4abd697b0793
5
5
  SHA512:
6
- metadata.gz: cb165bf2861c7d043d0aaa8ae217904766d8f2a52ed894be8f6db7204758b75fafadba9243ce8e6e333c1162c090fa4146940ae383db6cc308724a4954157c98
7
- data.tar.gz: 44ea1d2722ba0888ec5c09314bd6b0106ac3255a57705d199b3ca446f15b9ca0c1af133b1b6cb250702350f1657f4ae3df16e8890e90ef036582cdaecc7b34cf
6
+ metadata.gz: c5df36f9ffffee8976f0f6b91451eda83206a52301213500fc01284353f0a141318363e07bbb87dbafbc52389b580d57b99f49028f5ba1bee1eec599e0144365
7
+ data.tar.gz: 9b88d1d8f3760871fdc88dfb54a40441fb2a0c5409db68598121682090c6874cde263a15c906bef46aa53446a48ea20892634068a393b7ee1276c1f6d00d9fca
@@ -92,7 +92,7 @@ module Metanorma
92
92
 
93
93
  def decorate_remarks(options)
94
94
  promote_schema_prose
95
- stash_listing_imagesdir(options)
95
+ stash_figure_remarks(options)
96
96
  end
97
97
 
98
98
  private
@@ -142,35 +142,18 @@ module Metanorma
142
142
  @model.define_singleton_method(name) { splicer.call }
143
143
  end
144
144
 
145
- # The per-schema imagesdir for the listing's attribute entries
146
- # (formatted_hyperlinked_adoc_listing), plus the document's
147
- # imagesdir at decoration time so the listing can restore it
148
- # after the schema's content. The values ride on the schema as
149
- # singleton readers: the liquid drop has no access to the
150
- # asciidoctor document.
151
- def stash_listing_imagesdir(options)
152
- document = options["document"]
153
- dir = ExpressRemarkAdapter.schema_imagesdir(options, @model)
154
- previous = document && document.attributes["imagesdir"]
155
- @model.define_singleton_method(:listing_imagesdir) { dir }
156
- @model.define_singleton_method(:listing_imagesdir_restore) do
157
- previous
158
- end
159
- stash_figure_remarks(options, dir)
160
- end
161
-
162
- # Stashes the drop-facing figure resolver on the schema's
163
- # remark items (ExpressRemarkFigures): templates rendering the
164
- # remarks outside the source listing get their bare figure
165
- # macros resolved through the schema's directory, while the
166
- # listing keeps printing the model source as written. The
167
- # staging runs EAGERLY, at decoration: templates that print the
168
- # remark verbatim ("{{ remark }}") never call the resolved
169
- # accessor, and the staged copy must exist either way for
170
- # their bare targets to resolve against the document's
171
- # imagesdir.
172
- def stash_figure_remarks(options, schema_directory)
145
+ # Stages the schema's EXPRESS-G figures into the directory the
146
+ # document's image targets resolve against and rewrites the
147
+ # remark texts to the staged files' bare basenames — the
148
+ # plugin never sets, checks, or restores the document's
149
+ # imagesdir (metanorma-plugin-lutaml#371): every figure macro
150
+ # the templates print, inside the listing or out, carries a
151
+ # bare target that resolves as-is.
152
+ def stash_figure_remarks(options)
173
153
  document = options["document"]
154
+ schema_directory = ExpressRemarkAdapter.schema_imagesdir(
155
+ options, @model
156
+ )
174
157
  return unless document && schema_directory
175
158
  return unless @model.is_a?(Expressir::Model::Declarations::Schema)
176
159
 
@@ -184,6 +167,9 @@ module Metanorma
184
167
  item.define_singleton_method(:expressg_figure_remarks) do
185
168
  resolved
186
169
  end
170
+ # Resolve in place: the annex templates print `item.remarks`
171
+ # verbatim, outside the listing and outside any accessor.
172
+ item.remarks = resolved
187
173
  end
188
174
  end
189
175
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "digest"
3
4
  require "fileutils"
4
5
  require "pathname"
5
6
 
@@ -46,7 +47,10 @@ module Metanorma
46
47
  # A bare relative image macro: `image::name.svg[]`. Absolute
47
48
  # paths, URLs, data URIs, liquid references and macros carrying
48
49
  # an attribute list stay as written.
49
- IMAGE_MACRO_REGEXP = /\Aimage::([^\/\s:{}][^:\s{}]*)\[\]\s*\z/
50
+ # An optional attribute list is allowed: the WG12 remark figures
51
+ # carry captions (`image::images/x.svg[EXPRESS-G diagram]`), and
52
+ # the empty-list-only form skipped them silently (#371).
53
+ IMAGE_MACRO_REGEXP = /\Aimage::([^\/\s:{}][^:\s{}]*)\[[^\]]*\]\s*\z/
50
54
 
51
55
  # An imagesdir attribute entry; the bang form unsets. The LAST
52
56
  # entry in the source is the one in force where the member
@@ -133,6 +137,8 @@ module Metanorma
133
137
  # printing the macros as written.
134
138
  def to_s
135
139
  remarks.join("\n")
140
+ .gsub(/^[ \t]+(?=image::)/, "")
141
+ .gsub(/^(?!$)(image::)/) { "\n\n#{Regexp.last_match(1)}" }
136
142
  end
137
143
  end
138
144
 
@@ -157,48 +163,83 @@ module Metanorma
157
163
  File.expand_path(imagesdir, docdir)
158
164
  end
159
165
  @schema_directory = schema_directory
166
+ @errors = []
160
167
  end
161
168
 
162
169
  def remarks(texts)
163
170
  texts.map { |text| remark(text) }
164
171
  end
165
172
 
173
+ # The resolved text plus any figure-error lines emitted along
174
+ # the way (a missing figure surfaces as a visible error, never
175
+ # as a broken macro).
166
176
  def remark(text)
167
177
  text.each_line.map { |line| rewrite_line(line) }.join
168
178
  end
169
179
 
180
+ def errors
181
+ @errors.dup
182
+ end
183
+
170
184
  private
171
185
 
172
186
  # The figure file is STAGED into the resolved imagesdir
173
- # directory — the one directory this document's image targets
174
- # resolve against, since asciidoctor joins every target with
175
- # the imagesdir (the author's value, or its own "images"
176
- # default) before use — and the emitted target is the staged
177
- # file's bare basename. A ../-composed target escapes the
178
- # imagesdir join and is dropped silently by asciidoctor's path
179
- # handling (measured: the figure vanished from every output
180
- # format, exit 0), and an absolute target leaks the build path
181
- # (issue #359's original report). The staged copy is a build
182
- # artifact; no path enters the output.
187
+ # directory at the exact path the imagesdir join computes for
188
+ # its target — asciidoctor joins every image target with the
189
+ # imagesdir (the author's value, or its own "images" default)
190
+ # before use, so staging MIRRORS the target path under that
191
+ # directory and the emitted line stands exactly as written:
192
+ # the target is a static path whose composed location exists.
193
+ # No target rewriting, no imagesdir attribute entry
194
+ # (metanorma-plugin-lutaml#371). Only when that static spot is
195
+ # taken by a DIFFERENT figure (two schemas shipping a same-named
196
+ # file) does the line rewrite — to the unique staged path,
197
+ # still static.
183
198
  def rewrite_line(line)
184
199
  match = IMAGE_MACRO_REGEXP.match(line) or return line
185
- return line unless stage_figure(match[1])
200
+ before = @errors.length
201
+ final = final_target(match[1])
202
+ return @errors[before..].join("\n") if final.nil? && @errors.length > before
203
+
204
+ return line if final == match[1]
186
205
 
187
206
  trailing = line.length - line.rstrip.length
188
207
  suffix = trailing.positive? ? line[-trailing, trailing] : ""
189
- "#{line[/\Aimage::/]}#{File.basename(match[1])}[]#{suffix}"
208
+ "#{line[/\Aimage::/]}#{final}[]#{suffix}"
190
209
  end
191
210
 
192
- def stage_figure(bare)
193
- file = File.expand_path(bare, @schema_directory.to_s)
194
- return unless File.file?(file)
211
+ def final_target(target)
212
+ file = File.expand_path(target, @schema_directory.to_s)
213
+ unless File.file?(file)
214
+ # A missing figure must NOT reach asciidoctor as a broken
215
+ # image macro — metanorma's image-existence check then
216
+ # FATALs the whole build (#371). Emit a visible, localized
217
+ # error line in its place: what was expected, where it was
218
+ # looked for.
219
+ @errors << (
220
+ "[EXPRESS-G figure error] '#{target}' not found beside " \
221
+ "the schema (looked in '#{@schema_directory}')"
222
+ )
223
+ return
224
+ end
195
225
 
196
- staged = File.join(@imagesdir_directory, File.basename(bare))
197
- return true if File.file?(staged)
226
+ staged = File.join(@imagesdir_directory, target)
227
+ if File.file?(staged)
228
+ return target if FileUtils.identical?(file, staged)
229
+
230
+ unique = File.join(@imagesdir_directory,
231
+ Digest::SHA256.hexdigest(file)[0, 12],
232
+ target)
233
+ return target if File.file?(unique)
234
+
235
+ FileUtils.mkdir_p(File.dirname(unique))
236
+ FileUtils.cp(file, unique)
237
+ return unique.sub("#{@imagesdir_directory}/", "")
238
+ end
198
239
 
199
- FileUtils.mkdir_p(@imagesdir_directory)
240
+ FileUtils.mkdir_p(File.dirname(staged))
200
241
  FileUtils.cp(file, staged)
201
- true
242
+ target
202
243
  end
203
244
  end
204
245
  end
@@ -9,10 +9,9 @@ module Metanorma
9
9
  # whose fence is computed from the content so that no dash run
10
10
  # inside remark prose can close the listing early — 43 of the 125
11
11
  # SRL schema listings close early under the templates' hardcoded
12
- # two-dash fence — plus the imagesdir attribute entries that let
13
- # the schema's relative image macros resolve as written, with no
14
- # build path in the remark text (TRThurman's source-fidelity
15
- # requirements).
12
+ # two-dash fence — the figure blocks re-emitted after it carry
13
+ # static targets staged by the adapter, with no build path in the
14
+ # remark text (TRThurman's source-fidelity requirements).
16
15
  #
17
16
  # The schema's EXPRESS-G figure remark (`__expressg`, carrying the
18
17
  # svgmap figure blocks) is not source: it is extraction fodder.
@@ -21,9 +20,10 @@ module Metanorma
21
20
  # listings only rendered figures because their hardcoded fence
22
21
  # closed early, an accident the computed fence removed). The
23
22
  # listing therefore prints the EXPRESS source only, and the figure
24
- # blocks are re-emitted after the fence as real adoc, still inside
25
- # the schema's imagesdir attribute entries so the image macros
26
- # resolve as written.
23
+ # blocks are re-emitted after the fence as real adoc with bare
24
+ # basenames — the adapter stages the files and rewrites the
25
+ # remarks at decoration time, so no imagesdir attribute entry is
26
+ # ever emitted (metanorma/metanorma-plugin-lutaml#371).
27
27
  module ExpressSchemaListing
28
28
  SOURCE_BLOCK_HEADING = '[source%unnumbered,subs="+macros"]'
29
29
  # A dash run of two or more at line start: only such a run can
@@ -114,13 +114,11 @@ module Metanorma
114
114
  end
115
115
 
116
116
  # Methods mixed into the schema's liquid drop class. The
117
- # decorated schema carries its imagesdir values as singleton
118
- # readers (the drop has no access to the asciidoctor document);
119
- # attribute entries are emitted immediately before and after the
120
- # block, since attribute entries take effect sequentially and
121
- # cannot be changed inside the listing itself. The extracted
122
- # EXPRESS-G figures go after the block, still inside those
123
- # entries, so their relative image macros resolve as written.
117
+ # adapter stages the EXPRESS-G figures at decoration time, so
118
+ # the extracted figure blocks after the listing carry static,
119
+ # as-written targets — no attribute entries wrap the output
120
+ # (attribute entries could not be changed inside the listing
121
+ # anyway).
124
122
  module DropMethods
125
123
  def formatted_hyperlinked_adoc_listing
126
124
  source, figures = ExpressSchemaListing
@@ -128,27 +126,25 @@ module Metanorma
128
126
  @object.formatted_hyperlinked_adoc.to_s,
129
127
  )
130
128
  fence = ExpressSchemaListing.fence(source)
131
- listing = [
129
+ # The figure macros are bare basenames — the adapter stages
130
+ # the files and rewrites the remarks at decoration time — so
131
+ # no imagesdir attribute entry wraps the output (#371): the
132
+ # document's imagesdir state is the template layer's alone.
133
+ [
134
+ listing_block(source, fence),
135
+ *figures,
136
+ ].reject(&:empty?).join("\n\n")
137
+ end
138
+
139
+ private
140
+
141
+ def listing_block(source, fence)
142
+ [
132
143
  SOURCE_BLOCK_HEADING,
133
144
  fence,
134
145
  source,
135
146
  fence,
136
147
  ].join("\n")
137
- with_imagesdir_entries(listing, figures)
138
- end
139
-
140
- private
141
-
142
- def with_imagesdir_entries(listing, figures = [])
143
- body = [listing, *figures].reject(&:empty?).join("\n\n")
144
- return body unless @object.respond_to?(:listing_imagesdir)
145
-
146
- dir = @object.listing_imagesdir
147
- return body unless dir
148
-
149
- restore = @object.listing_imagesdir_restore
150
- closing = restore ? ":imagesdir: #{restore}" : ":!imagesdir:"
151
- ":imagesdir: #{dir}\n\n#{body}\n\n#{closing}"
152
148
  end
153
149
  end
154
150
  end
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.7.75".freeze
4
+ VERSION = "0.7.77".freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-plugin-lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.75
4
+ version: 0.7.77
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-18 00:00:00.000000000 Z
11
+ date: 2026-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor