Skip to content

Commit

Permalink
Update GML dictionary blog with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kwkwan authored and ronaldtse committed Aug 25, 2024
1 parent 0785245 commit 89f4ae3
Showing 1 changed file with 125 additions and 19 deletions.
144 changes: 125 additions & 19 deletions _posts/2024-08-21-render-gml-dictionary-ea-diagram.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ Two new plugins has been introduced into Metanorma. They are

== Rendering GML Dictionary by `lutaml_gml_dictionary`

`lutaml_gml_dictionary` allows to render a GML Dictionary by using Liquid Drop.
`lutaml_gml_dictionary` is used to render a GML Dictionary by using Liquid Drop
model `GmlDictionaryDrop`.

GmlDictionaryDrop has the following attributes:
`GmlDictionaryDrop` has the following attributes:

* name
* file_name
Expand All @@ -37,7 +38,61 @@ Each `dictionary_entry` has the following attributes:
* name
* description

.Example of using `lutaml_gml_dictionary`
For example, you want to render the GML Dictionary file named
`Building_class.xml`.

.GML Dictionary File `Building_class.xml`
[source,xml]
```
<?xml version="1.0" encoding="UTF-8"?>
<gml:Dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/SimpleDictionary/1.0.0/gmlSimpleDictionaryProfile.xsd" gml:id="cl_c9fa7a39-966f-4ee4-8102-91fb15ad2dd3">
<gml:name>Building_class</gml:name>
<gml:dictionaryEntry>
<gml:Definition gml:id="Building_class_1">
<gml:description>普通建物</gml:description>
<gml:name>3001</gml:name>
</gml:Definition>
</gml:dictionaryEntry>
<gml:dictionaryEntry>
<gml:Definition gml:id="Building_class_2">
<gml:description>堅ろう建物</gml:description>
<gml:name>3002</gml:name>
</gml:Definition>
</gml:dictionaryEntry>
<gml:dictionaryEntry>
<gml:Definition gml:id="Building_class_3">
<gml:description>普通無壁舎</gml:description>
<gml:name>3003</gml:name>
</gml:Definition>
</gml:dictionaryEntry>
<gml:dictionaryEntry>
<gml:Definition gml:id="Building_class_4">
<gml:description>堅ろう無壁舎</gml:description>
<gml:name>3004</gml:name>
</gml:Definition>
</gml:dictionaryEntry>
<gml:dictionaryEntry>
<gml:Definition gml:id="Building_class_5">
<gml:description>分類しない建物</gml:description>
<gml:name>3000</gml:name>
</gml:Definition>
</gml:dictionaryEntry>
</gml:Dictionary>
```

The `file_name` of the GML Dictionary is `Building_class.xml`. and the `name` of the
GML Dictionary is `Building_class`.

It has five dictionary entries.

The `name` and `description` of the first `dictionary_entry` are `3001` and
`普通建物`.

To render the GML Dictionary, you can use `lutaml_gml_dictionary` by specifying
the path of the GML Dictionary file and the liquid template.

.Render GML Dictionary by `lutaml_gml_dictionary`
[source,adoc]
-----
lutaml_gml_dictionary::/path/to/dictionary.xml[template="/path/to/template.liquid",context=dict]
Expand All @@ -46,35 +101,45 @@ lutaml_gml_dictionary::/path/to/dictionary.xml[template="/path/to/template.liqui
The command accepts the options listed below:

* `"/path/to/dictionary.xml` specifies the path of xml file of the
GML Dictionary.
GML Dictionary. (e.g. `/path/to/Building_class.xml`)

* `template="/path/to/template.liquid"` specifies the liquid template.
For example, you can create a liquid template and link it by `template`.

* `context=dict` define the context in the template.

.Example of the liquid template file:
[source,adoc]
.Liquid template file to show the GML Dictionary in a table
[source,liquid]
-----
[cols="3a,22a"]
|===
| Name | {{ dict.file_name }}
h| Code h| Description
{% for entry in dict.dictionary_entry %}
| {{ entry.name }} | {{ entry.description }}
{% endfor %}
|===
[.source]
<<source_link>>
-----

The liquid template will render the GML Dictionary as a table looks like the
following:

[cols="3a,22a"]
|===
| Name | Building_class.xml
h| Code h| Description
| 3001 | 普通建物
| 3002 | 堅ろう建物
| 3003 | 普通無壁舎
| 3004 | 堅ろう無壁舎
| 3000 | 分類しない建物
|===

In spite of specifying the path of the template, you can also define an inline
template within a block by
`[lutaml_gml_dictionary,"/path/to/dictionary.xml",context=dict]`.

.Example of using `lutaml_gml_dictionary` with an inline liquid template:
.Using `lutaml_gml_dictionary` with an inline liquid template:
[source,adoc]
-----
[lutaml_gml_dictionary,"/path/to/dictionary.xml",context=dict]
Expand All @@ -90,34 +155,75 @@ h| Help | Description
| {{ entry.name }} | {{ entry.description }}
{% endfor %}
|===
[.source]
<<source_link>>
--
-----

== Rendering a Enterprise Architect diagram from XMI by `lutaml_ea_diagram`

`lutaml_ea_diagram` allows to quickly render a EA diagram as an image file by
specifying the name of diagram.
specifying the `name` of diagram.

.Example of using `lutaml_ea_diagram`
.Using `lutaml_ea_diagram`
[source,adoc]
-----
lutaml_ea_diagram::[name="name_of_diagram",base_path="/path/to/xmi-images",format="png"]
-----

`lutaml_ea_diagram` will search the diagram with name `name_of_diagram` and then
render it as:
`lutaml_ea_diagram` will search the diagram with name `name_of_diagram` in the
EA XMI file to retrieve `xmi_id` and then render it as:

.Example of the rendered diagram
.The diagram will be rendered as an image
[source,adoc]
-----
[[figure-{{ diagram.xmi_id }}]]
.{{ diagram.name }}
image::{{ image_base_path }}/{{ diagram.xmi_id }}.{{ format | default: 'png' }}[]
-----

For example, you have a XMI file named `test.xmi` and you want to render the
EA diagram with name `Fig B1 Full model`.

.Diagram content in `test.xmi`
[source,xml]
-----
<diagrams>
<diagram xmi:id="EAID_0E029ABF_C35A_49e3_9EEA_FFD4F32780A8">
<properties name="Fig B1 Full model" type="Logical"/>
...
</diagram>
-----

You create a block to render the diagram by `lutaml_ea_diagram`:

.Render EA diagram by `lutaml_ea_diagram`
[source,adoc]
-----
= Document title
Author
:nodoc:
:novalid:
:no-isobib:
:imagesdir: assets
[lutaml_uml_datamodel_description,test.xmi]
--
--
lutaml_ea_diagram::[name="Fig B1 Full model",base_path="./xmi-images",format="png"]
-----

`lutaml_ea_diagram` will search the diagram with name `Fig B1 Full model` in
`test.xmi` to retrieve `EAID_0E029ABF_C35A_49e3_9EEA_FFD4F32780A8` and then
render it as:

[source,html]
-----
<figure id="_auto_id">
<name>Fig B1 Full model</name>
<image src="./xmi-images/EAID_0E029ABF_C35A_49e3_9EEA_FFD4F32780A8.png" mimetype="image/png" id="_auto_id" height="auto" width="auto"/>
</figure>
-----

== Conclusion

Questions or suggestions, please feel free to file an issue at
Expand Down

0 comments on commit 89f4ae3

Please sign in to comment.