metanorma-plugin-lutaml 0.7.79 → 0.7.81

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: '028325b5abc812f039d2f573d4538c521a2b6742ffedf04af46914231fa8629e'
4
- data.tar.gz: 43245d0f625aa5aa618d1afce0bf960275a7e30d0a68433029404249ea53d84d
3
+ metadata.gz: 1dfb4b9c90d1ffba66925177643b11f954b9aa0640e3fdc0c3beefec359267f5
4
+ data.tar.gz: b211eedd83758587686f9387f8e9875b52d0c9252632fedb7b9aacbd31e405a4
5
5
  SHA512:
6
- metadata.gz: b2af4244a3254697ec586878cfb0aac77216c3318e145879e85379a26f7db64a38d2c4f2c09c84b000302a24ab210d3ecbd7d1a3661233435251b0b0ed219420
7
- data.tar.gz: 98a7e4542de80069ea995186fe64ca8810d784eeb932ede2514e999740e70e765269f0e76fe858e0a6d57bb1c005273b50280f40af45d4fc7242e836660a9b04
6
+ metadata.gz: ed7b5fe9f10850fe9a3066c73996f38eb73445c5265a790685cc4af60b6c95740ab1e0860239ff5ba03156307c0c08715c5be3e671798533faf43ea25b9c88f9
7
+ data.tar.gz: ea8a4b896bd48f51fa4214c5e2d81fd24bc3bfe059a457d2cbed544e2d23f7a12c0a02eb47d92667c4e9d407ff72ac5a9e1b1a8e120947a4678c71ecf11df0cf
@@ -52,22 +52,29 @@ module Metanorma
52
52
  # the expressir version), the output stands as printed: the prose
53
53
  # shows exactly once either way.
54
54
  class ProseSplicer
55
- def initialize(schema, format, prose, block)
55
+ def initialize(schema, format, prose, format_name)
56
56
  @schema = schema
57
57
  @format = format
58
58
  @prose = prose
59
- @block = block
59
+ @format_name = format_name
60
60
  @schema_head = %r{
61
61
  \ASCHEMA\s+#{Regexp.escape(schema.id.to_s)}[^\n;]*;[^\n]*
62
62
  }x
63
63
  end
64
64
 
65
+ # The prose block is formatted at call time from the item's
66
+ # current remarks: re-decoration for another document rewrites
67
+ # the remarks (figure staging), and a process rendering several
68
+ # documents off one index must print each document's own
69
+ # resolution — a block captured at decoration time would print
70
+ # the first document's forever (#381).
65
71
  def call
72
+ block = SOURCE_FORMATTERS.fetch(@format_name).format(@prose)
66
73
  printed = format_without_prose
67
- return printed if printed.include?(@block)
74
+ return printed if printed.include?(block)
68
75
  return printed unless printed.match?(@schema_head)
69
76
 
70
- printed.sub(@schema_head) { |line| "#{line}\n\n#{@block}" }
77
+ printed.sub(@schema_head) { |line| "#{line}\n\n#{block}" }
71
78
  end
72
79
 
73
80
  private
@@ -91,8 +98,14 @@ module Metanorma
91
98
  end
92
99
 
93
100
  def decorate_remarks(options)
94
- promote_schema_prose
101
+ prose = promote_schema_prose
95
102
  stash_figure_remarks(options)
103
+ # The spliced prose blocks are built here, after the figure
104
+ # rewrite, so they print the resolved targets — and rebuilt
105
+ # on every decoration, so a process rendering several
106
+ # documents off one index prints each document's own
107
+ # resolution rather than the first document's (#381).
108
+ hide_from_source_formats(prose) if prose
96
109
  end
97
110
 
98
111
  private
@@ -105,39 +118,39 @@ module Metanorma
105
118
  # its target.
106
119
  #
107
120
  # Since expressir 2.4.59 (expressir#603) the formatters print
108
- # remark_items, so the synthetic item is hidden from them — and
109
- # then spliced back into the printed source in its standard
110
- # position (right after the SCHEMA line), so the source listing
111
- # shows the prose exactly once, as written.
121
+ # remark_items, so the synthetic item is hidden from them — the
122
+ # caller splices it back into the printed source in its standard
123
+ # position (right after the SCHEMA line) once the figure rewrite
124
+ # has run, so the source listing shows the resolved prose
125
+ # exactly once.
112
126
  def promote_schema_prose
