Skip to content

Commit

Permalink
setup templating
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaria committed Feb 27, 2024
1 parent 4f817d9 commit 3d23332
Show file tree
Hide file tree
Showing 9 changed files with 2,965 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Template

on:
push:
branches-ignore:
- main

jobs:
template:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check if RDF files modified
id: rdfModified
uses: dorny/paths-filter@v3
with:
base: ${{ github.ref }}
list-files: csv
filters: |
modified:
- '**.ttl'
- '**.jsonld'
- '**.trig'
- '**.nt'
- '**.nq'
- '**.rdf'
- '**.trix'
- name: RDF syntax check
if: steps.rdfModified.outputs.modified == 'true'
uses: AtomGraph/[email protected]
- name: Check if config modified
id: configModified
uses: dorny/paths-filter@v3
with:
base: ${{ github.ref }}
list-files: csv
filters: |
modified:
- 'config/**'
- name: Template
if: steps.rdfModified.outputs.modified == 'true' || steps.configModified.outputs.modified == 'true'
run: |
docker run --rm \
--pull=always \
-v /$(pwd)/config:/config \
-v /$(pwd)/shapes:/shapes \
-v /$(pwd)/doc/_gen/:/doc/_gen ghcr.io/skemu/rdf-template:latest
- name: Configure Git User
run: |
git config user.email "[email protected]"
git config user.name "GitHub Actions"
- name: Commit and push
if: steps.rdfModified.outputs.modified == 'true' || steps.configModified.outputs.modified == 'true'
run: |
git status
git add doc/_gen/
git status
git diff --staged --quiet || git commit -F- <<EOF
Apply templates
The following RDF files were modified:
${{ steps.rdfModified.outputs.modified_files }}
The following config files were modified:
${{ steps.configModified.outputs.modified_files }}
EOF
git push
- name: No templateable changes
if: steps.rdfModified.outputs.modified == 'false' && steps.configModified.outputs.modified == 'false'
run: echo "No changes to template"
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# dcat3-ap-nl
dcat3-ap-nl

## Run templating locally

```shell
docker run --rm \
--pull=always \
-v /$(pwd)/config:/config \
-v /$(pwd)/shapes:/shapes \
-v /$(pwd)/doc/_gen/:/doc/_gen ghcr.io/skemu/rdf-template:latest
```
53 changes: 53 additions & 0 deletions config/rdftemplate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespacePrefixes:
adms: http://www.w3.org/ns/adms#
dcat: http://www.w3.org/ns/dcat#
foaf: http://xmlns.com/foaf/0.1/
dct: http://purl.org/dc/terms/
locn: http://www.w3.org/ns/locn#
odrl: http://www.w3.org/ns/odrl/2/
prov: http://www.w3.org/ns/prov#
r5r: http://data.europa.eu/r5r/
rdfs: http://www.w3.org/2000/01/rdf-schema#
sh: http://www.w3.org/ns/shacl#
skos: http://www.w3.org/2004/02/skos/core#
spdx: http://spdx.org/rdf/terms#
time: http://www.w3.org/2006/time#
vcard: http://www.w3.org/2006/vcard/ns#
xsd: http://www.w3.org/2001/XMLSchema#

dataSources:
nodeShapes:
resolver: sparql
location: sparql/nodeShapes.rq
source: /shapes/dcat-ap.ttl
resultFrame:
_key: targetClass
targetClass:
_value: targetClass
_prefix: true
propertyShapes:
_key: property
propertyName: propertyName
property: property
propertyPrefixed:
_value: property
_prefix: true
description: description
class: class
classPrefixed:
_value: class
_prefix: true
datatype: datatype
datatypePrefixed:
_value: datatype
_prefix: true
nodeKind: nodeKind
nodeKindPrefixed:
_value: nodeKind
_prefix: true
minCount: minCount
maxCount: maxCount

templates:
- templateLocation: klassen.md
outputLocation: /doc/_gen/
39 changes: 39 additions & 0 deletions config/sparql/nodeShapes.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
PREFIX sh: <http://www.w3.org/ns/shacl#>

SELECT ?targetClass ?propertyShape ?property ?propertyName ?description ?class ?datatype ?nodeKind ?minCount ?maxCount
WHERE {
?nodeShape a sh:NodeShape;
sh:targetClass ?targetClass .

OPTIONAL {
?nodeShape sh:property ?propertyShape .
?propertyShape
sh:name ?propName ;
sh:path ?property ;
sh:description ?description .

OPTIONAL {
?propertyShape sh:class ?class .
}
OPTIONAL {
?propertyShape sh:datatype ?datatype .
}
OPTIONAL {
?propertyShape sh:nodeKind ?nodeKind .
}
OPTIONAL {
?propertyShape sh:minCount ?min .
}
OPTIONAL {
?propertyShape sh:maxCount ?max .
}
}

BIND(STR(?propName) as ?propertyName)

BIND(STR(?min) as ?minCount)

BIND(STR(?max) as ?maxCount)
}
ORDER BY ?propertyName

