changeset 65:ac1dc088e37e

add inclusion template
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 26 Oct 2011 21:21:47 -0700
parents 613ffeec2be5
children 5d34e9d14666
files decoupage.ini decoupage/formatters.py decoupage/templates/inclusion.html decoupage/templates/index.html decoupage/web.py example/inclusion/cat.txt example/inclusion/dog.txt example/inclusion/index.ini example/inclusion/monster.txt setup.py
diffstat 10 files changed, 38 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/decoupage.ini	Wed Dec 15 09:30:32 2010 -0800
+++ b/decoupage.ini	Wed Oct 26 21:21:47 2011 -0700
@@ -21,3 +21,4 @@
 paste.app_factory = decoupage.factory:factory
 decoupage.directory = %(here)s/example
 decoupage.configuration = %(here)s/example.ini
+decoupage.auto_reload = True
\ No newline at end of file
--- a/decoupage/formatters.py	Wed Dec 15 09:30:32 2010 -0800
+++ b/decoupage/formatters.py	Wed Oct 26 21:21:47 2011 -0700
@@ -204,6 +204,7 @@
         path = request.path_info
         if (path != '/') and self.up:
             data['files'].insert(0, {'path': '..',
+                                     'type': 'directory',
                                      'name': path.rsplit('/', 1)[0] + '/',
                                      'description': self.up})
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/decoupage/templates/inclusion.html	Wed Oct 26 21:21:47 2011 -0700
@@ -0,0 +1,24 @@
+<!DOCTYPE html
+    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:py="http://genshi.edgewall.org/"
+      xmlns:xi="http://www.w3.org/2001/XInclude">
+  <!-- include files as snippets -->
+  <head>
+    <xi:include href="head.html"/>
+  </head>
+  <body>
+    <xi:include py:if="include" href="${include}"/>
+    <h1 py:if="title">${title}</h1>
+
+    <py:for each="index, f in enumerate([i for i in files if i['type'] == 'file'])">
+      <!-- separate with an hr -->
+      <hr py:if="index"/>
+      <a name="${f['name']}"></a>
+      ${file(filepath(f['name'])).read()}
+      <a href="#${f['name']}">#</a>
+    </py:for>
+  </body>
+</html>
+      
--- a/decoupage/templates/index.html	Wed Dec 15 09:30:32 2010 -0800
+++ b/decoupage/templates/index.html	Wed Oct 26 21:21:47 2011 -0700
@@ -4,6 +4,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:py="http://genshi.edgewall.org/"
       xmlns:xi="http://www.w3.org/2001/XInclude">
+  <!-- basic index of files -->
   <head>
     <xi:include href="head.html"/>
   </head>
--- a/decoupage/web.py	Wed Dec 15 09:30:32 2010 -0800
+++ b/decoupage/web.py	Wed Oct 26 21:21:47 2011 -0700
@@ -156,6 +156,9 @@
         files = self.filedata(path, directory, conf)
         data = {'path': path, 'files': files, 'request': request }
 
+        # add a function to get the path to files
+        data['filepath'] = lambda *segments: os.path.join(*([directory] + list(segments)))
+
         # defaults; TODO: make this better
         # there shouldn't need to be defaults;
         # iirc, genshi has a mode where these will default to None
@@ -208,8 +211,8 @@
                 if os.path.exists(_template):
                     template = _template
                 else:
-                    for directory in self.template_directories:
-                        if template in os.listdir(directory):
+                    for _directory in self.template_directories:
+                        if template in os.listdir(_directory):
                             break
                     else:
                         raise IOError("template %s not found" % template)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/inclusion/cat.txt	Wed Oct 26 21:21:47 2011 -0700
@@ -0,0 +1,1 @@
+cat
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/inclusion/dog.txt	Wed Oct 26 21:21:47 2011 -0700
@@ -0,0 +1,1 @@
+dog
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/inclusion/index.ini	Wed Oct 26 21:21:47 2011 -0700
@@ -0,0 +1,2 @@
+/template = inclusion.html
+/ignore = index.ini
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/inclusion/monster.txt	Wed Oct 26 21:21:47 2011 -0700
@@ -0,0 +1,1 @@
+monster
--- a/setup.py	Wed Dec 15 09:30:32 2010 -0800
+++ b/setup.py	Wed Oct 26 21:21:47 2011 -0700
@@ -6,7 +6,7 @@
 except IOError:
     description = ''
 
-version = '0.10.1'
+version = '0.10.2'
 
 setup(name='decoupage',
       version=version,