113
127
  return unless @model.is_a?(Expressir::Model::Declarations::Schema)
114
- return if @model.remarks.to_a.empty?
115
128
 
116
129
  items = @model.remark_items.to_a
117
- return if items.any? { |ri| ri.id == @model.id }
130
+ existing = items.find { |ri| ri.id == @model.id }
131
+ return existing if existing
132
+ return if @model.remarks.to_a.empty?
118
133
 
119
134
  prose = Expressir::Model::Declarations::RemarkItem.new(
120
135
  id: @model.id,
121
136
  remarks: @model.remarks.dup,
122
137
  )
123
138
  @model.remark_items = [prose] + items
124
- hide_from_source_formats(prose)
139
+ prose
125
140
  end
126
141
 
127
142
  # Each format is still computed lazily and memoized by expressir;
128
- # it just runs without the promoted item in remark_items.
143
+ # it just runs without the promoted item in remark_items. The
144
+ # prose block itself is formatted per render by the splicer.
129
145
  def hide_from_source_formats(prose)
130
- blocks = SOURCE_FORMATS.to_h do |name|
131
- [name, SOURCE_FORMATTERS[name].format(prose)]
132
- end
133
146
  SOURCE_FORMATS.each do |name|
134
- splice_prose_into_format(name, prose, blocks[name])
147
+ splice_prose_into_format(name, prose)
135
148
  end
136
149
  end
137
150
 
138
- def splice_prose_into_format(name, prose, block)
151
+ def splice_prose_into_format(name, prose)
139
152
  format = @model.method(name)
140
- splicer = ProseSplicer.new(@model, format, prose, block)
153
+ splicer = ProseSplicer.new(@model, format, prose, name)
141
154
 
142
155
  @model.define_singleton_method(name) { splicer.call }
143
156
  end
@@ -163,13 +176,74 @@ module Metanorma
163
176
  schema_directory,
164
177
  )
165
178
  @model.remark_items.each do |item|
166
- resolved = resolver.remarks(item.remarks)
167
- item.define_singleton_method(:expressg_figure_remarks) do
179
+ rewrite_item(item, resolver)
180
+ end
181
+ # Figures also ride remarks tagged to nested declarations — an
182
+ # entity- or attribute-tagged remark hangs off that element,
183
+ # not the schema (solid_shape_element_schema carries its
184
+ # L-section figure blocks on an attribute remark). And under
185
+ # expressir 2.4.70+ (the untagged-remarks rework) such owner
186
+ # remarks sit on the owner's `remarks` string array with
187
+ # `remark_items` EMPTY, so both channels must be rewritten:
188
+ # the corpus templates print `attribute.remarks` directly.
189
+ walk_remark_item_owners(Array(@model.children)) do |owner|
190
+ if owner.respond_to?(:remark_items)
191
+ owner.remark_items.each { |item| rewrite_item(item, resolver) }
192
+ end
193
+ next unless owner.respond_to?(:remarks) && owner.remarks.to_a.any?
194
+
195
+ resolved = resolver.remarks(owner.remarks)
196
+ owner.define_singleton_method(:expressg_figure_remarks) do
168
197
  resolved
169
198
  end
