[tracker/wip/carlosg/hotdoc: 25/40] docs: Generate examples page with actual examples




commit 5bec5b88e5bd77f1828d3bfc614e39999853215f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jun 7 01:24:52 2021 +0200

    docs: Generate examples page with actual examples
    
    Do some string replacement here to include the examples.

 docs/reference/libtracker-sparql/embed-files.py    | 25 ++++++++++++++++++++++
 .../{examples.md => examples.md.in}                |  0
 docs/reference/libtracker-sparql/meson.build       | 23 ++++++++++++++++++--
 3 files changed, 46 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/libtracker-sparql/embed-files.py b/docs/reference/libtracker-sparql/embed-files.py
new file mode 100755
index 000000000..df993b24f
--- /dev/null
+++ b/docs/reference/libtracker-sparql/embed-files.py
@@ -0,0 +1,25 @@
+#!/usr/bin/python3
+
+import os, sys, re
+
+f = open(sys.argv[1])
+content = f.read()
+f.close()
+
+dirname = os.path.dirname(sys.argv[1])
+
+regex = re.compile('{{(.*)}}')
+matches = regex.findall(content)
+replacements = {}
+
+for m in matches:
+    f = open(os.path.join(dirname, m))
+    embedded = f.read()
+    escaped = embedded.replace('\\', '\\\\')
+    replace = re.compile('{{' + m + '}}')
+    content = replace.sub(escaped, content)
+    f.close()
+
+f = open(sys.argv[2], 'w')
+f.write(content)
+f.close()
diff --git a/docs/reference/libtracker-sparql/examples.md b/docs/reference/libtracker-sparql/examples.md.in
similarity index 100%
rename from docs/reference/libtracker-sparql/examples.md
rename to docs/reference/libtracker-sparql/examples.md.in
diff --git a/docs/reference/libtracker-sparql/meson.build b/docs/reference/libtracker-sparql/meson.build
index a492accfd..14321c810 100644
--- a/docs/reference/libtracker-sparql/meson.build
+++ b/docs/reference/libtracker-sparql/meson.build
@@ -1,3 +1,22 @@
+documents_with_examples = [
+  [ 'examples.md.in', 'examples.md' ],
+]
+examples = []
+
+foreach doc : documents_with_examples
+  examples += custom_target(
+    'examples-generate',
+    input: doc[0],
+    output: doc[1],
+    command: [
+      'embed-files.py',
+      '@INPUT@',
+      '@OUTPUT@',
+    ],
+    depend_files: [ doc[0] ],
+    build_by_default: true)
+endforeach
+
 base_ontology_docs = custom_target('ontology-docgen',
     output: ['dc-ontology.md'],
     command: [tracker_docgen,
@@ -12,7 +31,6 @@ base_ontology_docs = custom_target('ontology-docgen',
 content = [
   'overview.md',
   'ontologies.md',
-  'examples.md',
   'limits.md',
   'performance.md',
   'sparql-and-tracker.md',
@@ -22,6 +40,7 @@ content = [
 ]
 
 generated_content = [
+  'examples.md',
   'xsd-ontology.md',
   'dc-ontology.md',
   'rdf-ontology.md',
@@ -57,6 +76,6 @@ custom_target(
     '--content-dir=@0@'.format(icon_images_base),
     '@INPUT1@',
   ],
-  depends: [tracker_sparql_gir[0], base_ontology_docs],
+  depends: [tracker_sparql_gir[0], base_ontology_docs, examples],
   depend_files: [ content ],
   build_by_default: true)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]