changeset 37:7cee2869bd7b

stub out directory example
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 01 Jan 2011 22:28:35 -0800
parents 0cba953a03ca
children 9739212a63c3
files examples/doctest.txt makeitso/makeitso.py
diffstat 2 files changed, 26 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/examples/doctest.txt	Sat Jan 01 22:13:33 2011 -0800
+++ b/examples/doctest.txt	Sat Jan 01 22:28:35 2011 -0800
@@ -5,11 +5,13 @@
 
     >>> import makeitso
     >>> import os
+    >>> import shutil
+    >>> import tempfile
     >>> from StringIO import StringIO
-    >>> example = os.path.join(here, 'example.txt')
 
 Basic functionality:
 
+    >>> example = os.path.join(here, 'example.txt')
     >>> template = makeitso.PolyTemplate([example], interactive=False)
     >>> template.missing()
     set(['name'])
@@ -23,4 +25,21 @@
     >>> template.substitute(name='bar')
     >>> buffer.getvalue().strip()
     'Hello bar'
-    
+
+Substitute to a file:
+
+    >>> buffer = tempfile.mktemp()
+    >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False)
+    >>> template.substitute(name='fleem')
+    >>> file(buffer).read().strip()
+    'Hello fleem'
+    >>> os.remove(buffer)
+
+Directory case:
+
+    >>> exampledir = os.path.join(here, 'directory-example')
+    >>> tempdir = tempfile.mkdtemp()
+    >>> template = makeitso.PolyTemplate([exampledir], output=tempdir, interactive=False)
+    >>> sorted(template.missing())
+    ['bar', 'foo', 'subdir']
+    >>> shutil.rmtree(tempdir)
--- a/makeitso/makeitso.py	Sat Jan 01 22:13:33 2011 -0800
+++ b/makeitso/makeitso.py	Sat Jan 01 22:28:35 2011 -0800
@@ -195,12 +195,15 @@
     def substitute(self, **variables):
         output = ContentTemplate.substitute(self, **variables)
         f = self.output
+        
         if isinstance(f, basestring):
             if os.path.isdir(f):
                 f = os.path.join(f, basename(self.name))
             f = file(f, 'w')
-        print >> f, output
-            
+            print >> f, output
+            f.close()
+        else:
+            print >> f, output
 
 class DirectoryTemplate(ContentTemplate):
     """template for a directory structure"""