170
- # Resolve in place: the annex templates print `item.remarks`
171
- # verbatim, outside the listing and outside any accessor.
172
- item.remarks = resolved
199
+ owner.remarks = resolved
200
+ end
201
+ reset_format_memos
202
+ end
203
+
204
+ def rewrite_item(item, resolver)
205
+ resolved = resolver.remarks(item.remarks)
206
+ item.define_singleton_method(:expressg_figure_remarks) do
207
+ resolved
208
+ end
209
+ # Resolve in place: the annex templates print `item.remarks`
210
+ # verbatim, outside the listing and outside any accessor.
211
+ item.remarks = resolved
212
+ end
213
+
214
+ def walk_remark_item_owners(elements, &block)
215
+ elements.each do |element|
216
+ next unless element.is_a?(Expressir::Model::ModelElement)
217
+ # RemarkItems appear in their owner's children; they are
218
+ # leaves for this purpose — re-entering one would resolve
219
+ # its (already rewritten) remarks a second time.
220
+ next if element.is_a?(Expressir::Model::Declarations::RemarkItem)
221
+
222
+ has_items = element.respond_to?(:remark_items) && element.remark_items.to_a.any?
223
+ has_remarks = element.respond_to?(:remarks) && element.remarks.to_a.any?
224
+ block.call(element) if has_items || has_remarks
225
+ walk_remark_item_owners(Array(element.children), &block)
226
+ end
227
+ end
228
+
229
+ # expressir memoizes each printed source form in an ivar the
230
+ # first time it is formatted. The prose block is re-spliced per
231
+ # render, but the rest of the printed source — including the
232
+ # __expressg figure blocks — comes from that memo, so a process
233
+ # rendering several documents sharing one index must clear it
234
+ # on re-decoration or every document after the first prints the
235
+ # first document's figure targets (#381). expressir exposes no
236
+ # reset API; these are its memo ivars.
237
+ FORMAT_MEMO_IVARS = %i[
238
+ @formatted
239
+ @formatted_no_remarks
240
+ @formatted_hyperlinked
241
+ @formatted_hyperlinked_adoc
242
+ ].freeze
243
+
244
+ def reset_format_memos
245
+ FORMAT_MEMO_IVARS.each do |ivar|
246
+ @model.remove_instance_variable(ivar) if @model.instance_variable_defined?(ivar)
173
247
  end
174
248
  end
175
249
  end
@@ -50,7 +50,7 @@ module Metanorma
50
50
  # An optional attribute list is allowed: the WG12 remark figures
51
51
  # carry captions (`image::images/x.svg[EXPRESS-G diagram]`), and
52
52
  # the empty-list-only form skipped them silently (#371).
53
- IMAGE_MACRO_REGEXP = /\Aimage::([^\/\s:{}][^:\s{}]*)\[[^\]]*\]\s*\z/
53
+ IMAGE_MACRO_REGEXP = /\Aimage::([^:\s{}]+)\[[^\]]*\]\s*\z/
54
54
 
55
55
  # An imagesdir attribute entry; the bang form unsets. The LAST
56
56
  # entry in the source is the one in force where the member
@@ -205,6 +205,9 @@ module Metanorma
205
205
  end
206
206
 
207
207
  def final_target(target)
208
+ return target if target.start_with?("/")
209
+ return flat_target(target) if target.include?("/")
210
+
208
211
  file = File.expand_path(target, @schema_directory.to_s)
209
212
  unless File.file?(file)
210
213
  # A missing figure must NOT reach asciidoctor as a broken
@@ -237,6 +240,43 @@ module Metanorma
237
240
  FileUtils.cp(file, staged)
238
241
  target
239
242
  end
243
+
244
+ # A target carrying a path segment (as written in the schema
245
+ # source, e.g. `images/image-02.png`) is emitted FLAT: the
246
+ # staged spot must equal the imagesdir-join of the emitted
247
+ # target, and a subpath target would double under the join
248
+ # (`images/images/...`, #381). A basename collision with a
249
+ # different file disambiguates through a digest directory,
250
+ # whose emitted path is itself staged at its own join.
251
+ def flat_target(target)
252
+ file = File.expand_path(target, @schema_directory.to_s)
253
+ unless File.file?(file)
254
+ @errors << (
255
+ "[EXPRESS-G figure error] '#{target}' not found beside " \
256
+ "the schema (looked in '#{@schema_directory}')"
257
+ )
258
+ return
259
+ end
260
+
261
+ flat = File.basename(target)
262
+ staged = File.join(@imagesdir_directory, flat)
263
+ if File.file?(staged)
264
+ return flat if FileUtils.identical?(file, staged)
265
+
266
+ digest = Digest::SHA256.hexdigest(file)[0, 12]
267
+ unique = File.join(digest, flat)
268
+ staged_unique = File.join(@imagesdir_directory, unique)
269
+ return unique if File.file?(staged_unique)
270
+
271
+ FileUtils.mkdir_p(File.dirname(staged_unique))
272
+ FileUtils.cp(file, staged_unique)
273
+ return unique
274
+ end
275
+
276
+ FileUtils.mkdir_p(@imagesdir_directory)
277
+ FileUtils.cp(file, staged)
278
+ flat
279
+ end
240
280
  end
241
281
  end
242
282
  end
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.7.79".freeze
4
+ VERSION = "0.7.81".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -117,12 +117,27 @@ module Metanorma
117
117
 
118
118
  def add_model_anchor_context(context, root_package)
119
119
  packages = model_packages(root_package)
