@lde/docgen 0.6.12 → 0.6.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +114 -2
  2. package/package.json +8 -7
package/README.md CHANGED
@@ -1,3 +1,115 @@
1
- # docgen
1
+ # @lde/docgen
2
2
 
3
- Generate documentation RDF such as SHACL shapes.
3
+ Generate human-readable documentation from [SHACL](https://www.w3.org/TR/shacl/) shapes using [Liquid](https://liquidjs.com) templates.
4
+
5
+ - **Template-driven:** you control the output format (Markdown, HTML, plain text) with Liquid templates.
6
+ - **Standards-based:** reads any RDF serialization (Turtle, JSON-LD, N-Triples, etc.) via [rdf-dereference](https://github.com/rubensworks/rdf-dereference.js).
7
+ - **Structured output:** SHACL shapes are framed into a clean JSON-LD tree before rendering, so templates work with predictable, nested objects.
8
+
9
+ ## How it works
10
+
11
+ ```mermaid
12
+ graph LR
13
+ A[SHACL file] --> B[Parse to JSON-LD] --> C[Frame by NodeShape] --> D[Render with Liquid template] --> E[Output]
14
+ ```
15
+
16
+ 1. **Parse** — the SHACL file is dereferenced and converted to JSON-LD.
17
+ 2. **Frame** — the JSON-LD is [framed](https://www.w3.org/TR/json-ld11-framing/) using a JSON-LD Frame that selects `sh:NodeShape` resources and nests their property shapes. A default frame is included; you can supply your own.
18
+ 3. **Render** — the framed data is passed to a Liquid template as `nodeShapes`, an array of node shape objects.
19
+
20
+ ## CLI usage
21
+
22
+ ```sh
23
+ npx @lde/docgen@latest from-shacl <shacl-file> <template-file> [options]
24
+ ```
25
+
26
+ ### Arguments
27
+
28
+ | Argument | Description |
29
+ | ----------------- | --------------------------------------------------- |
30
+ | `<shacl-file>` | Path to a SHACL shapes file (any RDF serialization) |
31
+ | `<template-file>` | Path to a Liquid template file |
32
+
33
+ ### Options
34
+
35
+ | Option | Description | Default |
36
+ | -------------------- | ---------------------------- | ------------------------------------ |
37
+ | `-f, --frame <file>` | Path to a JSON-LD Frame file | Built-in `frames/shacl.frame.jsonld` |
38
+
39
+ ### Example
40
+
41
+ Given a SHACL file `shapes.ttl`:
42
+
43
+ ```turtle
44
+ @prefix dcat: <http://www.w3.org/ns/dcat#> .
45
+ @prefix dct: <http://purl.org/dc/terms/> .
46
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
47
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
48
+
49
+ [] a sh:NodeShape ;
50
+ sh:targetClass dcat:Dataset ;
51
+ sh:property [
52
+ sh:path dct:title ;
53
+ sh:minCount 1 ;
54
+ ] ,
55
+ [
56
+ sh:path dct:description ;
57
+ sh:minCount 1 ;
58
+ sh:datatype xsd:string ;
59
+ sh:description "A description of the dataset"@en ;
60
+ ] .
61
+ ```
62
+
63
+ And a template `spec.md.liquid`:
64
+
65
+ ```liquid
66
+ {% for nodeShape in nodeShapes -%}
67
+ ## {{ nodeShape.targetClass }}
68
+
69
+ | Property | Required | Type | Description |
70
+ |---|---|---|---|
71
+ {% assign mergedProperties = nodeShape.property | mergePropertiesByPath -%}
72
+ {% for property in mergedProperties -%}
73
+ | `{{ property.path }}` | {{ property.minCount | default: "no" }} | {{ property.datatype }} | {{ property.description | lang: "en" }} |
74
+ {% endfor %}
75
+ {% endfor %}
76
+ ```
77
+
78
+ Run:
79
+
80
+ ```sh
81
+ npx @lde/docgen@latest from-shacl shapes.ttl spec.md.liquid > spec.md
82
+ ```
83
+
84
+ ## Programmatic usage
85
+
86
+ ```typescript
87
+ import { generateDocumentation } from '@lde/docgen';
88
+
89
+ const output = await generateDocumentation(
90
+ 'shapes.ttl',
91
+ 'spec.md.liquid',
92
+ 'frames/shacl.frame.jsonld', // optional: path to custom frame
93
+ );
94
+ ```
95
+
96
+ ## Template data
97
+
98
+ The Liquid template receives a `nodeShapes` array. Each node shape object has the structure produced by the JSON-LD Frame — keys are SHACL term names (`targetClass`, `property`, `name`, etc.) with IRIs as values.
99
+
100
+ Property shapes with the same `sh:path` are common in SHACL (e.g. one for cardinality, another for datatype). The `mergePropertiesByPath` filter combines them into a single object per path.
101
+
102
+ ### Custom filters
103
+
104
+ | Filter | Description | Example |
105
+ | ----------------------- | --------------------------------------------------- | ------------------------------------------------------------------- |
106
+ | `lang` | Select a value by language tag | `{{ property.description \| lang: "en" }}` |
107
+ | `mergePropertiesByPath` | Merge property shapes that share the same `sh:path` | `{% assign merged = nodeShape.property \| mergePropertiesByPath %}` |
108
+
109
+ ## Custom frames
110
+
111
+ The default frame selects all `sh:NodeShape` resources. To customise which shapes are selected or how they are nested, pass a custom [JSON-LD Frame](https://www.w3.org/TR/json-ld11-framing/):
112
+
113
+ ```sh
114
+ npx @lde/docgen@latest from-shacl shapes.ttl template.liquid -f my-frame.jsonld
115
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lde/docgen",
3
- "version": "0.6.12",
3
+ "version": "0.6.14",
4
4
  "description": "Generate documentation from SHACL shapes",
5
5
  "keywords": [
6
6
  "shacl",
@@ -9,15 +9,16 @@
9
9
  "generator"
10
10
  ],
11
11
  "repository": {
12
- "url": "https://github.com/ldengine/lde",
12
+ "url": "git+https://github.com/ldelements/lde.git",
13
13
  "directory": "packages/docgen"
14
14
  },
15
+ "license": "MIT",
15
16
  "type": "module",
16
17
  "exports": {
17
18
  "./package.json": "./package.json",
18
19
  ".": {
19
- "development": "./src/index.ts",
20
20
  "types": "./dist/index.d.ts",
21
+ "development": "./src/index.ts",
21
22
  "import": "./dist/index.js",
22
23
  "default": "./dist/index.js"
23
24
  }
@@ -26,7 +27,7 @@
26
27
  "module": "./dist/index.js",
27
28
  "types": "./dist/index.d.ts",
28
29
  "bin": {
29
- "docgen": "./dist/cli.js"
30
+ "docgen": "dist/cli.js"
30
31
  },
31
32
  "files": [
32
33
  "dist",
@@ -35,9 +36,9 @@
35
36
  ],
36
37
  "dependencies": {
37
38
  "commander": "^14.0.3",
38
- "jsonld": "^8.3.3",
39
- "liquidjs": "^10.24.0",
40
- "rdf-dereference": "^4.0.0",
39
+ "jsonld": "^9.0.0",
40
+ "liquidjs": "^10.25.5",
41
+ "rdf-dereference": "^5.0.0",
41
42
  "rdf-serialize": "^5.1.0",
42
43
  "stream-to-string": "^1.2.1",
43
44
  "tslib": "^2.3.0"