Skip to content

Commit

Permalink
Introduce a new generateAnchorTag method inside oslo-core
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofVDB1 committed Nov 4, 2024
1 parent 43d0ce7 commit df090b0
Show file tree
Hide file tree
Showing 15 changed files with 720 additions and 573 deletions.
2 changes: 1 addition & 1 deletion packages/oslo-converter-stakeholders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"url": "https://github.com/Informatievlaanderen/OSLO-UML-Transformer/issues"
},
"dependencies": {
"@oslo-flanders/core": "^0.0.16-alpha.0",
"@oslo-flanders/core": "^0.0.17-alpha.0",
"csv-parse": "^5.3.6",
"inversify": "^6.0.1",
"reflect-metadata": "^0.1.13",
Expand Down
2 changes: 1 addition & 1 deletion packages/oslo-converter-uml-ea/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"jest-runner-groups": "^2.2.0"
},
"dependencies": {
"@oslo-flanders/core": "^0.0.16-alpha.0",
"@oslo-flanders/core": "^0.0.17-alpha.0",
"@oslo-flanders/ea-uml-extractor": "^0.0.27-alpha.0",
"@oslo-flanders/output-handlers": "^0.0.4-alpha.0",
"inversify": "^6.0.1",
Expand Down
8 changes: 8 additions & 0 deletions packages/oslo-core/lib/utils/anchorTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function generateAnchorTag(
entityLabel: string,
propLabel?: string,
): string {
const label = propLabel ? `${entityLabel}:${propLabel}` : entityLabel;
const anchorHref = `${encodeURIComponent(label.replace(' ', ''))}`;
return anchorHref;
}
2 changes: 1 addition & 1 deletion packages/oslo-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oslo-flanders/core",
"version": "0.0.16-alpha.0",
"version": "0.0.17-alpha.0",
"description": "Core interfaces and utilities",
"author": "Digitaal Vlaanderen <https://data.vlaanderen.be/id/organisatie/OVO002949>",
"homepage": "https://github.com/informatievlaanderen/OSLO-UML-Transformer/tree/main/packages/oslo-core#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/oslo-extractor-uml-ea/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"url": "https://github.com/Informatievlaanderen/OSLO-UML-Transformer/issues"
},
"dependencies": {
"@oslo-flanders/core": "^0.0.16-alpha.0",
"@oslo-flanders/core": "^0.0.17-alpha.0",
"alasql": "4.5.2",
"inversify": "^6.0.1",
"mdb-reader": "github:Informatievlaanderen/mdb-reader",
Expand Down
2 changes: 1 addition & 1 deletion packages/oslo-generator-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"url": "https://github.com/Informatievlaanderen/OSLO-UML-Transformer/issues"
},
"dependencies": {
"@oslo-flanders/core": "^0.0.16-alpha.0",
"@oslo-flanders/core": "^0.0.17-alpha.0",
"inversify": "^6.0.1",
"n3": "^1.17.2",
"rdf-data-factory": "^1.1.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/oslo-generator-html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ The service is executed from the CLI and expects the following parameters:
| `--templates` | path to local folder containing different templates that can be used for extending the root template | | |
| `--rootTemplate` | Use a different template other than the default ones (ap2.j2 and voc2.j2) | No | |

## Sidenote

For the application profile from OSLO we use a function to generate our anchor tags. The anchor tags are formed based on the available label of each entity and/or the available label of the property. If the label is not available, we use the URI of the entity or property. The final result gets encoded using the [`encodeURIComponent`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) function. The function can be found [here](../oslo-core/lib/utils/anchorTag.ts).

## Usage

```bash
Expand Down
11 changes: 2 additions & 9 deletions packages/oslo-generator-html/lib/HtmlGenerationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { inject, injectable } from 'inversify';
import * as nj from 'nunjucks';
import { HtmlGenerationServiceConfiguration } from './config/HtmlGenerationServiceConfiguration';
import { SpecificationType } from './utils/specificationTypeEnum';
import { generateAnchorTag } from '@oslo-flanders/core/lib/utils/anchorTag';

@injectable()
export class HtmlGenerationService implements IService {
Expand Down Expand Up @@ -39,7 +40,7 @@ export class HtmlGenerationService implements IService {

const env = nj.configure(this.dirs);
env.addFilter('replaceBaseURI', this.replaceBaseURI);
env.addGlobal('getAnchorTag', this.getAnchorTag);
env.addFilter('generateAnchorTag', generateAnchorTag);
}

public async run(): Promise<void> {
Expand Down Expand Up @@ -105,14 +106,6 @@ export class HtmlGenerationService implements IService {
await writeFile(this.configuration.output, html);
}

private getAnchorTag = (id: string, type: string) => {
let domain: string = '';
if (id && id?.includes('#')) {
domain = `${id?.split('#').pop()}`;
}
return domain;
};

private replaceBaseURI = (input: string, baseURI: string): string => {
return input.replace(new RegExp(baseURI, 'g'), '');
};
Expand Down
1,246 changes: 694 additions & 552 deletions packages/oslo-generator-html/lib/templates/ap2.j2

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/oslo-generator-html/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oslo-flanders/html-generator",
"version": "0.0.23-alpha.0",
"version": "0.0.24-alpha.0",
"description": "Generates an HTML file using an OSLO webuniversum config",
"author": "Digitaal Vlaanderen <https://data.vlaanderen.be/id/organisatie/OVO002949>",
"homepage": "https://github.com/informatievlaanderen/OSLO-UML-Transformer/tree/main/packages/oslo-generator-html#readme",
Expand Down Expand Up @@ -35,7 +35,7 @@
"url": "https://github.com/Informatievlaanderen/OSLO-UML-Transformer/issues"
},
"dependencies": {
"@oslo-flanders/core": "^0.0.16-alpha.0",
"@oslo-flanders/core": "^0.0.17-alpha.0",
"inversify": "^6.0.1",
"n3": "^1.16.4",
"nunjucks": "^3.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/oslo-generator-json-webuniversum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"url": "https://github.com/Informatievlaanderen/OSLO-UML-Transformer/issues"
},
"dependencies": {
"@oslo-flanders/core": "^0.0.16-alpha.0",
"@oslo-flanders/core": "^0.0.17-alpha.0",
"inversify": "^6.0.1",
"n3": "^1.17.2",
"rdf-data-factory": "^1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/oslo-generator-jsonld-context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@rdfjs/types": "^1.1.0"
},
"dependencies": {
"@oslo-flanders/core": "^0.0.16-alpha.0",
"@oslo-flanders/core": "^0.0.17-alpha.0",
"inversify": "^6.0.1",
"n3": "^1.16.2",
"rdf-data-factory": "^1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/oslo-generator-rdf-vocabulary/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@types/streamify-array": "^1.0.0"
},
"dependencies": {
"@oslo-flanders/core": "^0.0.16-alpha.0",
"@oslo-flanders/core": "^0.0.17-alpha.0",
"inversify": "^6.0.1",
"n3": "^1.16.2",
"rdf-data-factory": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/oslo-generator-respec-html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"url": "https://github.com/Informatievlaanderen/OSLO-UML-Transformer/issues"
},
"dependencies": {
"@oslo-flanders/core": "^0.0.16-alpha.0",
"@oslo-flanders/core": "^0.0.17-alpha.0",
"@oslo-flanders/html-respec-generator": "^0.0.11-alpha.0",
"@oslo-flanders/stakeholders-converter": "^0.0.12-alpha.0",
"inversify": "^6.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/oslo-generator-shacl-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"url": "https://github.com/Informatievlaanderen/OSLO-UML-Transformer/issues"
},
"dependencies": {
"@oslo-flanders/core": "^0.0.16-alpha.0",
"@oslo-flanders/core": "^0.0.17-alpha.0",
"i18n": "^0.15.1",
"inversify": "^6.0.1",
"n3": "^1.17.2",
Expand Down

0 comments on commit df090b0

Please sign in to comment.