metanorma-plugin-lutaml 0.7.73 → 0.7.74
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 +4 -4
- data/README.adoc +3 -0
- data/docs/usages/lutaml-jsonschema.adoc +77 -0
- data/lib/metanorma/plugin/lutaml/base_preprocessor.rb +9 -2
- data/lib/metanorma/plugin/lutaml/cache_registry.rb +5 -0
- data/lib/metanorma/plugin/lutaml/express_remark_adapter.rb +37 -7
- data/lib/metanorma/plugin/lutaml/express_remark_figures.rb +194 -0
- data/lib/metanorma/plugin/lutaml/lutaml_jsonschema_preprocessor.rb +136 -0
- data/lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb +1 -0
- data/lib/metanorma/plugin/lutaml/version.rb +1 -1
- data/lib/metanorma-plugin-lutaml.rb +4 -0
- data/metanorma-plugin-lutaml.gemspec +1 -0
- metadata +25 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f86981d696afc6cc0a4f7650942a9938f3ed13224f673dee6298764b83073f6
|
|
4
|
+
data.tar.gz: 867e0fe46d6c586a4328eed740b6bc25b6d002943843e6f2d6115615463b20df
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8efaef9b369242fd98aa5ca355b99ced2b3859776ee747b9e5b7ac2951073a106f1b30b40ea7b2e892027eb155049a0d17cb30ee9217f94aafde87f4c95b419a
|
|
7
|
+
data.tar.gz: 27d409bac16af7b9a4a05d2a2c2ab9bfc5346e09405bf0f4bcd27c5a6b0e2b1642c7969909db8d096fc34f2a287801a20458d8fa54db168751fc6fc282dd6cf7
|
data/README.adoc
CHANGED
|
@@ -17,6 +17,7 @@ within a Metanorma document:
|
|
|
17
17
|
* LutaML GML Dictionary files (`*.xml`)
|
|
18
18
|
* JSON or YAML files (`*.json|*.yml|*.yaml`)
|
|
19
19
|
* XML Schema files (`*.xsd`)
|
|
20
|
+
* JSON Schema files (`*.json`)
|
|
20
21
|
|
|
21
22
|
== Installation
|
|
22
23
|
|
|
@@ -43,6 +44,8 @@ link:docs/usages/lutaml-data.adoc[Usage with LutaML data files by lutaml_data]
|
|
|
43
44
|
|
|
44
45
|
link:docs/usages/lutaml-xsd.adoc[Usage with XML Schema files by lutaml_xsd]
|
|
45
46
|
|
|
47
|
+
link:docs/usages/lutaml-jsonschema.adoc[Usage with JSON Schema files by lutaml_jsonschema]
|
|
48
|
+
|
|
46
49
|
== Documentation
|
|
47
50
|
|
|
48
51
|
Please refer to https://www.metanorma.org.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
== Usage with JSON Schema
|
|
2
|
+
|
|
3
|
+
=== Overview
|
|
4
|
+
|
|
5
|
+
The `lutaml_jsonschema` macro parses *JSON Schema* files (draft-04 through
|
|
6
|
+
2020-12) through `lutaml-jsonschema` and turns the annotations in the schema
|
|
7
|
+
(`title`, `description`, `enum`, `pattern`, ranges and lengths) into document
|
|
8
|
+
content.
|
|
9
|
+
|
|
10
|
+
There are three forms:
|
|
11
|
+
|
|
12
|
+
* `lutaml_jsonschema::<path>[]` renders a built-in reference section.
|
|
13
|
+
* `lutaml_jsonschema::<path>[<context_name>, <template>]` renders a Liquid
|
|
14
|
+
template file.
|
|
15
|
+
* `[lutaml_jsonschema,<path>,<context_name>]` renders the Liquid template
|
|
16
|
+
written inside the block.
|
|
17
|
+
|
|
18
|
+
=== Built-in reference
|
|
19
|
+
|
|
20
|
+
[source,adoc]
|
|
21
|
+
-----
|
|
22
|
+
lutaml_jsonschema::schemas/person.schema.json[]
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
The output has one section per schema, titled with its `title`, followed by
|
|
26
|
+
its `description` and a table of its properties (name, type, whether it is
|
|
27
|
+
required, and a description with the constraints). Each entry under `$defs`
|
|
28
|
+
(or `definitions`) gets its own subsection. A property whose type is a `$ref`
|
|
29
|
+
links to the subsection of the definition it points to.
|
|
30
|
+
|
|
31
|
+
Definition anchors take the form `def-<schema name>-<definition name>`, where
|
|
32
|
+
the schema name is the file name without its `.json` extension, with dots
|
|
33
|
+
replaced by hyphens. For example, `Address` in `person.schema.json` gets the
|
|
34
|
+
anchor `def-person-schema-Address`. Several schemas can therefore be
|
|
35
|
+
documented in the same document without anchor clashes.
|
|
36
|
+
|
|
37
|
+
=== Liquid template file
|
|
38
|
+
|
|
39
|
+
[source,adoc]
|
|
40
|
+
-----
|
|
41
|
+
lutaml_jsonschema::schemas/person.schema.json[schema, templates/person.liquid]
|
|
42
|
+
-----
|
|
43
|
+
|
|
44
|
+
* `<context_name>`: The name of the variable that holds the schema in the
|
|
45
|
+
template.
|
|
46
|
+
* `<template>`: Path to the Liquid template, relative to the document.
|
|
47
|
+
* `include_path=<dir1>,<dir2>`: Optional extra directories for Liquid
|
|
48
|
+
`{% include %}` and `{% render %}`.
|
|
49
|
+
|
|
50
|
+
=== Liquid block
|
|
51
|
+
|
|
52
|
+
[source,adoc]
|
|
53
|
+
-----
|
|
54
|
+
[lutaml_jsonschema,schemas/person.schema.json,schema]
|
|
55
|
+
----
|
|
56
|
+
== {{ schema.title }}
|
|
57
|
+
|
|
58
|
+
{{ schema.description }}
|
|
59
|
+
|
|
60
|
+
{% for entry in schema.property_entries %}
|
|
61
|
+
* `{{ entry.name }}` ({{ entry.schema.type }}):
|
|
62
|
+
{{ entry.schema.description }}
|
|
63
|
+
{% endfor %}
|
|
64
|
+
----
|
|
65
|
+
-----
|
|
66
|
+
|
|
67
|
+
=== Liquid template context
|
|
68
|
+
|
|
69
|
+
The context variable is the parsed `Lutaml::Jsonschema::Schema`. Commonly used
|
|
70
|
+
fields:
|
|
71
|
+
|
|
72
|
+
* `title`, `description`, `type`, `required`, `enum`, `pattern`, `minimum`,
|
|
73
|
+
`maximum`, `min_length`, `max_length`: The schema keywords of the same name.
|
|
74
|
+
* `property_entries`: The properties, each with `name` and `schema` (the
|
|
75
|
+
property's own schema, with the same fields).
|
|
76
|
+
* `definition_entries`: The `$defs` (or `definitions`) entries, each with
|
|
77
|
+
`name` and `schema`.
|
|
@@ -25,8 +25,15 @@ module Metanorma
|
|
|
25
25
|
FILE_SYSTEM_PATTERNS = ["%s.liquid", "_%s.liquid", "_%s.adoc"].freeze
|
|
26
26
|
|
|
27
27
|
def process(document, reader)
|
|
28
|
-
|
|
29
|
-
.new(document, reader.lines).readlines
|
|
28
|
+
lines = Asciidoctor::PreprocessorNoIfdefsReader
|
|
29
|
+
.new(document, reader.lines).readlines
|
|
30
|
+
|
|
31
|
+
# Attribute entries apply at parse, after preprocessing, so the
|
|
32
|
+
# imagesdir the figure targets resolve against is read from the
|
|
33
|
+
# source lines here (ExpressRemarkFigures).
|
|
34
|
+
ExpressRemarkFigures.scan_source_imagesdir(document, lines)
|
|
35
|
+
|
|
36
|
+
input_lines = lines.to_enum
|
|
30
37
|
|
|
31
38
|
express_indexes = Utils.parse_document_express_indexes(
|
|
32
39
|
document, input_lines
|
|
@@ -156,6 +156,35 @@ module Metanorma
|
|
|
156
156
|
@model.define_singleton_method(:listing_imagesdir_restore) do
|
|
157
157
|
previous
|
|
158
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)
|
|
173
|
+
document = options["document"]
|
|
174
|
+
return unless document && schema_directory
|
|
175
|
+
return unless @model.is_a?(Expressir::Model::Declarations::Schema)
|
|
176
|
+
|
|
177
|
+
resolver = ExpressRemarkFigures::TargetResolver.new(
|
|
178
|
+
document.attributes["docfile"],
|
|
179
|
+
ExpressRemarkFigures.effective_imagesdir(document),
|
|
180
|
+
schema_directory,
|
|
181
|
+
)
|
|
182
|
+
@model.remark_items.each do |item|
|
|
183
|
+
resolved = resolver.remarks(item.remarks)
|
|
184
|
+
item.define_singleton_method(:expressg_figure_remarks) do
|
|
185
|
+
resolved
|
|
186
|
+
end
|
|
187
|
+
end
|
|
159
188
|
end
|
|
160
189
|
end
|
|
161
190
|
|
|
@@ -170,13 +199,14 @@ module Metanorma
|
|
|
170
199
|
|
|
171
200
|
# NO document-level imagesdir here: metanorma's figure
|
|
172
201
|
# absolutization joins document.attributes["imagesdir"] with
|
|
173
|
-
# svgmap-synthesized targets that are ALREADY
|
|
174
|
-
# (the
|
|
175
|
-
# the
|
|
176
|
-
#
|
|
177
|
-
#
|
|
178
|
-
#
|
|
179
|
-
#
|
|
202
|
+
# svgmap-synthesized targets that are ALREADY document-relative
|
|
203
|
+
# (the drop-facing remark figures compose their targets through
|
|
204
|
+
# the document's imagesdir directory, ExpressRemarkFigures),
|
|
205
|
+
# doubling the directory segments and failing the
|
|
206
|
+
# image-existence check (suma's dummy-collection repro). The
|
|
207
|
+
# remark content is served by the listing-scoped attribute
|
|
208
|
+
# entries emitted around each source block, which only affect
|
|
209
|
+
# asciidoctor resolution inside the listing.
|
|
180
210
|
end
|
|
181
211
|
|
|
182
212
|
class CachedRepoAdapter < Base
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "pathname"
|
|
5
|
+
|
|
6
|
+
module Metanorma
|
|
7
|
+
module Plugin
|
|
8
|
+
module Lutaml
|
|
9
|
+
# The drop-facing rewrite of a schema's remark figure macros.
|
|
10
|
+
#
|
|
11
|
+
# The __expressg remarks carry bare image macros
|
|
12
|
+
# (`image::<name>.svg[]`) whose files sit next to the schema's .exp
|
|
13
|
+
# file. The source listing resolves them through the listing-scoped
|
|
14
|
+
# :imagesdir: entries (ExpressSchemaListing), but templates that
|
|
15
|
+
# render the remark text OUTSIDE the listing -- the SRL member
|
|
16
|
+
# documents' annex-diagram templates print the remark verbatim --
|
|
17
|
+
# resolve the bare name against the document's :imagesdir:, which
|
|
18
|
+
# names the document's own images/ folder. The figure is not there,
|
|
19
|
+
# and the missing-image check stops the build (issue #359).
|
|
20
|
+
#
|
|
21
|
+
# The fix composes each bare figure target as the path from the
|
|
22
|
+
# document's imagesdir DIRECTORY to the resolved figure file, the
|
|
23
|
+
# only relative form that survives asciidoctor's resolution: an
|
|
24
|
+
# image target is joined with the document's imagesdir before use
|
|
25
|
+
# (one "../" per imagesdir segment is consumed by the join), so a
|
|
26
|
+
# target expressed relative to that directory lands on the file
|
|
27
|
+
# whether the document sets :imagesdir:, and with no :imagesdir:
|
|
28
|
+
# the imagesdir directory is the docfile directory and the target
|
|
29
|
+
# is the plain docfile-relative path -- the form the working
|
|
30
|
+
# collection builds carry in their document.xml. Every emitted
|
|
31
|
+
# target is document-relative: no build path enters the output.
|
|
32
|
+
#
|
|
33
|
+
# The imagesdir in force at parse time is known only from the
|
|
34
|
+
# source: attribute entries apply at parse, after preprocessing,
|
|
35
|
+
# so the preprocessors stash the value they scan from the source
|
|
36
|
+
# lines (scan_source_imagesdir) and the resolver falls back to the
|
|
37
|
+
# document's programmatic attributes where no entry exists.
|
|
38
|
+
#
|
|
39
|
+
# The rewrite rides the RemarkItem liquid drop, never the model:
|
|
40
|
+
# the source listing prints the model's formatted source and must
|
|
41
|
+
# keep showing the macros as written, while every drop-facing
|
|
42
|
+
# rendering gets the resolved targets. Figures that do not resolve
|
|
43
|
+
# under the schema keep their macros, so genuinely missing assets
|
|
44
|
+
# still surface loudly.
|
|
45
|
+
module ExpressRemarkFigures
|
|
46
|
+
# A bare relative image macro: `image::name.svg[]`. Absolute
|
|
47
|
+
# paths, URLs, data URIs, liquid references and macros carrying
|
|
48
|
+
# an attribute list stay as written.
|
|
49
|
+
IMAGE_MACRO_REGEXP = /\Aimage::([^\/\s:{}][^:\s{}]*)\[\]\s*\z/
|
|
50
|
+
|
|
51
|
+
# An imagesdir attribute entry; the bang form unsets. The LAST
|
|
52
|
+
# entry in the source is the one in force where the member
|
|
53
|
+
# document's annexes render.
|
|
54
|
+
# Linear form: one dispatch space then the rest of the line;
|
|
55
|
+
# surrounding whitespace is stripped by the caller. An
|
|
56
|
+
# end-anchored [ \t]* after .* backtracks quadratically
|
|
57
|
+
# (CodeQL rb/polynomial-redos).
|
|
58
|
+
IMAGESDIR_ENTRY_REGEXP = /\A:(!)?imagesdir:(?:[ \t](.*))?\z/
|
|
59
|
+
|
|
60
|
+
SOURCE_IMAGESDIR_ATTRIBUTE = "lutaml-source-imagesdir"
|
|
61
|
+
|
|
62
|
+
class << self
|
|
63
|
+
# Stashes the imagesdir value the source lines set, the only
|
|
64
|
+
# form the parse-time resolution can see (attribute entries
|
|
65
|
+
# apply at parse, after preprocessing). Called from the
|
|
66
|
+
# preprocessors' process with the document's full source.
|
|
67
|
+
def scan_source_imagesdir(document, lines)
|
|
68
|
+
found = false
|
|
69
|
+
value = nil
|
|
70
|
+
lines.reverse_each do |line|
|
|
71
|
+
entry = IMAGESDIR_ENTRY_REGEXP.match(line) or next
|
|
72
|
+
value = entry[1] ? "" : (entry[2] || "").strip
|
|
73
|
+
found = true
|
|
74
|
+
break
|
|
75
|
+
end
|
|
76
|
+
return unless found
|
|
77
|
+
|
|
78
|
+
document.attributes[SOURCE_IMAGESDIR_ATTRIBUTE] = value
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# The imagesdir the figure targets are composed against: the
|
|
82
|
+
# source-set value when the source carries an entry, else the
|
|
83
|
+
# document's programmatic attributes. An empty string is the
|
|
84
|
+
# explicit unset form.
|
|
85
|
+
def effective_imagesdir(document)
|
|
86
|
+
scanned = document.attributes[SOURCE_IMAGESDIR_ATTRIBUTE]
|
|
87
|
+
scanned.nil? ? document.attributes["imagesdir"] : scanned
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Patches the RemarkItem drop class the way
|
|
91
|
+
# ExpressSchemaListing.apply patches the Schema drop class:
|
|
92
|
+
# applied before the first template render of a repository
|
|
93
|
+
# (lutaml_preprocessor's update_repo), whose Liquid memoizes a
|
|
94
|
+
# drop class's invokable methods on first render.
|
|
95
|
+
def apply
|
|
96
|
+
klass = remark_item_class
|
|
97
|
+
return unless klass
|
|
98
|
+
|
|
99
|
+
klass.ensure_liquid_registered!
|
|
100
|
+
drop_class = klass.base_drop_class
|
|
101
|
+
return unless drop_class
|
|
102
|
+
return if drop_class.include?(DropMethods)
|
|
103
|
+
|
|
104
|
+
drop_class.include(DropMethods)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private
|
|
108
|
+
|
|
109
|
+
def remark_item_class
|
|
110
|
+
return unless defined?(::Expressir::Model::Declarations::RemarkItem)
|
|
111
|
+
|
|
112
|
+
::Expressir::Model::Declarations::RemarkItem
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
module DropMethods
|
|
117
|
+
def remarks
|
|
118
|
+
if @object.respond_to?(:expressg_figure_remarks)
|
|
119
|
+
@object.expressg_figure_remarks
|
|
120
|
+
else
|
|
121
|
+
@object.remarks
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Composes the drop-facing remark text for one decorated schema.
|
|
127
|
+
# +docfile+ and +imagesdir+ are the document's attributes;
|
|
128
|
+
# +schema_directory+ is the schema's imagesdir (its source
|
|
129
|
+
# directory as the document resolves it,
|
|
130
|
+
# ExpressRemarkAdapter.schema_imagesdir).
|
|
131
|
+
class TargetResolver
|
|
132
|
+
# Asciidoctor's default imagesdir for a document that sets
|
|
133
|
+
# none: bare image targets resolve against "images" under the
|
|
134
|
+
# docfile directory.
|
|
135
|
+
DEFAULT_IMAGESDIR = "images".freeze
|
|
136
|
+
|
|
137
|
+
def initialize(docfile, imagesdir, schema_directory)
|
|
138
|
+
docdir = File.dirname(File.expand_path(docfile.to_s))
|
|
139
|
+
@docdir = docdir
|
|
140
|
+
@imagesdir_directory =
|
|
141
|
+
if imagesdir.nil? || imagesdir.empty?
|
|
142
|
+
File.join(docdir, DEFAULT_IMAGESDIR)
|
|
143
|
+
else
|
|
144
|
+
File.expand_path(imagesdir, docdir)
|
|
145
|
+
end
|
|
146
|
+
@schema_directory = schema_directory
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def remarks(texts)
|
|
150
|
+
texts.map { |text| remark(text) }
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def remark(text)
|
|
154
|
+
text.each_line.map { |line| rewrite_line(line) }.join
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
private
|
|
158
|
+
|
|
159
|
+
# The figure file is STAGED into the resolved imagesdir
|
|
160
|
+
# directory — the one directory this document's image targets
|
|
161
|
+
# resolve against, since asciidoctor joins every target with
|
|
162
|
+
# the imagesdir (the author's value, or its own "images"
|
|
163
|
+
# default) before use — and the emitted target is the staged
|
|
164
|
+
# file's bare basename. A ../-composed target escapes the
|
|
165
|
+
# imagesdir join and is dropped silently by asciidoctor's path
|
|
166
|
+
# handling (measured: the figure vanished from every output
|
|
167
|
+
# format, exit 0), and an absolute target leaks the build path
|
|
168
|
+
# (issue #359's original report). The staged copy is a build
|
|
169
|
+
# artifact; no path enters the output.
|
|
170
|
+
def rewrite_line(line)
|
|
171
|
+
match = IMAGE_MACRO_REGEXP.match(line) or return line
|
|
172
|
+
return line unless stage_figure(match[1])
|
|
173
|
+
|
|
174
|
+
trailing = line.length - line.rstrip.length
|
|
175
|
+
suffix = trailing.positive? ? line[-trailing, trailing] : ""
|
|
176
|
+
"#{line[/\Aimage::/]}#{File.basename(match[1])}[]#{suffix}"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def stage_figure(bare)
|
|
180
|
+
file = File.expand_path(bare, @schema_directory.to_s)
|
|
181
|
+
return unless File.file?(file)
|
|
182
|
+
|
|
183
|
+
staged = File.join(@imagesdir_directory, File.basename(bare))
|
|
184
|
+
return true if File.file?(staged)
|
|
185
|
+
|
|
186
|
+
FileUtils.mkdir_p(@imagesdir_directory)
|
|
187
|
+
FileUtils.cp(file, staged)
|
|
188
|
+
true
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/jsonschema"
|
|
4
|
+
|
|
5
|
+
module Metanorma
|
|
6
|
+
module Plugin
|
|
7
|
+
module Lutaml
|
|
8
|
+
# Preprocessor for JSON Schema files. Parses the schema through
|
|
9
|
+
# lutaml-jsonschema and renders documentation from its annotations
|
|
10
|
+
# (title, description, constraints).
|
|
11
|
+
#
|
|
12
|
+
# Three forms are supported:
|
|
13
|
+
# Default: lutaml_jsonschema::path[]
|
|
14
|
+
# renders the built-in reference (properties tables and
|
|
15
|
+
# definitions) as embeddable AsciiDoc
|
|
16
|
+
# Direct: lutaml_jsonschema::path[context, template, options]
|
|
17
|
+
# renders a Liquid template file with the schema as context
|
|
18
|
+
# Block: [lutaml_jsonschema, path, context, options] .... ----
|
|
19
|
+
# renders the inline Liquid template with the schema
|
|
20
|
+
class LutamlJsonschemaPreprocessor < BasePreprocessor
|
|
21
|
+
CACHE = CacheStore.new
|
|
22
|
+
|
|
23
|
+
JSONSCHEMA_PREPROCESSOR_REGEX = %r{
|
|
24
|
+
^ # Start of line
|
|
25
|
+
\[ # Opening bracket
|
|
26
|
+
(?:\blutaml_jsonschema\b) # lutaml_jsonschema
|
|
27
|
+
, # Comma separator
|
|
28
|
+
(?<index_names>[^,]+)? # Schema path(s), ";"-separated
|
|
29
|
+
,? # Optional comma
|
|
30
|
+
(?<context_name>[^,]+)? # Optional context name
|
|
31
|
+
(?<options>,.*)? # Optional options
|
|
32
|
+
\] # Closing bracket
|
|
33
|
+
}x
|
|
34
|
+
|
|
35
|
+
JSONSCHEMA_DIRECT_REGEX = %r{
|
|
36
|
+
^\s* # Start of line
|
|
37
|
+
lutaml_jsonschema:: # Macro prefix
|
|
38
|
+
(?<file_path>[^\[]+?) # Schema file path
|
|
39
|
+
\[ # Opening bracket
|
|
40
|
+
(?<attributes>[^\]]*) # Optional context, template, options
|
|
41
|
+
\] # Closing bracket
|
|
42
|
+
\s*$ # End of line
|
|
43
|
+
}x
|
|
44
|
+
|
|
45
|
+
protected
|
|
46
|
+
|
|
47
|
+
def lutaml_liquid?(line)
|
|
48
|
+
line.match(JSONSCHEMA_PREPROCESSOR_REGEX)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def load_lutaml_file(document, file_path, _options)
|
|
52
|
+
load_schema_set(document, file_path).schemas.values.first
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def index_type_name
|
|
56
|
+
"JSON Schema"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def process_text_blocks(document, input_lines, express_indexes)
|
|
62
|
+
match = input_lines.peek.match(JSONSCHEMA_DIRECT_REGEX)
|
|
63
|
+
return handle_direct_block(document, input_lines, match) if match
|
|
64
|
+
|
|
65
|
+
super
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def handle_direct_block(document, input_lines, match)
|
|
69
|
+
input_lines.next # consume the matched line
|
|
70
|
+
file_path = match[:file_path].strip
|
|
71
|
+
render_direct(document, file_path, match[:attributes])
|
|
72
|
+
.split("\n", -1)
|
|
73
|
+
rescue StandardError => e
|
|
74
|
+
::Metanorma::Util.log(
|
|
75
|
+
"[#{self.class.name}] Failed to render JSON Schema " \
|
|
76
|
+
"`#{file_path}`: #{e.message}", :error
|
|
77
|
+
)
|
|
78
|
+
raise e
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def render_direct(document, file_path, attributes)
|
|
82
|
+
context_name, template_path, options =
|
|
83
|
+
parse_direct_attributes(attributes)
|
|
84
|
+
return render_default(document, file_path) unless context_name
|
|
85
|
+
|
|
86
|
+
render_template_file(document, file_path, context_name,
|
|
87
|
+
template_path, options)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def parse_direct_attributes(attributes)
|
|
91
|
+
named, positional = split_attributes(attributes)
|
|
92
|
+
if positional.size == 1
|
|
93
|
+
raise StandardError,
|
|
94
|
+
"lutaml_jsonschema:: needs both a context name and a " \
|
|
95
|
+
"template path, or neither (for the default reference)"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
options = named.to_h { |attr| attr.split("=", 2).map(&:strip) }
|
|
99
|
+
[positional[0], positional[1], options]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def split_attributes(attributes)
|
|
103
|
+
attributes.to_s.split(",").map(&:strip).reject(&:empty?)
|
|
104
|
+
.partition { |attr| attr.include?("=") }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def render_default(document, file_path)
|
|
108
|
+
::Lutaml::Jsonschema::Exports::Adoc
|
|
109
|
+
.new(load_schema_set(document, file_path), embeddable: true)
|
|
110
|
+
.render
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def render_template_file(document, file_path, context_name,
|
|
114
|
+
template_path, options)
|
|
115
|
+
schema = load_lutaml_file(document, file_path, options)
|
|
116
|
+
template_file = Utils.relative_file_path(document, template_path)
|
|
117
|
+
tmpl = template([File.read(template_file, encoding: "UTF-8")])
|
|
118
|
+
tmpl.registers[:file_system] = build_file_system(document, options)
|
|
119
|
+
tmpl.assigns[context_name] = schema.to_liquid
|
|
120
|
+
tmpl.render
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def load_schema_set(document, file_path)
|
|
124
|
+
full_path = Utils.relative_file_path(document, file_path)
|
|
125
|
+
unless File.file?(full_path)
|
|
126
|
+
raise StandardError, index_missing_message(file_path)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
CACHE.fetch_or_store([full_path, File.mtime(full_path)]) do
|
|
130
|
+
::Lutaml::Jsonschema::SchemaSet.load_from_files(full_path)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
@@ -60,6 +60,7 @@ module Metanorma
|
|
|
60
60
|
# repository: Liquid memoizes a drop class's invokable methods
|
|
61
61
|
# on first render, so the listing method must exist by then.
|
|
62
62
|
ExpressSchemaListing.apply
|
|
63
|
+
ExpressRemarkFigures.apply
|
|
63
64
|
adapter.decorate_remarks(options)
|
|
64
65
|
unwrapped
|
|
65
66
|
end
|
|
@@ -23,6 +23,8 @@ module Metanorma
|
|
|
23
23
|
"metanorma/plugin/lutaml/data2_text_preprocessor"
|
|
24
24
|
autoload :ExpressRemarkAdapter,
|
|
25
25
|
"metanorma/plugin/lutaml/express_remark_adapter"
|
|
26
|
+
autoload :ExpressRemarkFigures,
|
|
27
|
+
"metanorma/plugin/lutaml/express_remark_figures"
|
|
26
28
|
autoload :ExpressRepositoryCache,
|
|
27
29
|
"metanorma/plugin/lutaml/express_repository_cache"
|
|
28
30
|
autoload :ExpressSchemaListing,
|
|
@@ -55,6 +57,8 @@ module Metanorma
|
|
|
55
57
|
"metanorma/plugin/lutaml/lutaml_gml_dictionary_block_macro"
|
|
56
58
|
autoload :LutamlKlassTableBlockMacro,
|
|
57
59
|
"metanorma/plugin/lutaml/lutaml_klass_table_block_macro"
|
|
60
|
+
autoload :LutamlJsonschemaPreprocessor,
|
|
61
|
+
"metanorma/plugin/lutaml/lutaml_jsonschema_preprocessor"
|
|
58
62
|
autoload :LutamlPreprocessor,
|
|
59
63
|
"metanorma/plugin/lutaml/lutaml_preprocessor"
|
|
60
64
|
autoload :LutamlTableInlineMacro,
|
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
|
|
|
34
34
|
spec.add_dependency "expressir", "~> 2.3", ">= 2.3.5"
|
|
35
35
|
spec.add_dependency "isodoc", ">= 3.5.0"
|
|
36
36
|
spec.add_dependency "liquid", "~> 5"
|
|
37
|
+
spec.add_dependency "lutaml-jsonschema", "~> 0.1", ">= 0.1.29"
|
|
37
38
|
spec.add_dependency "lutaml-lml"
|
|
38
39
|
spec.add_dependency "lutaml-model", "~> 0.8.156"
|
|
39
40
|
spec.add_dependency "lutaml-uml", ">= 0.5", "< 2"
|
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.
|
|
4
|
+
version: 0.7.74
|
|
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-
|
|
11
|
+
date: 2026-11-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: asciidoctor
|
|
@@ -100,6 +100,26 @@ dependencies:
|
|
|
100
100
|
- - "~>"
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
102
|
version: '5'
|
|
103
|
+
- !ruby/object:Gem::Dependency
|
|
104
|
+
name: lutaml-jsonschema
|
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - "~>"
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0.1'
|
|
110
|
+
- - ">="
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: 0.1.29
|
|
113
|
+
type: :runtime
|
|
114
|
+
prerelease: false
|
|
115
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
116
|
+
requirements:
|
|
117
|
+
- - "~>"
|
|
118
|
+
- !ruby/object:Gem::Version
|
|
119
|
+
version: '0.1'
|
|
120
|
+
- - ">="
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: 0.1.29
|
|
103
123
|
- !ruby/object:Gem::Dependency
|
|
104
124
|
name: lutaml-lml
|
|
105
125
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -189,6 +209,7 @@ files:
|
|
|
189
209
|
- docs/usages/json_yaml.adoc
|
|
190
210
|
- docs/usages/lutaml-data.adoc
|
|
191
211
|
- docs/usages/lutaml-gml.adoc
|
|
212
|
+
- docs/usages/lutaml-jsonschema.adoc
|
|
192
213
|
- docs/usages/lutaml-uml.adoc
|
|
193
214
|
- docs/usages/lutaml-xsd.adoc
|
|
194
215
|
- docs/usages/xmi_to_uml.adoc
|
|
@@ -465,6 +486,7 @@ files:
|
|
|
465
486
|
- lib/metanorma/plugin/lutaml/data_providers.rb
|
|
466
487
|
- lib/metanorma/plugin/lutaml/express_hotspot_anchor.rb
|
|
467
488
|
- lib/metanorma/plugin/lutaml/express_remark_adapter.rb
|
|
489
|
+
- lib/metanorma/plugin/lutaml/express_remark_figures.rb
|
|
468
490
|
- lib/metanorma/plugin/lutaml/express_repository_cache.rb
|
|
469
491
|
- lib/metanorma/plugin/lutaml/express_schema_listing.rb
|
|
470
492
|
- lib/metanorma/plugin/lutaml/file_not_found_error.rb
|
|
@@ -520,6 +542,7 @@ files:
|
|
|
520
542
|
- lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_base.rb
|
|
521
543
|
- lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_block.rb
|
|
522
544
|
- lib/metanorma/plugin/lutaml/lutaml_gml_dictionary_block_macro.rb
|
|
545
|
+
- lib/metanorma/plugin/lutaml/lutaml_jsonschema_preprocessor.rb
|
|
523
546
|
- lib/metanorma/plugin/lutaml/lutaml_klass_table_block_macro.rb
|
|
524
547
|
- lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
|
|
525
548
|
- lib/metanorma/plugin/lutaml/lutaml_table_inline_macro.rb
|