metanorma-plugin-lutaml 0.7.72 → 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/docs/usages/lutaml-xsd.adoc +59 -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/express_schema_listing.rb +65 -9
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_attribute.liquid +24 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_attribute_group.liquid +60 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_attribute_value_constraints.liquid +65 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_child_elements.liquid +34 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_complex_type.liquid +109 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_diagram.liquid +25 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_diagram_children.liquid +31 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_element.liquid +110 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_xml_example_attribute.liquid +2 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_xml_example_child.liquid +26 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_xsd_ref.liquid +19 -0
- data/lib/metanorma/plugin/lutaml/liquid_templates/xsd/_xsd_schema.liquid +32 -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/lutaml_xsd_preprocessor.rb +33 -6
- 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 +37 -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`.
|
data/docs/usages/lutaml-xsd.adoc
CHANGED
|
@@ -82,6 +82,65 @@ Type: *{{ element.type }}*
|
|
|
82
82
|
----
|
|
83
83
|
-----
|
|
84
84
|
|
|
85
|
+
=== Default template
|
|
86
|
+
|
|
87
|
+
The plugin ships a default template that documents a whole schema: every
|
|
88
|
+
global element, complex type and attribute group, with its annotations,
|
|
89
|
+
attributes, content model, an XML example and a PlantUML structure diagram.
|
|
90
|
+
|
|
91
|
+
To render it, use the direct syntax without a template:
|
|
92
|
+
|
|
93
|
+
[source,adoc]
|
|
94
|
+
-----
|
|
95
|
+
lutaml_xsd::path/to/unitsml.xsd[schema]
|
|
96
|
+
-----
|
|
97
|
+
|
|
98
|
+
The direct syntax also takes a template file of your own:
|
|
99
|
+
`lutaml_xsd::path/to/unitsml.xsd[schema, templates/schema.liquid]`.
|
|
100
|
+
|
|
101
|
+
To skip the structure diagrams, for example when PlantUML is not
|
|
102
|
+
installed, add `diagrams=false`:
|
|
103
|
+
|
|
104
|
+
[source,adoc]
|
|
105
|
+
-----
|
|
106
|
+
lutaml_xsd::path/to/unitsml.xsd[schema, diagrams=false]
|
|
107
|
+
-----
|
|
108
|
+
|
|
109
|
+
The default templates are always on the template search path of a
|
|
110
|
+
`lutaml_xsd` block, so the same output is available from the block syntax:
|
|
111
|
+
|
|
112
|
+
[source,adoc]
|
|
113
|
+
-----
|
|
114
|
+
[lutaml_xsd,path/to/unitsml.xsd,schema]
|
|
115
|
+
----
|
|
116
|
+
{% render "xsd_schema", schema: schema, diagrams: false %}
|
|
117
|
+
----
|
|
118
|
+
-----
|
|
119
|
+
|
|
120
|
+
You can also render single parts, such as `element`, `complex_type` or
|
|
121
|
+
`attribute_group`, for one item:
|
|
122
|
+
|
|
123
|
+
[source,adoc]
|
|
124
|
+
-----
|
|
125
|
+
[lutaml_xsd,path/to/unitsml.xsd,schema]
|
|
126
|
+
----
|
|
127
|
+
{% for item in schema.elements_sorted_by_name %}
|
|
128
|
+
{% render "element", item: item, schema: schema %}
|
|
129
|
+
{% endfor %}
|
|
130
|
+
----
|
|
131
|
+
-----
|
|
132
|
+
|
|
133
|
+
The default output adds these anchors:
|
|
134
|
+
|
|
135
|
+
* `xsd_<name>` for elements
|
|
136
|
+
* `xsd_type_<name>` for complex types
|
|
137
|
+
* `xsd_attribute_group_<name>` for attribute groups
|
|
138
|
+
|
|
139
|
+
To change one part of the output, put a file with the same name, such as
|
|
140
|
+
`_diagram.liquid` or `_element.adoc`, in the document directory or in a
|
|
141
|
+
directory given with `include_path`. Files there take precedence over the
|
|
142
|
+
default templates.
|
|
143
|
+
|
|
85
144
|
=== Use Cases
|
|
86
145
|
|
|
87
146
|
* Generate documentation for XML schemas.
|
|
@@ -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
|
|
@@ -13,6 +13,17 @@ module Metanorma
|
|
|
13
13
|
# the schema's relative image macros resolve as written, with no
|
|
14
14
|
# build path in the remark text (TRThurman's source-fidelity
|
|
15
15
|
# requirements).
|
|
16
|
+
#
|
|
17
|
+
# The schema's EXPRESS-G figure remark (`__expressg`, carrying the
|
|
18
|
+
# svgmap figure blocks) is not source: it is extraction fodder.
|
|
19
|
+
# Inside the fence it prints as listing text and the figures are
|
|
20
|
+
# lost (metanorma/metanorma-plugin-lutaml#360 — the pre-0.7.70
|
|
21
|
+
# listings only rendered figures because their hardcoded fence
|
|
22
|
+
# closed early, an accident the computed fence removed). The
|
|
23
|
+
# 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.
|
|
16
27
|
module ExpressSchemaListing
|
|
17
28
|
SOURCE_BLOCK_HEADING = '[source%unnumbered,subs="+macros"]'
|
|
18
29
|
# A dash run of two or more at line start: only such a run can
|
|
@@ -22,6 +33,17 @@ module Metanorma
|
|
|
22
33
|
# Asciidoctor's shortest valid listing fence: a three-dash line
|
|
23
34
|
# is not a block delimiter at all.
|
|
24
35
|
MIN_FENCE_LENGTH = 4
|
|
36
|
+
# An EXPRESS-G figure remark as the source formatter prints it:
|
|
37
|
+
# the `(*"...__expressg"` header at line start, the figure body,
|
|
38
|
+
# and the closing `*)` on its own line. One blank line before the
|
|
39
|
+
# block and the newline after it go with it, so the removal does
|
|
40
|
+
# not stack blank lines around the fence. Remarks do not nest and
|
|
41
|
+
# cannot contain `*)`, so the first line-anchored `*)` closes.
|
|
42
|
+
EXPRESSG_REMARK_REGEXP =
|
|
43
|
+
%r{^\n?\(\*"[^\n]*__expressg[^\n]*"\n.*?^\*\)\n?}m
|
|
44
|
+
# The same remark with the figure body captured.
|
|
45
|
+
EXPRESSG_FIGURE_BODY_REGEXP =
|
|
46
|
+
%r{^\(\*"[^\n]*__expressg[^\n]*"\n(.*?)^\*\)}m
|
|
25
47
|
|
|
26
48
|
class << self
|
|
27
49
|
# Makes formatted_hyperlinked_adoc_listing available to liquid
|
|
@@ -54,8 +76,36 @@ module Metanorma
|
|
|
54
76
|
"-" * fence_length(content)
|
|
55
77
|
end
|
|
56
78
|
|
|
79
|
+
# Splits a printed schema into its listing source and the
|
|
80
|
+
# EXPRESS-G figure blocks: every `__expressg` remark is lifted
|
|
81
|
+
# out whole and its figure body (the svgmap figure adoc, as
|
|
82
|
+
# written) is kept for emission after the listing. The body's
|
|
83
|
+
# trailing newline belongs to the remark's closing marker, not
|
|
84
|
+
# to the content, and the body's EXPRESS nesting indent comes
|
|
85
|
+
# off as well — asciidoctor opens a delimited block only on a
|
|
86
|
+
# delimiter at column 0, so an indented `[.svgmap]`/`====`
|
|
87
|
+
# figure prints as text. Relative indentation within the body
|
|
88
|
+
# is kept. Content without an EXPRESS-G remark passes through
|
|
89
|
+
# unchanged.
|
|
90
|
+
def extract_expressg_figures(content)
|
|
91
|
+
figures = content.scan(EXPRESSG_FIGURE_BODY_REGEXP)
|
|
92
|
+
.map { |match| dedent(match.first.strip) }
|
|
93
|
+
stripped = content.gsub(EXPRESSG_REMARK_REGEXP, "")
|
|
94
|
+
[stripped, figures.reject(&:empty?)]
|
|
95
|
+
end
|
|
96
|
+
|
|
57
97
|
private
|
|
58
98
|
|
|
99
|
+
def dedent(body)
|
|
100
|
+
indent = body.each_line
|
|
101
|
+
.reject { |line| line.strip.empty? }
|
|
102
|
+
.filter_map { |line| line[/\A[ \t]+/] }
|
|
103
|
+
.min_by(&:length)
|
|
104
|
+
return body unless indent
|
|
105
|
+
|
|
106
|
+
body.gsub(/^#{Regexp.escape(indent)}/, "")
|
|
107
|
+
end
|
|
108
|
+
|
|
59
109
|
def schema_class
|
|
60
110
|
return unless defined?(::Expressir::Model::Declarations::Schema)
|
|
61
111
|
|
|
@@ -68,31 +118,37 @@ module Metanorma
|
|
|
68
118
|
# readers (the drop has no access to the asciidoctor document);
|
|
69
119
|
# attribute entries are emitted immediately before and after the
|
|
70
120
|
# block, since attribute entries take effect sequentially and
|
|
71
|
-
# cannot be changed inside the listing itself.
|
|
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.
|
|
72
124
|
module DropMethods
|
|
73
125
|
def formatted_hyperlinked_adoc_listing
|
|
74
|
-
|
|
75
|
-
|
|
126
|
+
source, figures = ExpressSchemaListing
|
|
127
|
+
.extract_expressg_figures(
|
|
128
|
+
@object.formatted_hyperlinked_adoc.to_s,
|
|
129
|
+
)
|
|
130
|
+
fence = ExpressSchemaListing.fence(source)
|
|
76
131
|
listing = [
|
|
77
132
|
SOURCE_BLOCK_HEADING,
|
|
78
133
|
fence,
|
|
79
|
-
|
|
134
|
+
source,
|
|
80
135
|
fence,
|
|
81
136
|
].join("\n")
|
|
82
|
-
with_imagesdir_entries(listing)
|
|
137
|
+
with_imagesdir_entries(listing, figures)
|
|
83
138
|
end
|
|
84
139
|
|
|
85
140
|
private
|
|
86
141
|
|
|
87
|
-
def with_imagesdir_entries(listing)
|
|
88
|
-
|
|
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)
|
|
89
145
|
|
|
90
146
|
dir = @object.listing_imagesdir
|
|
91
|
-
return
|
|
147
|
+
return body unless dir
|
|
92
148
|
|
|
93
149
|
restore = @object.listing_imagesdir_restore
|
|
94
150
|
closing = restore ? ":imagesdir: #{restore}" : ":!imagesdir:"
|
|
95
|
-
":imagesdir: #{dir}\n\n#{
|
|
151
|
+
":imagesdir: #{dir}\n\n#{body}\n\n#{closing}"
|
|
96
152
|
end
|
|
97
153
|
end
|
|
98
154
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{%- assign attribute_name = attribute.referenced_name | default: attribute.name | default: attribute.ref -%}
|
|
2
|
+
{%- assign attribute_type = attribute.referenced_type | default: attribute.type -%}
|
|
3
|
+
{%- capture attribute_docs -%}
|
|
4
|
+
{% for paragraph in attribute.annotation.documentation -%}
|
|
5
|
+
{{ paragraph.content }}
|
|
6
|
+
|
|
7
|
+
{% endfor -%}
|
|
8
|
+
{%- endcapture -%}
|
|
9
|
+
{%- assign attribute_docs = attribute_docs | strip -%}
|
|
10
|
+
{%- capture constraints -%}
|
|
11
|
+
{% render "attribute_value_constraints", attribute: attribute %}
|
|
12
|
+
{%- endcapture -%}
|
|
13
|
+
{%- assign constraints = constraints | strip -%}
|
|
14
|
+
|
|
15
|
+
`@{{ attribute_name }}`:: {% if attribute_type %}`{{ attribute_type }}` {% endif %}`[{{ attribute.cardinality | default: "0..1" }}]`
|
|
16
|
+
{% if attribute_docs != "" %}
|
|
17
|
+
+
|
|
18
|
+
--
|
|
19
|
+
{{ attribute_docs }}
|
|
20
|
+
--
|
|
21
|
+
{% endif %}
|
|
22
|
+
{% if constraints != "" %}
|
|
23
|
+
{{ constraints }}
|
|
24
|
+
{% endif %}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{%- assign item_attributes = item.attribute_elements -%}
|
|
2
|
+
{%- assign used_by_items = item.used_by -%}
|
|
3
|
+
{%- capture docs -%}
|
|
4
|
+
{% for paragraph in item.annotation.documentation -%}
|
|
5
|
+
{{ paragraph.content }}
|
|
6
|
+
|
|
7
|
+
{% endfor -%}
|
|
8
|
+
{%- endcapture -%}
|
|
9
|
+
{%- assign docs = docs | strip -%}
|
|
10
|
+
{%- capture used_by_list -%}
|
|
11
|
+
{% for used_by in used_by_items -%}
|
|
12
|
+
{%- capture used_by_kind -%}{% if used_by.element? %}element{% elsif used_by.attribute_group? %}attribute_group{% else %}type{% endif %}{%- endcapture %}
|
|
13
|
+
* {{ used_by.name }}{% render "xsd_ref", name: used_by.name, kind: used_by_kind, schema: schema %}
|
|
14
|
+
{% endfor -%}
|
|
15
|
+
{%- endcapture -%}
|
|
16
|
+
{%- assign used_by_list = used_by_list | strip -%}
|
|
17
|
+
{%- capture attribute_list -%}
|
|
18
|
+
{% for attribute in item_attributes -%}
|
|
19
|
+
{% render "attribute", attribute: attribute %}
|
|
20
|
+
|
|
21
|
+
{% endfor -%}
|
|
22
|
+
{%- endcapture -%}
|
|
23
|
+
{%- assign attribute_list = attribute_list | strip -%}
|
|
24
|
+
|
|
25
|
+
[[xsd_attribute_group_{{ item.name }}]]
|
|
26
|
+
=== `{{ item.name }}`
|
|
27
|
+
|
|
28
|
+
==== Group
|
|
29
|
+
|
|
30
|
+
{% if docs != "" %}
|
|
31
|
+
{{ docs }}
|
|
32
|
+
{% else %}
|
|
33
|
+
No documentation supplied.
|
|
34
|
+
{% endif %}
|
|
35
|
+
|
|
36
|
+
{% if used_by_items.size > 0 %}
|
|
37
|
+
This attribute group is used by:
|
|
38
|
+
|
|
39
|
+
{{ used_by_list }}
|
|
40
|
+
{% endif %}
|
|
41
|
+
|
|
42
|
+
{% unless diagrams == false %}
|
|
43
|
+
==== Structure diagram
|
|
44
|
+
|
|
45
|
+
{% render "diagram", item: item, attributes: item_attributes, schema: schema %}
|
|
46
|
+
{% endunless %}
|
|
47
|
+
|
|
48
|
+
==== Attributes
|
|
49
|
+
|
|
50
|
+
{% if item_attributes.size > 0 %}
|
|
51
|
+
{{ attribute_list }}
|
|
52
|
+
{% else %}
|
|
53
|
+
No attributes defined.
|
|
54
|
+
{% endif %}
|
|
55
|
+
|
|
56
|
+
.XSD source of `{{ item.name }}`
|
|
57
|
+
[source,xml]
|
|
58
|
+
-----
|
|
59
|
+
{{ item.to_formatted_xml }}
|
|
60
|
+
-----
|