Skip to content

Commit

Permalink
Update the plugins lutaml_ea_xmi and lutaml_klass_table to allow user…
Browse files Browse the repository at this point in the history
… to display guidance information
  • Loading branch information
kwkwan committed Oct 22, 2024
1 parent a7d8125 commit 23a5304
Show file tree
Hide file tree
Showing 23 changed files with 127,152 additions and 7 deletions.
14 changes: 13 additions & 1 deletion lib/metanorma/plugin/lutaml/lutaml_ea_xmi_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,24 @@ def lutaml_document_from_file_or_cache(document, file_path, yaml_config) # ruboc
Xmi::EaRoot.load_extension(ea_extension_full_path)
end

result_document = parse_result_document(full_path)
guidance = get_guidance_file(document, yaml_config["guidance"])
result_document = parse_result_document(full_path, guidance)
document.attributes["lutaml_xmi_cache"] ||= {}
document.attributes["lutaml_xmi_cache"][full_path] = result_document
result_document
end

def get_guidance_file(document, guidance_config)
guidance = nil

if guidance_config
guidance = Utils.relative_file_path(document,
guidance_config)
end

guidance
end

def parse_yaml_config_file(document, file_path)
return {} if file_path.nil?

Expand Down
3 changes: 2 additions & 1 deletion lib/metanorma/plugin/lutaml/lutaml_ea_xmi_preprocessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class LutamlEaXmiPreprocessor <

private

def parse_result_document(full_path)
def parse_result_document(full_path, guidance)
::Lutaml::XMI::Parsers::XML.serialize_xmi_to_liquid(
File.new(full_path, encoding: "UTF-8"),
guidance,
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ def process(parent, target, attrs)
)
end

if attrs["guidance"]
attrs["guidance"] = Utils.relative_file_path(
parent.document, attrs["guidance"]
)
end

klass = ::Lutaml::XMI::Parsers::XML.serialize_generalization_by_name(
xmi_path, attrs["name"]
xmi_path, attrs["name"], attrs["guidance"]
)

render(klass, parent, attrs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LutamlUmlDatamodelDescriptionPreprocessor <

private

def parse_result_document(full_path)
def parse_result_document(full_path, _guidance = nil)
::Lutaml::Parser.parse(File.new(full_path, encoding: "UTF-8")).first
end
end
Expand Down
5 changes: 2 additions & 3 deletions metanorma-plugin-lutaml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ Gem::Specification.new do |spec|
spec.add_dependency "coradoc", "~> 1.1.1"
spec.add_dependency "expressir", "~> 1.4.0"
spec.add_dependency "liquid"
spec.add_dependency "lutaml", ">= 0.9.14"
spec.add_dependency "ogc-gml"
spec.add_dependency "lutaml", ">= 0.9.18"
spec.add_dependency "ogc-gml", "1.0.0"
spec.add_dependency "relaton-cli"

spec.add_development_dependency "debug"
spec.add_development_dependency "equivalent-xml"
spec.add_development_dependency "metanorma-standoc"
spec.add_development_dependency "ogc-gml"
spec.add_development_dependency "rake", "~> 13"
spec.add_development_dependency "rspec", "~> 3.6"
spec.add_development_dependency "rspec-html-matchers"
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/lutaml/_bldg.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
== Test

My content
58 changes: 58 additions & 0 deletions spec/fixtures/lutaml/guidance/guidance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
classes:
- name: Building
attributes:
- name: gml:boundedBy
used: false
guidance: |
この属性は使用されていません。
- name: core:relativeToTerrain
used: false
guidance: |
この属性は使用されていません。
- name: core:relativeToWater
used: false
guidance: |
この属性は使用されていません。
- name: bldg:function
used: false
guidance: |
この属性は使用されていません。
- name: bldg:storeyHeightsAboveGround
used: false
guidance: |
この属性は使用されていません。
- name: bldg:storeyHeightsBelowGround
used: false
guidance: |
この属性は使用されていません。
- name: bldg:lod2MultiSurface
used: false
guidance: |
この関連役割は使用されていません。
- name: bldg:lod3MultiSurface
used: false
guidance: |
この関連役割は使用されていません。
- name: BuildingPart
attributes:
- name: gml:boundedBy
used: false
guidance: |
この属性は使用されていません。
- name: core:relativeToTerrain
used: false
guidance: |
この属性は使用されていません。
- name: core:relativeToWater
used: false
guidance: |
この属性は使用されていません。
- name: bldg:function
used: false
guidance: |
この関連役割は使用されていません。
- name: bldg:storeyHeightsAboveGround
used: false
guidance: |
この関連役割は使用されていません。
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ text }}

{% for diagram in package.diagrams %}
[[figure-{{ diagram.xmi_id }}]]
.{{ diagram.name }}
image::{{ image_base_path }}/{{ diagram.xmi_id }}.{{ format | default: 'png' }}[]

{% if diagram.definition %}
{{ diagram.definition | html2adoc }}
{% endif %}
{% endfor %}
83 changes: 83 additions & 0 deletions spec/fixtures/lutaml/liquid_templates_guidance/_klass_table.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{% assign root = klass.generalization %}

{%- capture upper_klass_name -%}
{{ root.general.upper_klass }}:{{ root.general.name }}
{%- endcapture -%}
{%- if upper_klass_name == ":" -%}
{%- assign upper_klass_name = "-" -%}
{%- endif -%}
{%- capture stereotype -%}<< {{ root.stereotype }} >>{%- endcapture -%}
{%- if stereotype == "<< >>" -%}
{%- assign stereotype = " " -%}
{%- endif -%}

[cols="1a,1a,2a,1a,1a"]
|===
| Definition of Type 4+| {{ root.definition }}
h| Upper Type 4+| {{ upper_klass_name }}
h| Stereotype 4+| {{ stereotype }}

5+h| Inherited Properties
h| Property Name h| Property Type and Multiplicity h| Definition h| Used h| Guidance
{% for attr in root.inherited_props %}
{%- if attr.has_association? == false -%}
{%- capture name_col -%}
{{ attr.name_ns }}:{{ attr.name }}
({{ attr.gen_name }})
{%- endcapture -%}
| {{ name_col | newline_to_br }}
| {{ attr.type }} [{{ attr.cardinality.min }}..{{ attr.cardinality.max }}]
| {{ attr.definition }}
| {{ attr.used? }}
| {{ attr.guidance }}
{%- endif -%}
{% endfor %}

5+h| Self-defined Properties
h| Property Name h| Property Type and Multiplicity h| Definition h| Used h| Guidance
{% for attr in root.owned_props %}
{%- if attr.has_association? == false -%}
{%- capture name_col -%}
{{ attr.name_ns }}:{{ attr.name }}
({{ attr.gen_name }})
{%- endcapture -%}
| {{ name_col | newline_to_br }}
| {{ attr.type }} [{{ attr.cardinality.min }}..{{ attr.cardinality.max }}]
| {{ attr.definition }}
| {{ attr.used? }}
| {{ attr.guidance }}
{%- endif -%}
{% endfor %}

5+h| Properties Inherited from Association
h| Property Name h| Property Type and Multiplicity h| Definition h| Used h| Guidance
{% for attr in root.inherited_assoc_props %}
{%- if attr.has_association? == true -%}
{%- capture name_col -%}
{{ attr.name_ns }}:{{ attr.name }}
({{ attr.gen_name }})
{%- endcapture -%}
| {{ name_col | newline_to_br }}
| {{ attr.type_ns }}:{{ attr.type }} [{{ attr.cardinality.min }}..{{ attr.cardinality.max }}]
| {{ attr.definition }}
| {{ attr.used? }}
| {{ attr.guidance }}
{%- endif -%}
{% endfor %}

5+h| Properties Defined in Association
h| Property Name h| Property Type and Multiplicity h| Definition h| Used h| Guidance
{% for attr in root.assoc_props %}
{%- if attr.has_association? == true -%}
{%- capture name_col -%}
{{ attr.name_ns }}:{{ attr.name }}
({{ attr.gen_name }})
{%- endcapture -%}
| {{ name_col | newline_to_br }}
| {{ attr.type_ns }}:{{ attr.type }} [{{ attr.cardinality.min }}..{{ attr.cardinality.max }}]
| {{ attr.definition }}
| {{ attr.used? }}
| {{ attr.guidance }}
{%- endif -%}
{% endfor %}
|===
Loading

0 comments on commit 23a5304

Please sign in to comment.