metanorma-plugin-lutaml 0.7.78 → 0.7.80
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31d20784c59524dc4c775cf8bc7ab345543da4ec44f04cd69961d20f7a15db24
|
|
4
|
+
data.tar.gz: 7532df396b22c7b72c15818e74926964683b2ca363faf25a745193cbc5850675
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fd731ef555de17f5de92763b077038b5661c42757b553552bd006e77d020d1c532cb7f4c86e5460f808c0b9738daa549fcbd1d8a194548b436984df23f39a819
|
|
7
|
+
data.tar.gz: bb40b6f99bcc348bdd0141bc4078266a3ee0c09d589824aace7cf3e1e129a13afa9466272f1d12f4d5cb8e1645daea133e37a4246ca9ae3fd971466cb6d494a9
|
|
@@ -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,
|
|
55
|
+
def initialize(schema, format, prose, format_name)
|
|
56
56
|
@schema = schema
|
|
57
57
|
@format = format
|
|
58
58
|
@prose = prose
|
|
59
|
-
@
|
|
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?(
|
|
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#{
|
|
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 —
|
|
109
|
-
#
|
|
110
|
-
# position (right after the SCHEMA line)
|
|
111
|
-
#
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
147
|
+
splice_prose_into_format(name, prose)
|
|
135
148
|
end
|
|
136
149
|
end
|
|
137
150
|
|
|
138
|
-
def splice_prose_into_format(name, prose
|
|
151
|
+
def splice_prose_into_format(name, prose)
|
|
139
152
|
format = @model.method(name)
|
|
140
|
-
splicer = ProseSplicer.new(@model, format, prose,
|
|
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
|
-
|
|
167
|
-
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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::([
|
|
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
|
|
@@ -148,20 +148,16 @@ module Metanorma
|
|
|
148
148
|
# directory as the document resolves it,
|
|
149
149
|
# ExpressRemarkAdapter.schema_imagesdir).
|
|
150
150
|
class TargetResolver
|
|
151
|
-
# Asciidoctor's default imagesdir for a document that sets
|
|
152
|
-
# none: bare image targets resolve against "images" under the
|
|
153
|
-
# docfile directory.
|
|
154
|
-
DEFAULT_IMAGESDIR = "images".freeze
|
|
155
|
-
|
|
156
151
|
def initialize(docfile, imagesdir, schema_directory)
|
|
157
152
|
docdir = File.dirname(File.expand_path(docfile.to_s))
|
|
158
153
|
@docdir = docdir
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
154
|
+
# Asciidoctor's default imagesdir is empty: a document that
|
|
155
|
+
# sets none resolves every bare image target against the
|
|
156
|
+
# docfile directory itself, and an explicit `:!imagesdir:`
|
|
157
|
+
# unset behaves identically. `File.expand_path` with an empty
|
|
158
|
+
# base returns the docdir, so both cases stage at the exact
|
|
159
|
+
# spot the bare target resolves to.
|
|
160
|
+
@imagesdir_directory = File.expand_path(imagesdir.to_s, docdir)
|
|
165
161
|
@schema_directory = schema_directory
|
|
166
162
|
@errors = []
|
|
167
163
|
end
|
|
@@ -209,6 +205,9 @@ module Metanorma
|
|
|
209
205
|
end
|
|
210
206
|
|
|
211
207
|
def final_target(target)
|
|
208
|
+
return target if target.start_with?("/")
|
|
209
|
+
return flat_target(target) if target.include?("/")
|
|
210
|
+
|
|
212
211
|
file = File.expand_path(target, @schema_directory.to_s)
|
|
213
212
|
unless File.file?(file)
|
|
214
213
|
# A missing figure must NOT reach asciidoctor as a broken
|
|
@@ -241,6 +240,43 @@ module Metanorma
|
|
|
241
240
|
FileUtils.cp(file, staged)
|
|
242
241
|
target
|
|
243
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
|
|
244
280
|
end
|
|
245
281
|
end
|
|
246
282
|
end
|