diff --git a/generated/download-items.html b/generated/download-items.html
index da4b7266..469dc6d9 100644
--- a/generated/download-items.html
+++ b/generated/download-items.html
@@ -21,4 +21,3 @@
Download
Documentation
-
diff --git a/generated/history-items.html b/generated/history-items.html
index 9e5ca592..78dd7ea3 100644
--- a/generated/history-items.html
+++ b/generated/history-items.html
@@ -1051,4 +1051,3 @@
-
diff --git a/generated/home-items.html b/generated/home-items.html
index 3cbccc02..e12005d6 100644
--- a/generated/home-items.html
+++ b/generated/home-items.html
@@ -50,4 +50,3 @@
-
diff --git a/site-tools/boost_site/settings.py b/site-tools/boost_site/settings.py
index 924a3dd0..cb115b48 100644
--- a/site-tools/boost_site/settings.py
+++ b/site-tools/boost_site/settings.py
@@ -32,10 +32,10 @@ settings = {
}
},
'index-pages' : {
- 'generated/download-items.html' : 'site-tools/templates/download-template.html',
- 'generated/history-items.html' : 'site-tools/templates/history-template.html',
- 'generated/news-items.html' : 'site-tools/templates/news-template.html',
- 'generated/home-items.html' : 'site-tools/templates/index-src.html'
+ 'generated/download-items.html' : 'site-tools/templates/download-template.py',
+ 'generated/history-items.html' : 'site-tools/templates/history-template.py',
+ 'generated/news-items.html' : 'site-tools/templates/news-template.py',
+ 'generated/home-items.html' : 'site-tools/templates/index-template.py'
},
# See boost_site.pages for matches pattern syntax.
#
diff --git a/site-tools/boost_site/site_tools.py b/site-tools/boost_site/site_tools.py
index 900e6815..f1fc8286 100755
--- a/site-tools/boost_site/site_tools.py
+++ b/site-tools/boost_site/site_tools.py
@@ -4,7 +4,7 @@
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
import os, sys, subprocess, glob, re, time, xml.dom.minidom, codecs
-import boost_site.templite, boost_site.pages, boost_site.boostbook_parser, boost_site.util
+import boost_site.pages, boost_site.boostbook_parser, boost_site.util
from boost_site.settings import settings
################################################################################
@@ -54,7 +54,7 @@ def update_quickbook(refresh = False):
}
for index_page in settings['index-pages']:
- boost_site.templite.write_template(
+ boost_site.util.write_py_template(
index_page,
settings['index-pages'][index_page],
index_page_variables)
diff --git a/site-tools/boost_site/templite.py b/site-tools/boost_site/templite.py
deleted file mode 100755
index 85d99b88..00000000
--- a/site-tools/boost_site/templite.py
+++ /dev/null
@@ -1,87 +0,0 @@
-# Templite
-#
-# Taken from:
-## {{{ http://code.activestate.com/recipes/496702/ (r3)
-#
-# Modified to use unicode, and added convenience method.
-#
-# Licensed under the PSF License
-
-import re
-
-# TODO: Integrate with main class?
-def write_template(location, template, params):
- template_file = open(template, 'r')
- try:
- template_format = template_file.read().decode('utf-8')
- finally:
- template_file.close()
-
- t = Templite(template_format)
- output = t(params)
- output_file = open(location, 'w')
- try:
- output_file.write(output.encode('utf-8'))
- finally:
- output_file.close()
-
-class Templite(object):
- delimiter = re.compile(r"\$\{(.*?)\}\$", re.DOTALL)
-
- def __init__(self, template):
- self.tokens = self.compile(template)
-
- @classmethod
- def from_file(cls, file):
- """
- loads a template from a file. `file` can be either a string, specifying
- a filename, or a file-like object, supporting read() directly
- """
- if isinstance(file, basestring):
- file = open(file)
- return cls(file.read())
-
- @classmethod
- def compile(cls, template):
- tokens = []
- for i, part in enumerate(cls.delimiter.split(template)):
- if i % 2 == 0:
- if part:
- tokens.append((False, part.replace("$\\{", "${")))
- else:
- if not part.strip():
- continue
- lines = part.replace("}\\$", "}$").splitlines()
- margin = min(len(l) - len(l.lstrip()) for l in lines if l.strip())
- realigned = "\n".join(l[margin:] for l in lines)
- code = compile(realigned, "" % (realigned[:20],), "exec")
- tokens.append((True, code))
- return tokens
-
- def render(__self, __namespace = None, **kw):
- """
- renders the template according to the given namespace.
- __namespace - a dictionary serving as a namespace for evaluation
- **kw - keyword arguments which are added to the namespace
- """
- namespace = {}
- if __namespace: namespace.update(__namespace)
- if kw: namespace.update(kw)
-
- def emitter(*args):
- for a in args: output.append(unicode(a))
- def fmt_emitter(fmt, *args):
- output.append(fmt % args)
- namespace["emit"] = emitter
- namespace["emitf"] = fmt_emitter
-
- output = []
- for is_code, value in __self.tokens:
- if is_code:
- eval(value, namespace)
- else:
- output.append(value)
- return "".join(output)
-
- # shorthand
- __call__ = render
diff --git a/site-tools/boost_site/util.py b/site-tools/boost_site/util.py
index b35fc245..e1ca521d 100755
--- a/site-tools/boost_site/util.py
+++ b/site-tools/boost_site/util.py
@@ -42,3 +42,17 @@ def write_template(dst_path, template_path, data):
output = re.sub(r' +$', '', output, flags = re.M)
out = open(dst_path, "w")
out.write(output.encode('utf-8'))
+
+def write_py_template(dst_path, template_path, data):
+ data['emit'] = Emitter()
+ exec(open(template_path).read(), {}, data)
+
+ out = open(dst_path, 'w')
+ out.write(data['emit'].output.encode('utf-8'))
+
+class Emitter:
+ def __init__(self):
+ self.output = ''
+
+ def __call__(self, x):
+ self.output += x
\ No newline at end of file
diff --git a/site-tools/templates/download-template.html b/site-tools/templates/download-template.py
similarity index 99%
rename from site-tools/templates/download-template.html
rename to site-tools/templates/download-template.py
index 6c2786eb..76ecd91e 100644
--- a/site-tools/templates/download-template.html
+++ b/site-tools/templates/download-template.py
@@ -1,4 +1,3 @@
-${
from boost_site.util import htmlencode
emit('\n');
@@ -30,4 +29,3 @@ for x in downloads:
emit('Documentation' % htmlencode(entry.documentation))
emit('\n')
emit('
\n')
-}$
diff --git a/site-tools/templates/history-template.html b/site-tools/templates/history-template.py
similarity index 99%
rename from site-tools/templates/history-template.html
rename to site-tools/templates/history-template.py
index 40b286e0..052fd265 100644
--- a/site-tools/templates/history-template.html
+++ b/site-tools/templates/history-template.py
@@ -1,4 +1,3 @@
-${
from boost_site.util import htmlencode
title = 'Boost Version History'
@@ -24,4 +23,3 @@ for entry in entries:
emit('Documentation' % htmlencode(entry.documentation))
emit('\n')
emit('\n')
-}$
diff --git a/site-tools/templates/index-src.html b/site-tools/templates/index-template.py
similarity index 99%
rename from site-tools/templates/index-src.html
rename to site-tools/templates/index-template.py
index 638f43a5..620e7133 100644
--- a/site-tools/templates/index-src.html
+++ b/site-tools/templates/index-template.py
@@ -1,4 +1,3 @@
-${
from boost_site.util import htmlencode
# TODO: This is duplicated from other places, should only be set once?
@@ -53,4 +52,3 @@ emit('More News... (RSS
emit('\n\n')
emit('
\n')
-}$
diff --git a/site-tools/templates/news-template.html b/site-tools/templates/news-template.py
similarity index 99%
rename from site-tools/templates/news-template.html
rename to site-tools/templates/news-template.py
index a84af40f..cb880b9b 100644
--- a/site-tools/templates/news-template.html
+++ b/site-tools/templates/news-template.py
@@ -1,4 +1,3 @@
-${
from boost_site.util import htmlencode
entries = pages.match_pages(['feed/news/*.qbk', 'feed/history/*.qbk|released'], 5)
@@ -31,4 +30,3 @@ for entry in entries:
emit('Documentation' % htmlencode(entry.documentation))
emit('\n')
emit('')
-}$
\ No newline at end of file