Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78676 - in website/public_html/beta: generated site-tools/boost_site site-tools/templates
From: dnljms_at_[hidden]
Date: 2012-05-27 08:48:31


Author: danieljames
Date: 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
New Revision: 78676
URL: http://svn.boost.org/trac/boost/changeset/78676

Log:
Website: Replace templite files with simple python scripts.
Added:
   website/public_html/beta/site-tools/templates/download-template.py (contents, props changed)
      - copied, changed from r78675, /website/public_html/beta/site-tools/templates/download-template.html
   website/public_html/beta/site-tools/templates/history-template.py (contents, props changed)
      - copied, changed from r78675, /website/public_html/beta/site-tools/templates/history-template.html
   website/public_html/beta/site-tools/templates/index-template.py (contents, props changed)
      - copied, changed from r78675, /website/public_html/beta/site-tools/templates/index-src.html
   website/public_html/beta/site-tools/templates/news-template.py (contents, props changed)
      - copied, changed from r78675, /website/public_html/beta/site-tools/templates/news-template.html
Removed:
   website/public_html/beta/site-tools/boost_site/templite.py
   website/public_html/beta/site-tools/templates/download-template.html
   website/public_html/beta/site-tools/templates/history-template.html
   website/public_html/beta/site-tools/templates/index-src.html
   website/public_html/beta/site-tools/templates/news-template.html
Text files modified:
   website/public_html/beta/generated/download-items.html | 1 -
   website/public_html/beta/generated/history-items.html | 1 -
   website/public_html/beta/generated/home-items.html | 1 -
   website/public_html/beta/site-tools/boost_site/settings.py | 8 ++++----
   website/public_html/beta/site-tools/boost_site/site_tools.py | 4 ++--
   website/public_html/beta/site-tools/boost_site/util.py | 14 ++++++++++++++
   website/public_html/beta/site-tools/templates/download-template.py | 2 --
   website/public_html/beta/site-tools/templates/history-template.py | 2 --
   website/public_html/beta/site-tools/templates/index-template.py | 2 --
   website/public_html/beta/site-tools/templates/news-template.py | 2 --
   10 files changed, 20 insertions(+), 17 deletions(-)

Modified: website/public_html/beta/generated/download-items.html
==============================================================================
--- website/public_html/beta/generated/download-items.html (original)
+++ website/public_html/beta/generated/download-items.html 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
@@ -21,4 +21,3 @@
 <li>Download</li>
 <li>Documentation</li>
 </ul>
-

Modified: website/public_html/beta/generated/history-items.html
==============================================================================
--- website/public_html/beta/generated/history-items.html (original)
+++ website/public_html/beta/generated/history-items.html 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
@@ -1051,4 +1051,3 @@
 <ul class="menu">
 <li>Details</li>
 </ul>
-

Modified: website/public_html/beta/generated/home-items.html
==============================================================================
--- website/public_html/beta/generated/home-items.html (original)
+++ website/public_html/beta/generated/home-items.html 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
@@ -50,4 +50,3 @@
 </div>
 
 <div class="clear"></div>
-

Modified: website/public_html/beta/site-tools/boost_site/settings.py
==============================================================================
--- website/public_html/beta/site-tools/boost_site/settings.py (original)
+++ website/public_html/beta/site-tools/boost_site/settings.py 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
@@ -32,10 +32,10 @@
         }
     },
     '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.
     #

Modified: website/public_html/beta/site-tools/boost_site/site_tools.py
==============================================================================
--- website/public_html/beta/site-tools/boost_site/site_tools.py (original)
+++ website/public_html/beta/site-tools/boost_site/site_tools.py 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
@@ -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 @@
     }
 
     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)