51 changes: 51 additions & 0 deletions config/templates/klasse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% set targetClassLocalName = nodeShape.targetClass | split(':') | last %}
## {{ targetClassLocalName }} - {{ nodeShape.targetClass }}

{% if nodeShape.propertyShapes is not empty %}
<table>
<tr>
<th>Property</th>
<th>URI</th>
<th>Range</th>
<th>Card</th>
</tr>
{% endif %}
{% for propEntry in nodeShape.propertyShapes %}
{% set prop = propEntry.value %}
<tr>
<td><a href="{{ prop.property }}">{{ prop.propertyName }}</a></td>
<td>{{ prop.property }}</td>
<td>{% if prop.class != null %}<a href="{{ prop.class }}">{{ prop.classPrefixed }}</a>{% elseif prop.datatype != null %}<a href="{{ prop.datatype }}">{{ prop.datatypePrefixed }}</a>{% elseif prop.nodeKind != null %}<a href="{{ prop.nodeKind }}">prop.nodeKindPrefixed</a>{% endif %}</td>
<td>{{ prop.minCount | default("0") }}..{{ prop.maxCount | default("n") }}</td>
</tr>
{% endfor %}
</table>


<!-- <p data-include-format="markdown" data-include="/doc/klasse/{{ nodeShape.targetClass }}/prop/{{ prop.property }}.md"></p> -->
{% for propEntry in nodeShape.propertyShapes %}
{% set prop = propEntry.value %}
### {{ prop.propertyName }}

<table>
<tr>
<td><em>Property</em></td>
<td>{{ prop.propertyName }}</td>
</tr>
<tr>
<td><em>Cardinality</em></td>
<td>{{ prop.minCount | default("0") }}..{{ prop.maxCount | default("n") }}</td>
</tr>
<tr>
<td><em>URI</em></td>
<td><a href="{{ prop.property }}">{{ prop.propertyPrefixed }}</a></td>
</tr>
<tr>
<td><em>Range</em></td>
<td>{% if prop.class != null %}<a href="{{ prop.class }}">{{ prop.classPrefixed }}</a>{% elseif prop.datatype != null %}<a href="{{ prop.datatype }}">{{ prop.datatypePrefixed }}</a>{% elseif prop.nodeKind != null %}<a href="{{ prop.nodeKind }}">prop.nodeKindPrefixed</a>{% endif %}</td>
</tr>
</table>

{% endfor %}

<!-- property tabel -->
23 changes: 23 additions & 0 deletions config/templates/klassen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Klassen

