Skip to content

Commit acdf604

Browse files
committed
feat: towards support for AsciiDoc, Jinja templates
Replicate the existing HTML meta-templates, with a view towards the following output directory structure when the generation is implemented: ``` output/ └── <ap_name>/ └── asciidoc/ ├── main.adoc ├── statistics.adoc ├── <class_name>/ │ ├── added_instance_<class>.adoc │ ├── deleted_instance_<class>.adoc │ └── <property_group>/ │ ├── added_property_<property>.adoc │ └── ... └── static/ ├── layout.adoc └── macros.adoc ``` HTML → AsciiDoc conversions: - `<h1>, <h2>, <h3>` → `=, ==, ===` - `<p>` → Plain text paragraphs - `<strong>` → `*bold*` - HTML tables → AsciiDoc tables (`[cols=...]`, `|===, |`) - Removed HTML/CSS/JavaScript (not needed in AsciiDoc) Preserved: - Jinja2 template logic (if/for blocks, variables, macros) - Template structure and includes - Data processing macros
1 parent 39d8e9a commit acdf604

File tree

7 files changed

+256
-0
lines changed

7 files changed

+256
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% raw %}
2+
{% import "macros.adoc" as mc %}
3+
{% endraw %}
4+
{{ "{%" }} set content, error = from_endpoint(conf.default_endpoint).with_query_from_file(conf.query_files["{{ query_file }}"]).fetch_tabular() {{ "%}" }}
5+
{% raw %}
6+
{% if not content.empty %}
7+
{% call mc.render_fetch_results(content, error) %}
8+
{% set compress_uris = simplify_uri_columns_in_tabular(data_frame=content,namespace_inventory=namespaces,error_fail=False) %}
9+
{% endraw %}
10+
== {{ operation|title }} {{ class_name }}s
11+
12+
The table below lists the {{ operation }} *{{ cls }}*
13+
14+
*Query identifier:* {{ query_file }}
15+
16+
{{ "{{" }} mc.pandas_table(content, "{{ operation|title }} {{ class_name }}s") {{ "}}" }}
17+
{% raw %}
18+
{% endcall %}
19+
{% endif %}
20+
{% endraw %}
21+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{% raw %}
2+
{% extends "layout.adoc" %}
3+
{% import "macros.adoc" as mc %}
4+
{% block content %}
5+
{% endraw %}
6+
7+
This report is automatically generated from the {% raw %}{{ conf.dataset_name }}{% endraw %} RDF dataset on {% raw %}{{ conf.timestamp }}{% endraw %}
8+
and aims at presenting the difference between two versions of an RDFS/OWL vocabulary following the {% raw %}{{ conf.application_profile }}{% endraw %} application profile.
9+
10+
== Report details
11+
12+
*Dataset ID:* {% raw %}{{ conf.dataset_name }}{% endraw %}
13+
14+
*Dataset name:* {% raw %}{{ conf.original_name }}{% endraw %}
15+
16+
*Old version file:* {% raw %}{{ conf.old_version_file }}{% endraw %}
17+
18+
*New version file:* {% raw %}{{ conf.new_version_file }}{% endraw %}
19+
20+
*Time:* {% raw %}{{ conf.timestamp }}{% endraw %}
21+
22+
*Application profile:* {% raw %}{{ conf.application_profile }}{% endraw %}
23+
24+
{% raw %}
25+
{% set namespaces = namespace_inventory({}) %}
26+
{% include "statistics.adoc" %}
27+
{% endraw %}
28+
{% for class_key , class_data in data_source.items() %}
29+
== {{ class_data.label }}
30+
{% if class_data.description is not undefined %}
31+
{{ class_data.description }}
32+
{% endif %}
33+
{% for instance_change_file in class_data.instance_changes.files %}
34+
{{ "{% include " }}"{{ instance_change_file }}"{{ " with context %}" }}
35+
{% endfor %}
36+
{% for prop_group, prop_group_data in class_data.prop_groups.items() %}
37+
=== {{ prop_group_data.label }}
38+
{% for prop_file in prop_group_data.query_template_file_paths %}
39+
{{ "{% include " }}"{{ prop_file }}"{{ " with context %}" }}
40+
{% endfor %}
41+
{% endfor %}
42+
{% endfor %}
43+
{% raw %}
44+
== Prefixes
45+
46+
{{ mc.render_namespaces(namespaces.namespaces_as_dict()) }}
47+
{% endblock %}
48+
{% endraw %}
49+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% raw %}
2+
{% import "macros.adoc" as mc %}
3+
{% endraw %}
4+
{{ "{%" }} set content, error = from_endpoint(conf.default_endpoint).with_query_from_file(conf.query_files["{{ query_file }}"]).fetch_tabular() {{ "%}" }}
5+
{% raw %}
6+
{% if not content.empty %}
7+
{% call mc.render_fetch_results(content, error) %}
8+
{% set compress_uris = simplify_uri_columns_in_tabular(data_frame=content,namespace_inventory=namespaces,error_fail=False) %}
9+
{% endraw %}
10+
=== {{ operation|title }} {{ property_name }}
11+
12+
The table below lists the {{ operation }} *{{ property }}*
13+
14+
*Query identifier:* {{ query_file }}
15+
16+
{{ "{{" }} mc.pandas_table(content, "{{ operation|title }} {{ property_name }}") {{ "}}" }}
17+
{% raw %}
18+
{% endcall %}
19+
{% endif %}
20+
{% endraw %}
21+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% raw %}
2+
{% import "macros.adoc" as mc %}
3+
{% endraw %}
4+
{{ "{%" }} set content, error = from_endpoint(conf.default_endpoint).with_query_from_file(conf.query_files["{{ query_file }}"]).fetch_tabular() {{ "%}" }}
5+
{% raw %}
6+
{% if not content.empty %}
7+
{% call mc.render_fetch_results(content, error) %}
8+
{% set compress_uris = simplify_uri_columns_in_tabular(data_frame=content,namespace_inventory=namespaces,error_fail=False) %}
9+
{% endraw %}
10+
=== {{ operation|title }} reified {{ property_name }}
11+
12+
The table below lists the {{ operation }} *{{ property }} / {{ object_property }}*
13+
14+
*Query identifier:* {{ query_file }}
15+
16+
{{ "{{" }} mc.pandas_table(content, "{{ operation|title }} reified {{ property_name }}") {{ "}}" }}
17+
{% raw %}
18+
{% endcall %}
19+
{% endif %}
20+
{% endraw %}
21+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% raw %}
2+
= {{ conf.title }}
3+
4+
{% block content %}
5+
{% endblock %}
6+
{% endraw %}
7+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{# Default way of showing errors #}
2+
{% macro render_error(message) -%}
3+
[NOTE]
4+
====
5+
*Error*
6+
7+
{{ message|e }}
8+
====
9+
{%- endmacro %}
10+
11+
{# Default macro for showing/wrapping the fetch results #}
12+
{% macro render_fetch_results(content, error) -%}
13+
{% if error %}
14+
{{ render_error(error) }}
15+
{% else %}
16+
{% if content is undefined %}
17+
{{ render_error("Some content expected but none was found.") }}
18+
{% else %}
19+
{{ caller() }}
20+
{% endif %}
21+
{% endif %}
22+
{%- endmacro %}
23+
24+
25+
{% macro pandas_table(df, caption, column_labels={}) -%}
26+
{% if (df is defined) and (df is not none) %}
27+
{% set df = df.fillna(value="") %}
28+
[cols="{{ df.columns|length }}*", options="header"]
29+
|===
30+
{% for column in df.columns %}
31+
{% if column in column_labels %}
32+
|{{ column_labels[column] }}
33+
{% else %}
34+
|{{ column }}
35+
{% endif %}
36+
{% endfor %}
37+
38+
{% for idx, row in df.iterrows() %}
39+
{% for colname in df.columns %}
40+
{# handle decimal format: float, float64, float32 #}
41+
{% if 'float' in (df.dtypes[colname] | string) %}
42+
|{{ row[colname] | round(precision=2) }}
43+
{% else %}
44+
|{{ row[colname] }}
45+
{% endif %}
46+
{% endfor %}
47+
48+
{% endfor %}
49+
|===
50+
51+
.{{ caption }}
52+
{% else %}
53+
{{ render_error("How did you get here? did you forget to use 'render_fetch_results' macro?") }}
54+
{% endif %}
55+
{%- endmacro %}
56+
57+
{% macro count_value(df) %}
58+
{% for idx, row in df.iterrows() %}
59+
{% for colname in df.columns %}
60+
|{{ row[colname] }}
61+
{% endfor %}
62+
{% endfor %}
63+
{% endmacro %}
64+
65+
{% macro render_namespaces(namesapces_dist) %}
66+
[cols="1,3", options="header"]
67+
|===
68+
|Namespace
69+
|URI
70+
71+
{% for prefix, uri in namesapces_dist|dictsort %}
72+
|{{ prefix }}
73+
|{{ uri }}
74+
75+
{% endfor %}
76+
|===
77+
78+
.Prefixes
79+
{% endmacro %}
80+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{% raw %}
2+
{% import "macros.adoc" as mc %}
3+
{% endraw %}
4+
== Statistics
5+
6+
{% for class_key , class_data in data_source.items() %}
7+
=== {{ class_data.label }}
8+
{% if class_data.description is not undefined %}
9+
{{ class_data.description }}
10+
{% endif %}
11+
12+
[cols="1,1,1", options="header"]
13+
|===
14+
|Instance
15+
|Added
16+
|Deleted
17+
18+
|{{ class_data.label }}
19+
{% for count_query in class_data.instance_changes.count_queries %}
20+
{{ "{%" }} set content, error = from_endpoint(conf.default_endpoint).with_query_from_file(conf.query_files["{{ count_query }}"]).fetch_tabular() {{ "%}" }}
21+
{% raw %}
22+
{% call mc.render_fetch_results(content, error) %}
23+
{{ mc.count_value(content) }}
24+
{% endcall %}
25+
{% endraw %}
26+
{% endfor %}
27+
|===
28+
29+
[cols="1,1,1,1,1,1,1", options="header"]
30+
|===
31+
|Property group
32+
|Property
33+
|Added
34+
|Deleted
35+
|Updated
36+
|Moved
37+
|Changed
38+
{% for prop_group, prop_group_data in class_data.prop_groups.items() %}
39+
{% set prop_group_name = prop_group_data.label %}
40+
{% for index ,count_prop_section in prop_group_data.count_queries.items() %}
41+
42+
|{{ prop_group_name }}
43+
|{{ count_prop_section.label }}
44+
{% for query_file in count_prop_section.files %}
45+
{{ "{%" }} set content, error = from_endpoint(conf.default_endpoint).with_query_from_file(conf.query_files["{{ query_file }}"]).fetch_tabular() {{ "%}" }}
46+
{% raw %}
47+
{% call mc.render_fetch_results(content, error) %}
48+
{{ mc.count_value(content) }}
49+
{% endcall %}
50+
{% endraw %}
51+
{% endfor %}
52+
{% endfor %}
53+
{% endfor %}
54+
|===
55+
56+
{% endfor %}
57+

0 commit comments

Comments
 (0)