Deleted: website/public_html/beta/site-tools/boost_site/templite.py
==============================================================================
--- website/public_html/beta/site-tools/boost_site/templite.py 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
+++ (empty file)
@@ -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, "<templite %r>" % (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

Modified: website/public_html/beta/site-tools/boost_site/util.py
==============================================================================
--- website/public_html/beta/site-tools/boost_site/util.py (original)
+++ website/public_html/beta/site-tools/boost_site/util.py 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
@@ -42,3 +42,17 @@
     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

Deleted: website/public_html/beta/site-tools/templates/download-template.html
==============================================================================
--- website/public_html/beta/site-tools/templates/download-template.html 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
+++ (empty file)
@@ -1,33 +0,0 @@
-${
-from boost_site.util import htmlencode
-emit('<ul class="toc">\n');
-
-for x in downloads:
- emit('<li>%s</li>\n' % (x['anchor'], x['label']))
-
-emit('<li>Old Boost Releases</li>\n')
-emit('<li>Subversion Repository</li>\n')
-emit('</ul>\n')
-
-for x in downloads:
- emit('<h2 id="%s">%s</h2>' % (x['anchor'], x['label']))
- for entry in x['entries']:
- emit('\n')
- emit(' <h3><span class=\n "news-title">%s</span></h3>\n\n' % entry.full_title_xml)
- emit(' <p class="news-date">%s</p>\n\n' % entry.web_date())
- emit(' <p class="news-description">\n')
- emit(' <span class="brief"><span class="purpose">%s</span></span></p>\n\n' % entry.purpose_xml)
- emit('<ul class="menu">\n')
- emit('<li>')
- emit('Details' % htmlencode(entry.location))
- emit('</li>\n')
- if(entry.download_item):
- emit('<li>')
- emit('Download' % htmlencode(entry.download_item))
- emit('</li>\n')
- if(entry.documentation):
- emit('<li>')
- emit('Documentation' % htmlencode(entry.documentation))
- emit('</li>\n')
- emit('</ul>\n')
-}$

Copied: website/public_html/beta/site-tools/templates/download-template.py (from r78675, /website/public_html/beta/site-tools/templates/download-template.html)
==============================================================================
--- /website/public_html/beta/site-tools/templates/download-template.html (original)
+++ website/public_html/beta/site-tools/templates/download-template.py 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
@@ -1,4 +1,3 @@
-${
 from boost_site.util import htmlencode
 emit('<ul class="toc">\n');
 
@@ -30,4 +29,3 @@
             emit('Documentation' % htmlencode(entry.documentation))
             emit('</li>\n')
         emit('</ul>\n')
-}$

Deleted: website/public_html/beta/site-tools/templates/history-template.html
==============================================================================
--- website/public_html/beta/site-tools/templates/history-template.html 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
+++ (empty file)
@@ -1,27 +0,0 @@
-${
-from boost_site.util import htmlencode
-
-title = 'Boost Version History'
-entries = pages.match_pages(['feed/history/*.qbk|released'])
-
-for entry in entries:
- emit('\n')
- emit(' <h2 class="news-title">\n <a name="i%s" id="i%s"></a>%s</h2>\n\n' % (entry.id, entry.id, htmlencode(entry.location), entry.title_xml))
- emit(' <p class="news-date">%s</p>\n\n' % (entry.web_date()))
- emit(' <div class="news-description">\n')
- emit(' <span class="brief"><span class="purpose">%s</span></span>\n' % (entry.purpose_xml))
- emit(' </div>\n\n')
- emit('<ul class="menu">\n')
- emit('<li>')
- emit('Details' % htmlencode(entry.location))
- emit('</li>\n')
- if(entry.download_item):
- emit('<li>')
- emit('Download' % htmlencode(entry.download_item))
- emit('</li>\n')
- if(entry.documentation):
- emit('<li>')
- emit('Documentation' % htmlencode(entry.documentation))
- emit('</li>\n')
- emit('</ul>\n')
-}$

Copied: website/public_html/beta/site-tools/templates/history-template.py (from r78675, /website/public_html/beta/site-tools/templates/history-template.html)
==============================================================================
--- /website/public_html/beta/site-tools/templates/history-template.html (original)
+++ website/public_html/beta/site-tools/templates/history-template.py 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
@@ -1,4 +1,3 @@
-${
 from boost_site.util import htmlencode
 
 title = 'Boost Version History'
@@ -24,4 +23,3 @@
         emit('Documentation' % htmlencode(entry.documentation))
         emit('</li>\n')
     emit('</ul>\n')
-}$

Deleted: website/public_html/beta/site-tools/templates/index-src.html
==============================================================================
--- website/public_html/beta/site-tools/templates/index-src.html 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
+++ (empty file)
@@ -1,56 +0,0 @@
-${
-from boost_site.util import htmlencode
-
-# TODO: This is duplicated from other places, should only be set once?
-news = pages.match_pages(['feed/news/*.qbk', 'feed/history/*.qbk|released'], 3)
-
-emit('<div class="directory-item" id="important-downloads">\n');
-emit('<h2>Downloads</h2>\n');
-emit('<div id="downloads">\n');
-
-for x in downloads:
- label = x['label']
- entries = x['entries']
- emit('<h3>%s</h3>\n' % label)
- emit('<ul>\n')
- for entry in entries:
- emit('<li>')
- emit('<div class="news-title">')
- if entry.download_item:
- emit('<a href="%s">' % htmlencode(entry.download_item))
- emit(entry.full_title_xml)
- if entry.download_item:
- emit('</a>')
- emit('</div>')
- emit('<div class="news-date">')
- emit('Release Notes' % (htmlencode(entry.location)))
- if entry.documentation:
- emit(' | ')
- emit('Documentation' % (htmlencode(entry.documentation)))
- emit('</div>')
- emit('<div class="news-date">%s</div>' % (entry.web_date()))
- emit('</li>\n')
- emit('</ul>\n')
-
-emit('</div>\n')
-emit('<p>More Downloads...')
-emit('(RSS)</p>\n')
-emit('</div>\n\n')
-
-emit('<div class="directory-item" id="important-news">\n')
-emit('<h2>News</h2>\n\n')
-
-emit('<ul id="news">\n')
-
-for entry in news:
- emit('\n')
- emit(' <li><span class=\n "news-title">%s</span>\n' % (htmlencode(entry.location), entry.full_title_xml))
- emit(' <span class=\n "news-description"><span class="brief"><span class="purpose">%s</span></span></span>\n' % entry.purpose_xml)
- emit(' <span class=\n "news-date">%s</span></li>' % (entry.web_date()))
-emit('</ul>\n\n')
-
-emit('<p>More News... (<a href=feed/news.rss">RSS</a>)</p>\n')
-emit('</div>\n\n')
-
-emit('<div class="clear"></div>\n')
-}$

Copied: website/public_html/beta/site-tools/templates/index-template.py (from r78675, /website/public_html/beta/site-tools/templates/index-src.html)
==============================================================================
--- /website/public_html/beta/site-tools/templates/index-src.html (original)
+++ website/public_html/beta/site-tools/templates/index-template.py 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
@@ -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('</div>\n\n')
 
 emit('<div class="clear"></div>\n')
-}$

