Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
source "https://rubygems.org"

gem "lutaml",
github: "lutaml/lutaml",
branch: "update/xsd_support_metanorma_plugin"
gem "lutaml-model",
github: "lutaml/lutaml-model",
branch: "update/liquid_element_order"
gem "metanorma"
gem "metanorma-cli"
# gem "metanorma-nist", source: "https://rubygems.pkg.github.com/metanorma"
gem "metanorma-plugin-lutaml",
github: "metanorma/metanorma-plugin-lutaml",
branch: "feature/unitsml_liquid_filters"
gem "metanorma-standoc",
github: "metanorma/metanorma-standoc",
branch: "update/lutaml_xsd_preprocessor_support"
17 changes: 17 additions & 0 deletions sources/unitsml_xsd_docs/document.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[#top]
= XSD Templates

[lutaml_xsd, ../../unitsdb/unitsml-v1.0-csd04.xsd, schema]
----
== Elements

include::sources/_elements.adoc[]

== Complex Types

include::sources/_complex_type.adoc[]

== Attribute Groups

include::sources/_attribute_groups.adoc[]
----
44 changes: 44 additions & 0 deletions sources/unitsml_xsd_docs/sources/_attribute_groups.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% for attribute_group in schema.attribute_group %}

[#attribute_group_{{attribute_group.name}}]

=== Attribute Group: *{{ attribute_group.name }}*

==== **Used By** {{ schema | used_by: attribute_group | join: ", " }}

==== Description pass:[{{ attribute_group.annotation.documentation.first.content }}]

.XML Instance Representation
[source, xml]
-----
{%- for attr in attribute_group.attribute %}
{{ attr.name }}="{{ attr | attr_type: }}" [{{ attr | min_max_arg: }}]
{%- endfor %}
-----

.Schema Component Representation
[source, xml]
-----
<xsd:attributeGroup name="{{attribute_group.name}}">
{%- assign element_order = attribute_group | resolved_element_order: %}
{%- for element in element_order %}
{%- assign attribute_drop = element | class_name_end_with: "::AttributeDrop" -%}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want any "Ruby class names" in Liquid... The attribute variable here should already be the Drop object. Every XSD element should be here as a Drop object.

{%- assign attribute_group_drop = element | class_name_end_with: "::AttributeGroupDrop" -%}
{%- assign simple_type = element.simple_type %}
{%- if attribute_drop %}
<xsd:attribute{{ element | attributes_xml_representation_for: }}{% unless simple_type %}/{% endunless %}>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to handcraft XML elements here? We actually want the source directly, which should be provided by the drop (add a "source" method?).

You can see how Expressir stores the source of the parsed content and provides it through the method.

{%- if simple_type %}
{%- render "sources/simple_type", simple_type: simple_type, element: element, indent: " " %}
</xsd:attribute>
{%- endif %}
{%- endif %}
{%- if attribute_group_drop %}
<xsd:attributeGroup{{ attribute_group_drop | attributes_xml_representation_for: }}/>
{%- endif %}
{%- endfor %}
</xsd:attributeGroup>
-----

---

{% endfor %}
75 changes: 75 additions & 0 deletions sources/unitsml_xsd_docs/sources/_complex_type.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{% for complex_type in schema.complex_type %}

[#complex_type_{{complex_type.name}}]

=== Complex Type: *{{ complex_type.name }}*

==== Used By {{ schema | used_by: complex_type | join: ", " }}

Description pass:[{{ complex_type.annotation.documentation.first.content }}]

{% assign complex_type_element_order = complex_type | resolved_element_order: %}
{% assign complex_type_attributes = schema | attributes: complex_type -%}
{% assign elements = schema | child_elements: complex_type %}
.XML Instance Representation
[source, xml]
-----
<...{{ complex_type_attributes | xml_representations: schema }}
{%- if elements.size > 0 -%}>
{%- for child in elements -%}
{% assign element_name = child.ref || child.name %}
{%- if element_name %}
<{{ element_name }}> ... </{{ element_name }}> {{ child | cardinality_representation: }}
{%- else %}
{{ child }}
{%- endif %}
{%- endfor %}
</...>
{%- else -%}
/>
{% endif %}
-----

.Schema Component Representation
[source, xml]
-----
<xsd:complexType name="{{ complex_type.name }}">
{%- for object in complex_type_element_order %}
{%- assign sequence_drop = object | class_name_end_with: "::SequenceDrop" -%}
{%- assign attribute_drop = object | class_name_end_with: "::AttributeDrop" -%}
{%- assign simple_content_drop = object | class_name_end_with: "::SimpleContentDrop" -%}
{%- assign attribute_group_drop = object | class_name_end_with: "::AttributeGroupDrop" -%}
{%- if sequence_drop %}
<xsd:sequence{{ object | attributes_xml_representation_for: }}>
{%- for element in object.element %}
<xsd:element{{ element | attributes_xml_representation_for: }}/>
{%- endfor %}
{%- for any in object.any %}
<xsd:any{{ any | attributes_xml_representation_for: }}/>
{%- endfor %}
</xsd:sequence>
{%- endif %}
{%- if attribute_drop %}
<xsd:attribute{{ object | attributes_xml_representation_for: }}{% unless object.simple_type %}/{% endunless %}>
{%- if object.simple_type %}
{%- render "sources/simple_type", simple_type: object.simple_type, indent: " " %}
</xsd:attribute>
{%- endif %}
{%- endif %}
{%- if attribute_group_drop %}
<xsd:attributeGroup{{ object | attributes_xml_representation_for: }}/>
{%- endif %}
{%- if simple_content_drop %}{% assign simple_content_children = object | simple_content_children: %}
<xsd:simpleContent>
{%- for child in simple_content_children %}
{{ child }}
{%- endfor %}
</xsd:simpleContent>
{%- endif %}
{%- endfor %}
</xsd:complexType>
-----

---

{% endfor %}
40 changes: 40 additions & 0 deletions sources/unitsml_xsd_docs/sources/_elements.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% for element in schema.element %}

[#element_{{element.name}}]
=== Element: *{{ element.name }}*

==== Type <<complex_type_{{element.type}}, {{ element.type }}>>
{% assign used_by_elements = schema | used_by: element %}
{% if used_by_elements.size > 0 %}==== *Used By* {{ used_by_elements | join: ", " }}{% endif %}

==== Description *pass:[{{ element.annotation.documentation.first.content }}]*
{% assign element_attributes = schema | attributes: element %}
{% assign element_children = schema | child_elements: element %}

.XML Instance Representation
[source, xml]
-----
<{{element.name}}{{ element_attributes | xml_representations: schema }}
{%- if element_children.size > 0 -%}>
{%- for child in element_children -%}
{% assign element_name = child.ref || child.name %}
{%- if element_name %}
<{{element_name}}> ... </{{ element_name }}> {{ child | cardinality_representation: }}
{%- else %}
{{ child }}
{%- endif %}
{%- endfor %}
</{{element.name}}>
{%- else -%}
/>
{% endif %}
-----

.Schema Component Representation
[source, xml]
-----
<xsd:element name="{{element.name}}" type="{{element.type}}" />
-----
---

{% endfor %}
19 changes: 19 additions & 0 deletions sources/unitsml_xsd_docs/sources/_simple_type.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{%- assign simple_type_indent = indent | append: " " %}
{%- assign extended_indent = simple_type_indent | append: " " %}
{{indent}}<xsd:simpleType>
{%- if simple_type.restriction %}
{%- assign restriction = simple_type.restriction %}
{{simple_type_indent}}<xsd:restriction base="{{ restriction.base }}">
{%- for enumeration in restriction.enumeration %}
{{extended_indent}}<xsd:enumeration value="{{ enumeration.value }}"/>
{%- endfor %}
{{simple_type_indent}}</xsd:restriction>
{%- elsif simple_type.union %}
{%- assign union = simple_type.union %}
{{simple_type_indent}}<xsd:union memberTypes="{{ union.member_types }}"{% unless union.simple_type %}/{% endunless %}>
{%- for union_simple_type in union.simple_type %}
{%- render "sources/simple_type", simple_type: union_simple_type, indent: extended_indent %}
{{simple_type_indent}}</xsd:union>
{%- endfor %}
{%- endif %}
{{indent}}</xsd:simpleType>