{% set classOrder = [
"http://www.w3.org/ns/dcat#Dataset",
"http://www.w3.org/ns/dcat#Distribution",
"http://www.w3.org/ns/dcat#DataService",
"http://www.w3.org/ns/dcat#Catalog",
"http://www.w3.org/ns/dcat#CatalogRecord"
] %}
{# Process classes in classOrder #}
{% for class in classOrder %}
{% set nodeShape = nodeShapes[[class]] %}
{% if nodeShape is not empty %}
{% include "./klasse.md" %}
{% endif %}
{% endfor %}
{# Process all other classes not specified in classOrder #}
{% for nodeShapeEntry in nodeShapes %}
{% if not(classOrder contains nodeShapeEntry.key) %}
{% set nodeShape = nodeShapeEntry.value %}
{% include "./klasse.md" %}
{% endif %}
{% endfor %}
52 changes: 52 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://cdn.jsdelivr.net/gh/digitalbazaar/[email protected]/dist/main.js" class="remove"></script>
<script class="remove">
async function loadTurtle() {
//this is the function you call in 'preProcess', to load the highlighter
const worker = await new Promise(resolve => {
require(["core/worker"], ({ worker }) => resolve(worker));
});
const action = "highlight-load-lang";
const langURL =
"https://cdn.jsdelivr.net/gh/redmer/highlightjs-turtle/src/languages/turtle.js";
const propName = "hljsDefineTurtle"; // This funtion is defined in the highlighter being loaded
const lang = "turtle"; // this is the class you use to identify the language
worker.postMessage({ action, langURL, propName, lang });
return new Promise(resolve => {
worker.addEventListener("message", function listener({ data }) {
const { action: responseAction, lang: responseLang } = data;
if (responseAction === action && responseLang === lang) {
worker.removeEventListener("message", listener);
resolve();
}
});
});
}
</script>
<script src="https://tools.geostandaarden.nl/respec/config/geonovum-config.js" class="remove"></script>
<script src="js/config.js" class="remove"></script>
<script class="remove"> respecConfig = {...organisationConfig, ...respecConfig}</script>
<script>document.title = respecConfig.title</script>
<title>Default</title>
<link rel="shortcut icon" type="image/x-icon" href="https://tools.geostandaarden.nl/respec/style/logos/Geonovum.ico" />
<script src="https://gitdocumentatie.logius.nl/publicatie/respec/builds/respec-nlgov.js" class="remove" async></script>
</head>

<body>
<section id="abstract" data-include-format="markdown" data-include="doc/abstract.md"></section>
<section id="sotd"></section><!-- Wordt automatisch gevuld -->

<!-- TODO: voeg hier je eigen hoofdstukken toe -->
<section data-include-format="markdown" data-include="doc/_gen/klassen.md"></section>

<!-- <section id='conformance'></section> -->
<section id='tof'></section>
<section id="index"></section>
</body>

</html>
77 changes: 77 additions & 0 deletions js/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
let respecConfig = {
useLogo: true,
useLabel: true,
preProcess: [loadTurtle],
pluralize: true,
// title is verplicht! Neem hier de titel van het document op ----------------------
title: "DCAT-AP-NL Metadata Profiel",
//-- specStatus is verplicht! (activeer 1 van de volgende) --------------------------
specStatus: "wv", // Werkversie
// specStatus: "cv", // Consultatieversie
//specStatus: "vv", // Versie ter vaststelling
//specStatus: "def", // Vastgestelde versie
//specStatus: "basis", // Basis Document
//-- specType is verplicht bij alle andere dan BASIS ---------------------------------
//specType: "NO", // Norm
// specType: "ST", // Standaard
//specType: "IM", // Informatie Model
specType: "PR", // Praktijkrichtlijn
// specType: "HR", // HandReiking
//specType: "WA", // Werkafspraak
//specType: "BD", // Beheer Documentatie
//specType: "AL", // Algemeen document
//specType: "BP", // Best Practice
//-- pubDomain is verplicht! (komt in de URL) -------------------------------------
// pubDomain: "dk",
//-- license: voor de geldende gebruiksvoorwaarden. Default is cc-by.
//licence: "cc-by-nd", // bronvermelding, geen afgeleide werken (default)
//licence: "cc0", // Public Domain Dedication
licence: "cc-by", // Attribution, met bronvermelding
//-- shortName is verplicht! (komt in de URL: kies logische afkorting)--------------
shortName: "DCAT-AP-NL",
//-- publishDate is verplicht -------------------------------------------------------
//-- NB: in de werkversie uitzetten, want dan pakt Respec de pushdate ---------------
//publishDate: "2023-03-28",
//eventueel is het mogelijk een versienummer mee te geven, maar bij Geonovum werken we gewoonlijk alleen met datum als onderdeel van de permanente URI.
//publishVersion: "0.0.2",
//previousVersion: "0.0.1",
//-- Voor dit blok geldt: alleen als er eerdere versies zijn en altijd beiden aan/uit!
//previousPublishDate: "2014-05-01",
//previousMaturity: "CV",
//-- de namen van de Editor(s) / Redacteur(en)---------------------------------------
//-- vul in: per Editor: name:, company:, companyURL: -------------------------------
editors: [
{
name: "John Doe",
company: "Geonovum",
companyURL: "https://www.geonovum.nl",
}
],
//-- de namen van de auteur(s) ------------------------------------------------------
//-- vul in: per auteur: name:, company:, companyURL: -------------------------------
authors: [
{
name: "Jane Doe",
company: "Geonovum",
companyURL: "https://www.geonovum.nl",
}
],
//neem hier de URL van de github repository op waar het respec document in staat
github: "https://github.com/skemu/dcat-ap-test/",
// Create PDF and link to file in header (optional):
// alternateFormats: [
// {
// label: "pdf",
// uri: "template.pdf",
// },
// ],
localBiblio: {
"ISO11179": {
date: "2023-01",
title: "ISO/IEC 11179-3",
href: "https://www.iso.org/standard/78915.html",
publisher: "International Organization for Standardization (ISO)",
status: "Published",
},
}
};
Loading

0 comments on commit 3d23332

Please sign in to comment.