[gtk-doc] db2html: move templates out of the code
- From: Stefan Sauer <stefkost src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-doc] db2html: move templates out of the code
- Date: Sat, 16 Dec 2017 20:18:19 +0000 (UTC)
commit 6e10d5c3997c6c3ca14adb47508c33813414aa5b
Author: Stefan Sauer <ensonic users sf net>
Date: Sat Dec 16 21:17:18 2017 +0100
db2html: move templates out of the code
Load the templates from files and introduce some macros.
tools/db2html.py | 32 +++++++++++++++++---------------
tools/templates/book.html | 17 +++++++++++++++++
tools/templates/common.html | 20 ++++++++++++++++++++
3 files changed, 54 insertions(+), 15 deletions(-)
---
diff --git a/tools/db2html.py b/tools/db2html.py
index f7f498d..58482af 100644
--- a/tools/db2html.py
+++ b/tools/db2html.py
@@ -25,7 +25,8 @@ The tool loaded the main xml document (<module>-docs.xml) and chunks it
like the xsl-stylesheets would do. For that it resolves all the xml-includes.
TODO: convert the docbook-xml to html
-- try macros for the navigation
+- navigation
+- toc
Requirements:
sudo pip3 install anytree jinja2 lxml
@@ -33,8 +34,11 @@ sudo pip3 install anytree jinja2 lxml
Examples:
python3 tools/db2html.py tests/gobject/docs/tester-docs.xml
ll tests/gobject/docs/db2html
+
python3 tools/db2html.py tests/bugs/docs/tester-docs.xml
ll tests/bugs/docs/db2html
+cp tests/bugs/docs/html/*.{css,png} tests/bugs/docs/db2html/
+xdg-open tests/bugs/docs/db2html/index.html
"""
import argparse
@@ -44,9 +48,10 @@ import os
import sys
from anytree import Node
-from jinja2 import Template
+from jinja2 import Environment, FileSystemLoader
from lxml import etree
+
# http://www.sagehill.net/docbookxsl/Chunking.html
CHUNK_TAGS = [
'appendix',
@@ -97,21 +102,18 @@ CHUNK_NAMING = {
},
}
-DOCTYPE = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
-
-BOOK_TEMPLATE = DOCTYPE + """
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<title>{{ xpath('./bookinfo/title/text()') }}</title>
-</head>
-<body>
-</body>
-</html>
-"""
+# Jinja2 templates
+TOOL_PATH = os.path.dirname(os.path.abspath(__file__))
+TEMPLATE_ENV = Environment(
+ # loader=PackageLoader('gtkdoc', 'templates'),
+ # autoescape=select_autoescape(['html', 'xml'])
+ loader=FileSystemLoader(os.path.join(TOOL_PATH, 'templates')),
+ autoescape=False,
+ trim_blocks=True,
+)
TEMPLATES = {
- 'book': Template(BOOK_TEMPLATE),
+ 'book': TEMPLATE_ENV.get_template('book.html'),
}
diff --git a/tools/templates/book.html b/tools/templates/book.html
new file mode 100644
index 0000000..f828c62
--- /dev/null
+++ b/tools/templates/book.html
@@ -0,0 +1,17 @@
+{% from 'common.html' import doctype, navigation_main %}
+{% set title = xpath('./bookinfo/title/text()') %}
+{{ doctype() }}
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>{{ title }}</title>
+<link rel="stylesheet" href="style.css" type="text/css">
+</head>
+<body>
+<div class="book">
+<div class="titlepage">
+{{ navigation_main(title) }}
+</div>
+</div>
+</body>
+</html>
\ No newline at end of file
diff --git a/tools/templates/common.html b/tools/templates/common.html
new file mode 100644
index 0000000..58b0032
--- /dev/null
+++ b/tools/templates/common.html
@@ -0,0 +1,20 @@
+{% macro doctype() %}
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+{% endmacro %}
+
+{% macro navigation_main(title) %}
+<div>
+ <table class="navigation" id="top" width="100%" cellpadding="2" cellspacing="0">
+ <tr><th valign="middle"><p class="title">{{ title }}</p></th></tr>
+ </table>
+</div>
+{% endmacro %}
+
+{% macro navigation_std(title) %}
+{% endmacro %}
+
+{% macro navigation_ref(title) %}
+{% endmacro %}
+
+{% macro navigation_idx(title) %}
+{% endmacro %}
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]