120
+ register_model_anchors(context, packages, root_package)
121
+ register_anchorable_ids(context, packages, root_package)
122
+ end
123
+
124
+ def register_model_anchors(context, packages, root_package)
120
125
  context["additional_context"]["model_anchors"] =
121
126
  model_reference_targets(packages)
122
127
  .merge(model_anchors(packages))
123
128
  .merge(model_stub_anchors(root_package))
124
129
  end
125
130
 
131
+ # Real model entities AND stubs (#70): both are XMI-declared
132
+ # objects, so their links survive templates that do not render
133
+ # their sections. Only ids the XMI never defines (attribute
134
+ # types, association ends present solely as idrefs) degrade.
135
+ def register_anchorable_ids(context, packages, root_package)
136
+ stub_ids = model_stub_anchors(root_package).keys
137
+ context["additional_context"]["model_anchorable"] =
138
+ model_anchors(packages).keys | stub_ids
139
+ end
140
+
126
141
  # Ids the XMI templates link to (attribute types, association ends),
127
142
  # including ones the XMI never defines. Unnamed; anchors override.
128
143
  def model_reference_targets(packages)
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "asciidoctor"
4
4
  require "asciidoctor/extensions"
5
+ require "set"
5
6
 
6
7
  module Metanorma
7
8
  module Plugin
@@ -16,6 +17,11 @@ module Metanorma
16
17
  (?:,(?<content>.*?))?&gt;&gt;/x)
17
18
 
18
19
  INVENTORY_ATTRIBUTE = "lutaml_model_anchors"
20
+ # Ids of real model entities (classes, enums, data types, packages).
21
+ # These never degrade to plain text (#70): even when the current
22
+ # template does not render their sections, the link must survive
23
+ # for collection-level documents to resolve.
24
+ ANCHORABLE_ATTRIBUTE = "lutaml_model_anchorable"
19
25
 
20
26
  def self.root_document(document)
21
27
  document = document.parent_document while document.parent_document
@@ -32,12 +38,23 @@ module Metanorma
32
38
  .merge!(anchors) { |_, old, new| new || old }
33
39
  end
34
40
 
41
+ # The subset of the inventory that is a real model entity
42
+ # (classes, enums, data types, packages, stubs). Only ids the XMI
43
+ # never defines (attribute types and association ends present
44
+ # solely as idrefs) degrade to plain text; XMI-declared objects
45
+ # stay linked (#70).
46
+ def self.register_anchorable(document, ids)
47
+ document = root_document(document)
48
+ document.attributes[ANCHORABLE_ATTRIBUTE] ||= Set.new
49
+ document.attributes[ANCHORABLE_ATTRIBUTE].merge(ids)
50
+ end
51
+
35
52
  def process(parent, target, attrs)
36
53
  document = self.class.root_document(parent.document)
37
54
  inventory = document.attributes.fetch(INVENTORY_ATTRIBUTE, {})
38
55
  name = inventory[target]
39
56
  text = reference_text(parent, attrs["text"], target, name)
40
- value = if inventory.key?(target) && !anchored?(document, target)
57
+ value = if suppress_link?(document, target)
41
58
  plain_text(parent, text, target)
42
59
  else
43
60
  label = text ? ",#{text}" : ""
@@ -48,6 +65,13 @@ module Metanorma
48
65
 
49
66
  private
50
67
 
68
+ def suppress_link?(document, target)
69
+ inventory = document.attributes.fetch(INVENTORY_ATTRIBUTE, {})
70
+ anchorable = document.attributes.fetch(ANCHORABLE_ATTRIBUTE, Set.new)
71
+ inventory.key?(target) && !anchored?(document, target) &&
72
+ !anchorable.member?(target)
73
+ end
74
+
51
75
  def anchored?(document, target)
52
76
  document.catalog[:refs].key?("section-#{target}")
53
77
  end
@@ -41,6 +41,9 @@ module Metanorma
41
41
  XmiModelReference.register(
42
42
  document, additional_context["model_anchors"] || {}
43
43
  )
44
+ XmiModelReference.register_anchorable(
45
+ document, additional_context["model_anchorable"] || []
46
+ )
44
47
  render_result.split("\n")
45
48
  end
46
49
 
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.79
4
+ version: 0.7.81
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-19 00:00:00.000000000 Z
11
+ date: 2026-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor