metanorma-plugin-lutaml 0.7.72 → 0.7.73
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/docs/usages/lutaml-xsd.adoc +59 -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_xsd_preprocessor.rb +33 -6
- data/lib/metanorma/plugin/lutaml/version.rb +1 -1
- metadata +13 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1662314db4b6726c36bc6edf1d7d741735f6f3c08632ea55c209667037eeee33
|
|
4
|
+
data.tar.gz: b910af1297f97f930643b4c2039af36c26f8d753d71b21ced0abf47da9306ed3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d8d1c32f22f3c529037de1ada6adb3519a855d499c83a4a9ba3bc8a530c57e0e19bf0e64f92629e9df262048330c14b3eb0317cc836aaaa8ecedc98bc1a6274d
|
|
7
|
+
data.tar.gz: b5faab6e73acdbd20ba770208fd9af8a7f8959e6cffaf17654c72e65cd76dc312226c32a684819a473e6c851e135afa934b3f0239d950a1465c7e789ead8ba27
|
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.
|
|
@@ -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
|
+
-----
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{%- assign simple_type = attribute.simple_type -%}
|
|
2
|
+
{%- if simple_type == nil and attribute.referenced_object -%}
|
|
3
|
+
{%- assign simple_type = attribute.referenced_object.simple_type -%}
|
|
4
|
+
{%- endif -%}
|
|
5
|
+
{%- if simple_type -%}
|
|
6
|
+
{%- assign restriction = simple_type.restriction -%}
|
|
7
|
+
{%- assign union = simple_type.union -%}
|
|
8
|
+
{%- if restriction -%}
|
|
9
|
+
{%- assign enum_values = restriction.enumeration | map: "value" -%}
|
|
10
|
+
{%- assign pattern_values = restriction.pattern | map: "value" -%}
|
|
11
|
+
{%- capture constraint_body -%}
|
|
12
|
+
{% if restriction.base -%}
|
|
13
|
+
Base type: `{{ restriction.base }}`
|
|
14
|
+
{% endif -%}
|
|
15
|
+
{% if enum_values.size > 0 %}
|
|
16
|
+
|
|
17
|
+
Allowed values:
|
|
18
|
+
|
|
19
|
+
{% for enum_value in enum_values %}
|
|
20
|
+
* `{{ enum_value }}`
|
|
21
|
+
{% endfor %}
|
|
22
|
+
{% endif -%}
|
|
23
|
+
{% if pattern_values.size > 0 %}
|
|
24
|
+
|
|
25
|
+
Patterns:
|
|
26
|
+
|
|
27
|
+
{% for pattern_value in pattern_values %}
|
|
28
|
+
* `{{ pattern_value }}`
|
|
29
|
+
{% endfor %}
|
|
30
|
+
{% endif -%}
|
|
31
|
+
{%- endcapture -%}
|
|
32
|
+
{%- assign constraint_body = constraint_body | strip -%}
|
|
33
|
+
{%- if constraint_body != "" %}
|
|
34
|
+
+
|
|
35
|
+
--
|
|
36
|
+
{{ constraint_body }}
|
|
37
|
+
--
|
|
38
|
+
{% endif -%}
|
|
39
|
+
{%- elsif union -%}
|
|
40
|
+
{%- capture union_body -%}
|
|
41
|
+
{% if union.member_types -%}
|
|
42
|
+
Member types: `{{ union.member_types }}`
|
|
43
|
+
{% endif -%}
|
|
44
|
+
{% for union_simple_type in union.simple_type -%}
|
|
45
|
+
{% assign union_restriction = union_simple_type.restriction -%}
|
|
46
|
+
{% assign union_enum_values = union_restriction.enumeration | map: "value" -%}
|
|
47
|
+
{% if union_enum_values.size > 0 %}
|
|
48
|
+
|
|
49
|
+
Allowed `{{ union_restriction.base }}` values:
|
|
50
|
+
|
|
51
|
+
{% for union_enum_value in union_enum_values %}
|
|
52
|
+
* `{{ union_enum_value }}`
|
|
53
|
+
{% endfor %}
|
|
54
|
+
{% endif -%}
|
|
55
|
+
{% endfor -%}
|
|
56
|
+
{%- endcapture -%}
|
|
57
|
+
{%- assign union_body = union_body | strip -%}
|
|
58
|
+
{%- if union_body != "" %}
|
|
59
|
+
+
|
|
60
|
+
--
|
|
61
|
+
{{ union_body }}
|
|
62
|
+
--
|
|
63
|
+
{% endif -%}
|
|
64
|
+
{%- endif -%}
|
|
65
|
+
{%- endif -%}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{%- assign marker = marker | default: "*" -%}
|
|
2
|
+
{%- assign child_marker = marker | append: "*" -%}
|
|
3
|
+
{%- capture cardinality -%}[{{ child.min_occurrences | default: "1" }}..{{ child.max_occurrences | default: "1" }}]{%- endcapture -%}
|
|
4
|
+
{%- if child.annotation? or child.attribute? or child.attribute_group? -%}
|
|
5
|
+
{%- elsif child.sequence? %}
|
|
6
|
+
{{ marker }} Sequence {{ cardinality }}
|
|
7
|
+
{% for element in child.resolved_element_order -%}
|
|
8
|
+
{% render "child_elements", child: element, marker: child_marker %}
|
|
9
|
+
{% endfor -%}
|
|
10
|
+
{%- elsif child.choice? %}
|
|
11
|
+
{{ marker }} Choice {{ cardinality }}
|
|
12
|
+
{% for element in child.resolved_element_order -%}
|
|
13
|
+
{% render "child_elements", child: element, marker: child_marker %}
|
|
14
|
+
{% endfor -%}
|
|
15
|
+
{%- elsif child.all? %}
|
|
16
|
+
{{ marker }} All {{ cardinality }}
|
|
17
|
+
{% for element in child.resolved_element_order -%}
|
|
18
|
+
{% render "child_elements", child: element, marker: child_marker %}
|
|
19
|
+
{% endfor -%}
|
|
20
|
+
{%- elsif child.any? %}
|
|
21
|
+
{{ marker }} Any element from any namespace ({{ child.process_contents | default: "strict" }} processing) {{ cardinality }}
|
|
22
|
+
{%- elsif child.simple_content? %}
|
|
23
|
+
{{ marker }} Simple content based on `{{ child.base_type | default: child.base }}` {{ cardinality }}
|
|
24
|
+
{%- elsif child.element? -%}
|
|
25
|
+
{%- assign element_name = child.referenced_name | default: child.name | default: child.ref -%}
|
|
26
|
+
{%- assign element_type = child.referenced_type | default: child.type -%}
|
|
27
|
+
{{ marker }} `<{{ element_name }}>`{% if element_type %} of type `{{ element_type }}`{% endif %} {{ cardinality }}
|
|
28
|
+
{%- elsif child.child_elements.size > 0 -%}
|
|
29
|
+
{%- assign group_name = child.name | default: child.ref | default: "anonymous" -%}
|
|
30
|
+
{{ marker }} Group `{{ group_name }}` {{ cardinality }}
|
|
31
|
+
{% for element in child.child_elements -%}
|
|
32
|
+
{% render "child_elements", child: element, marker: child_marker %}
|
|
33
|
+
{% endfor -%}
|
|
34
|
+
{%- endif -%}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
{%- assign item_attributes = item.attribute_elements -%}
|
|
2
|
+
{%- assign used_by_items = item.used_by -%}
|
|
3
|
+
{%- assign content_model_items = item.resolved_element_order -%}
|
|
4
|
+
{%- capture docs -%}
|
|
5
|
+
{% for paragraph in item.annotation.documentation -%}
|
|
6
|
+
{{ paragraph.content }}
|
|
7
|
+
|
|
8
|
+
{% endfor -%}
|
|
9
|
+
{%- endcapture -%}
|
|
10
|
+
{%- assign docs = docs | strip -%}
|
|
11
|
+
{%- capture used_by_list -%}
|
|
12
|
+
{% for used_by in used_by_items -%}
|
|
13
|
+
{%- capture used_by_kind -%}{% if used_by.element? %}element{% elsif used_by.attribute_group? %}attribute_group{% else %}type{% endif %}{%- endcapture %}
|
|
14
|
+
* {{ used_by.name }}{% render "xsd_ref", name: used_by.name, kind: used_by_kind, schema: schema %}
|
|
15
|
+
{% endfor -%}
|
|
16
|
+
{%- endcapture -%}
|
|
17
|
+
{%- assign used_by_list = used_by_list | strip -%}
|
|
18
|
+
{%- assign example_element = used_by_items | first -%}
|
|
19
|
+
{%- assign example_element_name = example_element.name -%}
|
|
20
|
+
{%- capture attribute_list -%}
|
|
21
|
+
{% for attribute in item_attributes -%}
|
|
22
|
+
{% render "attribute", attribute: attribute %}
|
|
23
|
+
|
|
24
|
+
{% endfor -%}
|
|
25
|
+
{%- endcapture -%}
|
|
26
|
+
{%- assign attribute_list = attribute_list | strip -%}
|
|
27
|
+
{%- capture content_model_list -%}
|
|
28
|
+
{% for child in content_model_items -%}
|
|
29
|
+
{% render "child_elements", child: child %}
|
|
30
|
+
{% endfor -%}
|
|
31
|
+
{%- endcapture -%}
|
|
32
|
+
{%- assign content_model_list = content_model_list | strip -%}
|
|
33
|
+
{%- capture example_attributes -%}
|
|
34
|
+
{% for attr in item_attributes -%}
|
|
35
|
+
{% render "xml_example_attribute", attr: attr -%}
|
|
36
|
+
{% endfor -%}
|
|
37
|
+
{%- endcapture -%}
|
|
38
|
+
{%- capture example_children -%}
|
|
39
|
+
{% if item.mixed -%}
|
|
40
|
+
<!-- mixed content -->
|
|
41
|
+
{% endif -%}
|
|
42
|
+
{% for child in content_model_items -%}
|
|
43
|
+
{% render "xml_example_child", child: child, indent: " " -%}
|
|
44
|
+
{% endfor -%}
|
|
45
|
+
{%- endcapture -%}
|
|
46
|
+
|
|
47
|
+
[[xsd_type_{{ item.name }}]]
|
|
48
|
+
=== `{{ item.name }}`
|
|
49
|
+
|
|
50
|
+
==== General
|
|
51
|
+
|
|
52
|
+
{% if docs != "" %}
|
|
53
|
+
{{ docs }}
|
|
54
|
+
{% else %}
|
|
55
|
+
No documentation supplied.
|
|
56
|
+
{% endif %}
|
|
57
|
+
|
|
58
|
+
{% if used_by_items.size > 0 %}
|
|
59
|
+
This complex type is used by:
|
|
60
|
+
|
|
61
|
+
{{ used_by_list }}
|
|
62
|
+
{% endif %}
|
|
63
|
+
|
|
64
|
+
{% unless diagrams == false %}
|
|
65
|
+
==== Structure diagram
|
|
66
|
+
|
|
67
|
+
{% render "diagram", item: item, attributes: item_attributes, children: content_model_items, schema: schema %}
|
|
68
|
+
{% endunless %}
|
|
69
|
+
|
|
70
|
+
==== Attributes
|
|
71
|
+
|
|
72
|
+
{% if item_attributes.size > 0 %}
|
|
73
|
+
{{ attribute_list }}
|
|
74
|
+
{% else %}
|
|
75
|
+
No attributes defined.
|
|
76
|
+
{% endif %}
|
|
77
|
+
|
|
78
|
+
==== Content model
|
|
79
|
+
|
|
80
|
+
{% if item.mixed %}
|
|
81
|
+
This complex type allows mixed content.
|
|
82
|
+
|
|
83
|
+
{% endif %}
|
|
84
|
+
{% if content_model_list != "" %}
|
|
85
|
+
{{ content_model_list }}
|
|
86
|
+
{% else %}
|
|
87
|
+
No child elements defined.
|
|
88
|
+
{% endif %}
|
|
89
|
+
|
|
90
|
+
{% if example_element_name %}
|
|
91
|
+
[example]
|
|
92
|
+
.Illustrative element using `{{ item.name }}`
|
|
93
|
+
====
|
|
94
|
+
[source,xml]
|
|
95
|
+
-----
|
|
96
|
+
<{{ example_element_name }}{{ example_attributes }}{% if example_children != "" %}>
|
|
97
|
+
{% if example_children != "" %}{{ example_children }}{% endif %}
|
|
98
|
+
</{{ example_element_name }}>
|
|
99
|
+
{% else %}/>
|
|
100
|
+
{% endif %}
|
|
101
|
+
-----
|
|
102
|
+
====
|
|
103
|
+
{% endif %}
|
|
104
|
+
|
|
105
|
+
.XSD source of `{{ item.name }}`
|
|
106
|
+
[source,xml]
|
|
107
|
+
-----
|
|
108
|
+
{{ item.to_formatted_xml }}
|
|
109
|
+
-----
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{%- assign root_id = "schema_" | append: item.name -%}
|
|
2
|
+
{%- if item.element? -%}{%- assign root_anchor = "xsd_" -%}{%- elsif item.attribute_group? -%}{%- assign root_anchor = "xsd_attribute_group_" -%}{%- else -%}{%- assign root_anchor = "xsd_type_" -%}{%- endif -%}
|
|
3
|
+
The diagram shows attributes and the content model in schema order.
|
|
4
|
+
Element edges show occurrence ranges; see the declarations below for all constraints.
|
|
5
|
+
|
|
6
|
+
.Structure of `{{ item.name }}`
|
|
7
|
+
[plantuml,format=svg]
|
|
8
|
+
....
|
|
9
|
+
@startuml {{ root_anchor }}{{ item.name }}
|
|
10
|
+
!pragma layout smetana
|
|
11
|
+
left to right direction
|
|
12
|
+
hide empty members
|
|
13
|
+
hide circle
|
|
14
|
+
skinparam classAttributeIconSize 0
|
|
15
|
+
skinparam shadowing false
|
|
16
|
+
class "{{ item.name }}{% if item.element? and item.type %} : {{ item.type }}{% endif %}" as {{ root_id }} [[#{{ root_anchor }}{{ item.name }}]] {
|
|
17
|
+
{% for attribute in attributes %}
|
|
18
|
+
{%- assign attribute_name = attribute.referenced_name | default: attribute.name | default: attribute.ref -%}
|
|
19
|
+
{%- assign attribute_type = attribute.referenced_type | default: attribute.type -%}
|
|
20
|
+
@{{ attribute_name }}{% if attribute_type %} : {{ attribute_type }}{% endif %} [{{ attribute.cardinality | default: "0..1" }}]
|
|
21
|
+
{% endfor %}
|
|
22
|
+
}
|
|
23
|
+
{% render "diagram_children", children: children, parent_id: root_id, schema: schema %}
|
|
24
|
+
@enduml
|
|
25
|
+
....
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{%- assign position = 0 -%}
|
|
2
|
+
{% for child in children %}
|
|
3
|
+
{%- assign node_id = parent_id | append: "_" | append: forloop.index0 -%}
|
|
4
|
+
{%- assign minimum = child.min_occurs | default: child.min_occurrences | default: "1" -%}
|
|
5
|
+
{%- assign maximum = child.max_occurs | default: child.max_occurrences | default: "1" | replace: "unbounded", "*" -%}
|
|
6
|
+
{%- if child.annotation? or child.attribute? or child.attribute_group? -%}
|
|
7
|
+
{%- elsif child.element? -%}
|
|
8
|
+
{%- assign position = position | plus: 1 -%}
|
|
9
|
+
{%- assign element_name = child.referenced_name | default: child.name | default: child.ref -%}
|
|
10
|
+
{%- assign element_type = child.referenced_type | default: child.type -%}
|
|
11
|
+
{%- assign global_element = schema.elements_sorted_by_name | where: "name", element_name | first -%}
|
|
12
|
+
{%- assign element_type_name = element_type | split: ":" | last -%}
|
|
13
|
+
{%- assign global_type = schema.complex_types_sorted_by_name | where: "name", element_type_name | first -%}
|
|
14
|
+
class "{{ element_name }}{% if element_type %} : {{ element_type }}{% endif %}" as {{ node_id }}{% if global_element %} [[#xsd_{{ global_element.name }}]]{% elsif global_type %} [[#xsd_type_{{ global_type.name }}]]{% endif %}
|
|
15
|
+
{{ parent_id }} --> {{ node_id }} : {{ position }}. [{{ minimum }}..{{ maximum }}]
|
|
16
|
+
{%- elsif child.any? %}
|
|
17
|
+
{%- assign position = position | plus: 1 -%}
|
|
18
|
+
class "Any element\n{{ child.process_contents | default: "strict" }} processing" as {{ node_id }}
|
|
19
|
+
{{ parent_id }} --> {{ node_id }} : {{ position }}. [{{ minimum }}..{{ maximum }}]
|
|
20
|
+
{%- elsif child.simple_content? %}
|
|
21
|
+
{%- assign position = position | plus: 1 -%}
|
|
22
|
+
class "Simple content\n{{ child.base_type | default: child.base }}" as {{ node_id }}
|
|
23
|
+
{{ parent_id }} --> {{ node_id }}
|
|
24
|
+
{%- elsif child.resolved_element_order.size > 0 %}
|
|
25
|
+
{%- assign position = position | plus: 1 -%}
|
|
26
|
+
{%- capture label -%}{% if child.sequence? %}Sequence{% elsif child.choice? %}Choice{% elsif child.all? %}All{% elsif child.complex_content? %}Complex content{% else %}Group{% endif %}{%- endcapture %}
|
|
27
|
+
class "{{ label }}" as {{ node_id }}
|
|
28
|
+
{{ parent_id }} --> {{ node_id }} : {{ position }}.
|
|
29
|
+
{% render "diagram_children", children: child.resolved_element_order, parent_id: node_id, schema: schema %}
|
|
30
|
+
{% endif %}
|
|
31
|
+
{% endfor %}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
{%- assign item_complex_type = item.referenced_complex_type -%}
|
|
2
|
+
{%- assign item_attributes = item.attributes -%}
|
|
3
|
+
{%- assign used_by_items = item.used_by -%}
|
|
4
|
+
{%- assign content_model_items = item_complex_type.resolved_element_order -%}
|
|
5
|
+
{%- capture docs -%}
|
|
6
|
+
{% for paragraph in item.annotation.documentation -%}
|
|
7
|
+
{{ paragraph.content }}
|
|
8
|
+
|
|
9
|
+
{% endfor -%}
|
|
10
|
+
{%- endcapture -%}
|
|
11
|
+
{%- assign docs = docs | strip -%}
|
|
12
|
+
{%- capture used_by_list -%}
|
|
13
|
+
{% for used_by in used_by_items -%}
|
|
14
|
+
{%- capture used_by_kind -%}{% if used_by.element? %}element{% elsif used_by.attribute_group? %}attribute_group{% else %}type{% endif %}{%- endcapture %}
|
|
15
|
+
* {{ used_by.name }}{% render "xsd_ref", name: used_by.name, kind: used_by_kind, schema: schema %}
|
|
16
|
+
{% endfor -%}
|
|
17
|
+
{%- endcapture -%}
|
|
18
|
+
{%- assign used_by_list = used_by_list | strip -%}
|
|
19
|
+
{%- capture attribute_list -%}
|
|
20
|
+
{% for attribute in item_attributes -%}
|
|
21
|
+
{% render "attribute", attribute: attribute %}
|
|
22
|
+
|
|
23
|
+
{% endfor -%}
|
|
24
|
+
{%- endcapture -%}
|
|
25
|
+
{%- assign attribute_list = attribute_list | strip -%}
|
|
26
|
+
{%- capture content_model_list -%}
|
|
27
|
+
{% for child in content_model_items -%}
|
|
28
|
+
{% render "child_elements", child: child %}
|
|
29
|
+
{% endfor -%}
|
|
30
|
+
{%- endcapture -%}
|
|
31
|
+
{%- assign content_model_list = content_model_list | strip -%}
|
|
32
|
+
{%- capture example_attributes -%}
|
|
33
|
+
{% for attr in item_attributes -%}
|
|
34
|
+
{% render "xml_example_attribute", attr: attr -%}
|
|
35
|
+
{% endfor -%}
|
|
36
|
+
{%- endcapture -%}
|
|
37
|
+
{%- capture example_children -%}
|
|
38
|
+
{% if item_complex_type.mixed -%}
|
|
39
|
+
<!-- mixed content -->
|
|
40
|
+
{% endif -%}
|
|
41
|
+
{% for child in content_model_items -%}
|
|
42
|
+
{% render "xml_example_child", child: child, indent: " " -%}
|
|
43
|
+
{% endfor -%}
|
|
44
|
+
{%- endcapture -%}
|
|
45
|
+
|
|
46
|
+
[[xsd_{{ item.name }}]]
|
|
47
|
+
=== `<{{ item.name }}>`
|
|
48
|
+
|
|
49
|
+
==== General
|
|
50
|
+
|
|
51
|
+
{% if docs != "" %}
|
|
52
|
+
{{ docs }}
|
|
53
|
+
{% else %}
|
|
54
|
+
No documentation supplied.
|
|
55
|
+
{% endif %}
|
|
56
|
+
|
|
57
|
+
{% if used_by_items.size > 0 %}
|
|
58
|
+
This element is used by:
|
|
59
|
+
|
|
60
|
+
{{ used_by_list }}
|
|
61
|
+
{% endif %}
|
|
62
|
+
|
|
63
|
+
{% unless diagrams == false %}
|
|
64
|
+
==== Structure diagram
|
|
65
|
+
|
|
66
|
+
{% render "diagram", item: item, attributes: item_attributes, children: content_model_items, schema: schema %}
|
|
67
|
+
{% endunless %}
|
|
68
|
+
|
|
69
|
+
==== Attributes
|
|
70
|
+
|
|
71
|
+
{% if item_attributes.size > 0 %}
|
|
72
|
+
{{ attribute_list }}
|
|
73
|
+
{% else %}
|
|
74
|
+
No attributes defined.
|
|
75
|
+
{% endif %}
|
|
76
|
+
|
|
77
|
+
==== Content model
|
|
78
|
+
|
|
79
|
+
{% if item.type %}
|
|
80
|
+
This element uses the `{{ item.type }}` type{% render "xsd_ref", name: item.type, kind: "type", schema: schema %}.
|
|
81
|
+
|
|
82
|
+
{% endif %}
|
|
83
|
+
{% if item_complex_type.mixed %}
|
|
84
|
+
This element allows mixed content.
|
|
85
|
+
|
|
86
|
+
{% endif %}
|
|
87
|
+
{% if content_model_list != "" %}
|
|
88
|
+
{{ content_model_list }}
|
|
89
|
+
{% else %}
|
|
90
|
+
No child elements defined.
|
|
91
|
+
{% endif %}
|
|
92
|
+
|
|
93
|
+
[example]
|
|
94
|
+
.Illustrative usage of `<{{ item.name }}>`
|
|
95
|
+
====
|
|
96
|
+
[source,xml]
|
|
97
|
+
-----
|
|
98
|
+
<{{ item.name }}{{ example_attributes }}{% if example_children != "" %}>
|
|
99
|
+
{% if example_children != "" %}{{ example_children }}{% endif %}
|
|
100
|
+
</{{ item.name }}>
|
|
101
|
+
{% else %}/>
|
|
102
|
+
{% endif %}
|
|
103
|
+
-----
|
|
104
|
+
====
|
|
105
|
+
|
|
106
|
+
.XSD source of `<{{ item.name }}>`
|
|
107
|
+
[source,xml]
|
|
108
|
+
-----
|
|
109
|
+
{{ item.to_formatted_xml }}
|
|
110
|
+
-----
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
{%- assign attribute_name = attr.referenced_name | default: attr.name | default: attr.ref -%}
|
|
2
|
+
{%- assign attribute_value = attr.fixed | default: attr.default | default: attr.referenced_type | default: attr.type | default: "..." %} {{ attribute_name }}="{{ attribute_value }}"{%- comment -%}{%- endcomment -%}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{%- assign indent = indent | default: " " -%}
|
|
2
|
+
{%- assign child_indent = indent | append: " " -%}
|
|
3
|
+
{%- if child.annotation? or child.attribute? or child.attribute_group? -%}
|
|
4
|
+
{%- elsif child.sequence? -%}
|
|
5
|
+
{% for element in child.resolved_element_order -%}
|
|
6
|
+
{% render "xml_example_child", child: element, indent: indent %}
|
|
7
|
+
{% endfor -%}
|
|
8
|
+
{%- elsif child.choice? %}
|
|
9
|
+
{{ indent }}<!-- One of: -->
|
|
10
|
+
{% for element in child.resolved_element_order -%}
|
|
11
|
+
{% render "xml_example_child", child: element, indent: child_indent %}
|
|
12
|
+
{% endfor -%}
|
|
13
|
+
{%- elsif child.all? -%}
|
|
14
|
+
{% for element in child.resolved_element_order -%}
|
|
15
|
+
{% render "xml_example_child", child: element, indent: indent %}
|
|
16
|
+
{% endfor -%}
|
|
17
|
+
{%- elsif child.any? %}
|
|
18
|
+
{{ indent }}<!-- Any element from any namespace -->
|
|
19
|
+
{%- elsif child.element? -%}
|
|
20
|
+
{%- assign element_name = child.referenced_name | default: child.name | default: child.ref -%}
|
|
21
|
+
{{ indent }}<{{ element_name }}>...</{{ element_name }}>
|
|
22
|
+
{%- elsif child.child_elements.size > 0 -%}
|
|
23
|
+
{% for element in child.child_elements -%}
|
|
24
|
+
{% render "xml_example_child", child: element, indent: indent %}
|
|
25
|
+
{% endfor -%}
|
|
26
|
+
{%- endif -%}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Cross-reference to a global schema component, rendered as " (<<anchor>>)".
|
|
3
|
+
Renders nothing when `name` is not a global component of `kind`
|
|
4
|
+
("element", "type" or "attribute_group"). Namespace prefixes are ignored.
|
|
5
|
+
{%- endcomment -%}
|
|
6
|
+
{%- if name -%}
|
|
7
|
+
{%- assign ref_name = name | split: ":" | last -%}
|
|
8
|
+
{%- if kind == "type" -%}
|
|
9
|
+
{%- assign found = schema.complex_types_sorted_by_name | where: "name", ref_name | first -%}
|
|
10
|
+
{%- assign prefix = "xsd_type_" -%}
|
|
11
|
+
{%- elsif kind == "attribute_group" -%}
|
|
12
|
+
{%- assign found = schema.attribute_groups_sorted_by_name | where: "name", ref_name | first -%}
|
|
13
|
+
{%- assign prefix = "xsd_attribute_group_" -%}
|
|
14
|
+
{%- else -%}
|
|
15
|
+
{%- assign found = schema.elements_sorted_by_name | where: "name", ref_name | first -%}
|
|
16
|
+
{%- assign prefix = "xsd_" -%}
|
|
17
|
+
{%- endif -%}
|
|
18
|
+
{%- if found %} (<<{{ prefix }}{{ ref_name }}>>){% endif -%}
|
|
19
|
+
{%- endif -%}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Default lutaml_xsd template: renders every global element, complex type and
|
|
3
|
+
attribute group of the schema. Pass `diagrams: false` to omit the PlantUML
|
|
4
|
+
structure diagrams.
|
|
5
|
+
{%- endcomment -%}
|
|
6
|
+
{%- assign elements = schema.elements_sorted_by_name -%}
|
|
7
|
+
{%- assign complex_types = schema.complex_types_sorted_by_name -%}
|
|
8
|
+
{%- assign attribute_groups = schema.attribute_groups_sorted_by_name -%}
|
|
9
|
+
{%- if elements.size > 0 %}
|
|
10
|
+
== Elements
|
|
11
|
+
|
|
12
|
+
{% for item in elements %}
|
|
13
|
+
{% render "element", item: item, schema: schema, diagrams: diagrams %}
|
|
14
|
+
|
|
15
|
+
{% endfor %}
|
|
16
|
+
{%- endif %}
|
|
17
|
+
{%- if complex_types.size > 0 %}
|
|
18
|
+
== Complex types
|
|
19
|
+
|
|
20
|
+
{% for item in complex_types %}
|
|
21
|
+
{% render "complex_type", item: item, schema: schema, diagrams: diagrams %}
|
|
22
|
+
|
|
23
|
+
{% endfor %}
|
|
24
|
+
{%- endif %}
|
|
25
|
+
{%- if attribute_groups.size > 0 %}
|
|
26
|
+
== Attribute groups
|
|
27
|
+
|
|
28
|
+
{% for item in attribute_groups %}
|
|
29
|
+
{% render "attribute_group", item: item, schema: schema, diagrams: diagrams %}
|
|
30
|
+
|
|
31
|
+
{% endfor %}
|
|
32
|
+
{%- endif %}
|
|
@@ -12,8 +12,18 @@ module Metanorma
|
|
|
12
12
|
# Two syntaxes are supported:
|
|
13
13
|
# Block: [lutaml_xsd, path, context, options] .... ----
|
|
14
14
|
# Direct: lutaml_xsd::path[context, template, options]
|
|
15
|
+
#
|
|
16
|
+
# The bundled default templates (liquid_templates/xsd) are always on
|
|
17
|
+
# the template search path, after the document directory and any
|
|
18
|
+
# `include_path`, so documents can override single partials. The
|
|
19
|
+
# direct syntax renders the default `xsd_schema` template when no
|
|
20
|
+
# template is given.
|
|
15
21
|
class LutamlXsdPreprocessor < BasePreprocessor
|
|
16
22
|
CACHE = CacheStore.new
|
|
23
|
+
DEFAULT_TEMPLATES_DIR = File.expand_path(
|
|
24
|
+
"liquid_templates/xsd", __dir__
|
|
25
|
+
).freeze
|
|
26
|
+
DEFAULT_TEMPLATE = "xsd_schema"
|
|
17
27
|
XSD_PREPROCESSOR_REGEX = %r{
|
|
18
28
|
^ # Start of line
|
|
19
29
|
\[ # Opening bracket
|
|
@@ -31,9 +41,10 @@ module Metanorma
|
|
|
31
41
|
lutaml_xsd:: # Macro prefix
|
|
32
42
|
(?<file_path>[^\[]+?) # XSD file path
|
|
33
43
|
\[ # Opening bracket
|
|
34
|
-
(?<context_name>[
|
|
35
|
-
|
|
36
|
-
(?<template>[^,\]]
|
|
44
|
+
(?<context_name>[^,\]]+) # Context name
|
|
45
|
+
(?:,\s* # Comma separator
|
|
46
|
+
(?<template>[^,\]=]+?))? # Optional template file path
|
|
47
|
+
\s* # Optional whitespace
|
|
37
48
|
(?<options>,[^\]]+)? # Optional options
|
|
38
49
|
\] # Closing bracket
|
|
39
50
|
\s*$ # End of line
|
|
@@ -59,6 +70,12 @@ module Metanorma
|
|
|
59
70
|
end
|
|
60
71
|
end
|
|
61
72
|
|
|
73
|
+
def build_file_system(document, options)
|
|
74
|
+
file_system = super
|
|
75
|
+
file_system.roots.push(DEFAULT_TEMPLATES_DIR)
|
|
76
|
+
file_system
|
|
77
|
+
end
|
|
78
|
+
|
|
62
79
|
def index_type_name
|
|
63
80
|
"XSD"
|
|
64
81
|
end
|
|
@@ -94,17 +111,17 @@ module Metanorma
|
|
|
94
111
|
|
|
95
112
|
file_path = match[:file_path].strip
|
|
96
113
|
context_name = match[:context_name].strip
|
|
97
|
-
template_file = Utils.relative_file_path(document,
|
|
98
|
-
match[:template].strip)
|
|
99
114
|
options = match[:options] ? parse_options(match[:options].strip) : {}
|
|
100
115
|
|
|
101
116
|
schema = load_lutaml_file(document, file_path, options)
|
|
102
117
|
schema_drop = update_repo(options, schema).to_liquid
|
|
103
118
|
|
|
104
|
-
template_source =
|
|
119
|
+
template_source = direct_template_source(document, match[:template],
|
|
120
|
+
context_name)
|
|
105
121
|
tmpl = template([template_source])
|
|
106
122
|
tmpl.registers[:file_system] = build_file_system(document, options)
|
|
107
123
|
tmpl.assigns[context_name] = schema_drop
|
|
124
|
+
tmpl.assigns["diagrams"] = options["diagrams"] != "false"
|
|
108
125
|
|
|
109
126
|
tmpl.render.split("\n", -1)
|
|
110
127
|
rescue StandardError => e
|
|
@@ -115,6 +132,16 @@ module Metanorma
|
|
|
115
132
|
raise e
|
|
116
133
|
end
|
|
117
134
|
|
|
135
|
+
def direct_template_source(document, template_path, context_name)
|
|
136
|
+
if template_path.nil? || template_path.strip.empty?
|
|
137
|
+
return "{% render \"#{DEFAULT_TEMPLATE}\", " \
|
|
138
|
+
"schema: #{context_name}, diagrams: diagrams %}"
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
File.read(Utils.relative_file_path(document, template_path.strip),
|
|
142
|
+
encoding: "UTF-8")
|
|
143
|
+
end
|
|
144
|
+
|
|
118
145
|
def parse_xsd_file(full_path, location)
|
|
119
146
|
content = File.read(full_path, encoding: "UTF-8")
|
|
120
147
|
::Lutaml::Xml::Schema::Xsd.parse(content, location: location)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.73
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -495,6 +495,18 @@ files:
|
|
|
495
495
|
- lib/metanorma/plugin/lutaml/liquid_templates/_packages_entity_list_class.liquid
|
|
496
496
|
- lib/metanorma/plugin/lutaml/liquid_templates/_packages_entity_list_classes.liquid
|
|
497
497
|
- lib/metanorma/plugin/lutaml/liquid_templates/_packages_enum.liquid
|
|
498
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_attribute.liquid
|
|
499
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_attribute_group.liquid
|
|
500
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_attribute_value_constraints.liquid
|
|
501
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_child_elements.liquid
|
|
502
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_complex_type.liquid
|
|
503
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_diagram.liquid
|
|
504
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_diagram_children.liquid
|
|
505
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_element.liquid
|
|
506
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_xml_example_attribute.liquid
|
|
507
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_xml_example_child.liquid
|
|
508
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_xsd_ref.liquid
|
|
509
|
+
- lib/metanorma/plugin/lutaml/liquid_templates/xsd/_xsd_schema.liquid
|
|
498
510
|
- lib/metanorma/plugin/lutaml/lutaml_data_preprocessor.rb
|
|
499
511
|
- lib/metanorma/plugin/lutaml/lutaml_diagram_base.rb
|
|
500
512
|
- lib/metanorma/plugin/lutaml/lutaml_diagram_block.rb
|