Deleted: website/public_html/beta/site-tools/templates/news-template.html
==============================================================================
--- website/public_html/beta/site-tools/templates/news-template.html 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
+++ (empty file)
@@ -1,34 +0,0 @@
-${
-from boost_site.util import htmlencode
-
-entries = pages.match_pages(['feed/news/*.qbk', 'feed/history/*.qbk|released'], 5)
-
-emit('<ul class="toc">\n')
-emit(' ')
-for entry in entries:
- emit('\n')
- emit(' <li><span class=\n "news-title">%s</span></li>\n' % (htmlencode(entry.id), entry.title_xml))
-emit(' </ul>')
-for entry in entries:
- emit('\n')
- emit(' <h2 class="news-title">\n')
- emit(' <a name="i%s" id="i%s"></a>%s' % (entry.id, entry.id, htmlencode(entry.location), entry.title_xml))
- emit('</h2>\n\n')
- emit(' <p class="news-date">%s</p>\n\n' % (entry.web_date()))
- emit(' <div class="news-description">\n')
- emit(' <span class="brief"><span class="purpose">%s</span></span>\n' % (entry.purpose_xml))
- emit(' </div>\n\n')
- emit('<ul class="menu">\n')
- emit('<li>')
- emit('Details' % htmlencode(entry.location))
- emit('</li>\n')
- if(entry.download_item):
- emit('<li>')
- emit('Download' % htmlencode(entry.download_item))
- emit('</li>\n')
- if(entry.documentation):
- emit('<li>')
- emit('Documentation' % htmlencode(entry.documentation))
- emit('</li>\n')
- emit('</ul>')
-}$
\ No newline at end of file

Copied: website/public_html/beta/site-tools/templates/news-template.py (from r78675, /website/public_html/beta/site-tools/templates/news-template.html)
==============================================================================
--- /website/public_html/beta/site-tools/templates/news-template.html (original)
+++ website/public_html/beta/site-tools/templates/news-template.py 2012-05-27 08:48:30 EDT (Sun, 27 May 2012)
@@ -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 @@
         emit('Documentation' % htmlencode(entry.documentation))
         emit('</li>\n')
     emit('</ul>')
-}$
\ No newline at end of file


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk