From 83b51153eae974aedff13b76bf35f61f2504215a Mon Sep 17 00:00:00 2001 From: samatstarion Date: Sat, 16 Nov 2024 17:13:22 +0100 Subject: [PATCH] [Add] IEnumerableHelper --- uml4net.HandleBars/IEnumerableHelper.cs | 53 +++ .../Generators/HandleBarsReportGenerator.cs | 2 + .../Templates/uml-to-html-docs.hbs | 385 +++++++++++------- 3 files changed, 286 insertions(+), 154 deletions(-) create mode 100644 uml4net.HandleBars/IEnumerableHelper.cs diff --git a/uml4net.HandleBars/IEnumerableHelper.cs b/uml4net.HandleBars/IEnumerableHelper.cs new file mode 100644 index 00000000..ea4d6faf --- /dev/null +++ b/uml4net.HandleBars/IEnumerableHelper.cs @@ -0,0 +1,53 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright 2019-2024 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, softwareUseCases +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace uml4net.HandleBars +{ + using System.Collections.Generic; + using System.Linq; + + using HandlebarsDotNet; + + /// + /// A helper that supports operations on IEnumerable + /// + public static class IEnumerableHelper + { + /// + /// Registers the + /// + /// + /// The context with which the helper needs to be registered + /// + public static void RegisterEnumerableHelper(this IHandlebars handlebars) + { + handlebars.RegisterHelper("IEnumerable.IsEmpty", (context, parameters) => + { + if (parameters[0] is IEnumerable list && !list.Any()) + { + return true; + } + + return false; + + }); + } + } +} \ No newline at end of file diff --git a/uml4net.Reporting/Generators/HandleBarsReportGenerator.cs b/uml4net.Reporting/Generators/HandleBarsReportGenerator.cs index abe963a1..5a16a05d 100644 --- a/uml4net.Reporting/Generators/HandleBarsReportGenerator.cs +++ b/uml4net.Reporting/Generators/HandleBarsReportGenerator.cs @@ -35,6 +35,7 @@ namespace uml4net.Reporting.Generators using uml4net.Reporting.Payload; using uml4net.Reporting.Resources; using uml4net.xmi.Readers; + using uml4net.HandleBars; /// /// Abstract super class from which all generators @@ -75,6 +76,7 @@ protected HandleBarsReportGenerator(ILoggerFactory loggerFactory = null) : base( protected virtual void RegisterHelpers() { uml4net.HandleBars.StringHelper.RegisterStringHelper(this.Handlebars); + uml4net.HandleBars.IEnumerableHelper.RegisterEnumerableHelper(this.Handlebars); uml4net.HandleBars.PropertyHelper.RegisterStructuralFeatureHelper(this.Handlebars); uml4net.HandleBars.GeneralizationHelper.RegisterGeneralizationHelper(this.Handlebars); uml4net.HandleBars.DocumentationHelper.RegisteredDocumentationHelper(this.Handlebars); diff --git a/uml4net.Reporting/Templates/uml-to-html-docs.hbs b/uml4net.Reporting/Templates/uml-to-html-docs.hbs index f3a8eb86..18457fa3 100644 --- a/uml4net.Reporting/Templates/uml-to-html-docs.hbs +++ b/uml4net.Reporting/Templates/uml-to-html-docs.hbs @@ -265,168 +265,245 @@

1. Enumeration Types

- {{#each this.Enumerations as | enumeration |}} -

{{enumeration.Name}}

-

Definition

- {{ #RawDocumentation enumeration }} -

Enumeration Literals

- - - - - - - - - {{#each enumeration.OwnedLiteral as | enumerationLiteral |}} - - - - - {{/each}} - -
NameDescription
{{enumerationLiteral.Name}} - {{ #RawDocumentation enumerationLiteral }} -
- {{/each}} + {{ #if (IEnumerable.IsEmpty this.Enumerations) }} +

No Enumerations have been found in the UML model

+ {{ else }} + {{#each this.Enumerations as | enumeration |}} +

{{enumeration.Name}} [Enumeration]

+

Features

+ + + + + + + + + + + + + + + + + +
NameDescription
Fully Qualified Name {{ enumeration.QualifiedName }}
Definition{{ #RawDocumentation enumeration }}
+

Enumeration Literals

+ + + + + + + + + {{#each enumeration.OwnedLiteral as | enumerationLiteral |}} + + + + + {{/each}} + +
NameDescription
{{enumerationLiteral.Name}} + {{ #RawDocumentation enumerationLiteral }} +
+ {{/each}} + {{ /if }}

2. Primitive Types

- {{#each this.PrimitiveTypes as | primitiveType |}} -

{{primitiveType.Name}}

-

Definition

- {{ #RawDocumentation primitiveType }} - {{/each}} + {{ #if (IEnumerable.IsEmpty this.PrimitiveTypes) }} +

No Primitive Types have been found in the UML model

+ {{ else }} + {{#each this.PrimitiveTypes as | primitiveType |}} +

{{primitiveType.Name}} [PrimitiveType]

+

Features

+ + + + + + + + + + + + + + + + + +
NameDescription
Fully Qualified Name {{ primitiveType.QualifiedName }}
Definition{{ #RawDocumentation primitiveType }}
+ {{/each}} + {{ /if }}

3. Data Types

- {{#each this.DataTypes as | datatype |}} -

{{datatype.Name}}

-

Definition

- {{ #RawDocumentation datatype }} - {{/each}} + {{ #if (IEnumerable.IsEmpty this.DataTypes) }} +

No Data Types (other than Enumerations and Primitive Types) have been found in the UML model

+ {{ else }} + {{#each this.DataTypes as | datatype |}} +

{{datatype.Name}} [DataType]

+

Features

+ + + + + + + + + + + + + + + + + +
NameDescription
Fully Qualified Name {{ primitiveType.QualifiedName }}
Definition{{ #RawDocumentation primitiveType }}
+ {{/each}} + {{ /if }}

4. Classes

- {{#each this.Classes as | class |}} - -

{{class.Name}}

-

Definition

- {{ #RawDocumentation class }} -

Features

- - - - - - - - - - - - - - - - - - - - - -
NameDescription
Is Abstract {{#if class.IsAbstract}} TRUE {{else}} FALSE {{/if}}
Generalizations - {{#each class.SuperClass as | superClass |}} - {{superClass.Name}} - {{/each}} -
Specializations TBD - -
-

Properties

- - - - - - - - - - - - {{#each this.QueryAllProperties as | property |}} - - - - - - - - {{/each}} - -
NameTypeDefaultDescriptionInheritance
{{ property.Name }} - {{Property.QueryTypeName property}} [{{ property.Lower }}..{{ property.Upper }}] - {{#if property.IsDerived }} {derived} {{/if}} - {{#if (Property.QueryIsContainment property) }} {composite} {{/if}} - {{ property.DefaultValueLiteral }}{{ #RawDocumentation property }}{{property.Owner.Name}}
- {{/each}} - - + {{ #if (IEnumerable.IsEmpty this.Classes) }} +

No Classes have been found in the UML model

+ {{ else }} + {{#each this.Classes as | class |}} +

{{class.Name}} [Class]

+

Features

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameDescription
Fully Qualified Name {{ class.QualifiedName }}
Definition{{ #RawDocumentation class }}
Is Abstract {{#if class.IsAbstract}} TRUE {{else}} FALSE {{/if}}
Generalizations + {{#each class.SuperClass as | superClass |}} + {{superClass.Name}} + {{/each}} +
Specializations TBD + +
+

Properties

+ + + + + + + + + + + + {{#each this.QueryAllProperties as | property |}} + + + + + + + + {{/each}} + +
NameTypeDefaultDescriptionInheritance
{{ property.Name }} + {{Property.QueryTypeName property}} [{{ property.Lower }}..{{ property.Upper }}] + {{#if property.IsDerived }} {derived} {{/if}} + {{#if (Property.QueryIsContainment property) }} {composite} {{/if}} + {{ property.DefaultValueLiteral }}{{ #RawDocumentation property }}{{property.Owner.Name}}
+ {{/each}} + {{ /if }}

4. Interfaces

- {{#each this.Interfaces as | interface |}} - -

{{interface.Name}}

-

Definition

- {{ #RawDocumentation interface }} -

Features

- - - - - - - - - - - - - -
NameDescription
Generalizations - {{#each interface.ESuperTypes as | superInterface |}} - {{superInterface.Name}} - {{/each}} -
-

Properties

- - - - - - - - - - - - {{#each this.QueryAllProperties as | property |}} - - - - - - - - {{/each}} - -
NameTypeDefaultDescriptionInheritance
{{ property.Name }} - {{Property.QueryTypeName property}} [{{ property.Lower }}..{{ property.Upper }}] - {{#if property.IsDerived }} {derived} {{/if}} - {{#if (Property.QueryIsContainment property) }} {composite} {{/if}} - {{ property.DefaultValueLiteral }}{{ #RawDocumentation property }}{{property.Owner.Name}}
- {{/each}} + {{ #if (IEnumerable.IsEmpty this.Interfaces) }} +

No Interfaces have been found in the UML model

+ {{ else }} + {{#each this.Interfaces as | interface |}} +

{{interface.Name}} [Interface]

+

Definition

+ {{ #RawDocumentation interface }} +

Features

+ + + + + + + + + + + + + + + + + +
NameDescription
Fully Qualified Name {{ interface.QualifiedName }}
Generalizations + {{#each interface.ESuperTypes as | superInterface |}} + {{superInterface.Name}} + {{/each}} +
+

Properties

+ + + + + + + + + + + + {{#each this.QueryAllProperties as | property |}} + + + + + + + + {{/each}} + +
NameTypeDefaultDescriptionInheritance
{{ property.Name }} + {{Property.QueryTypeName property}} [{{ property.Lower }}..{{ property.Upper }}] + {{#if property.IsDerived }} {derived} {{/if}} + {{#if (Property.QueryIsContainment property) }} {composite} {{/if}} + {{ property.DefaultValueLiteral }}{{ #RawDocumentation property }}{{property.Owner.Name}}
+ {{/each}} + {{ /if }}