Commits

Pablo Caro Revuelta  committed 2751f6d

Support of .html.mako extension

  • Participants
  • Parent commits fcdbcd3

Comments (0)

Files changed (1)

File src/tacot/__init__.py

             os.makedirs(os.path.dirname(dest_filepath))
 
         if fnmatch.fnmatch(source_filepath, "*.html"):
-            f = codecs.open(source_filepath, "r", "utf8")
-            data = f.read()
-            f.close()
-            t = Template(data, lookup=template_lookup, uri=source_filepath)
-            f = codecs.open(dest_filepath, "w", "utf8")
-            f.write(t.render_unicode(
-                root_path=RootPath(os.path.relpath(root_path, os.path.dirname(source_filepath))),
-                current_page=source_filepath,
-                g=type("Global", (object,), {})
-            ))
-            f.close()
+            render_and_copy(source_filepath, dest_filepath, template_lookup, root_path)
+        elif fnmatch.fnmatch(source_filepath, "*.mako"):
+            render_and_copy(source_filepath, dest_filepath[:-len('.mako')],
+                            template_lookup, root_path)
         else:
             shutil.copy(source_filepath, dest_filepath)
 
 
+def render_and_copy(source, dest, lookup, root_path):
+    f = codecs.open(source, "r", "utf8")
+    data = f.read()
+    f.close()
+    t = Template(data, lookup=lookup, uri=source)
+    f = codecs.open(dest, "w", "utf8")
+    f.write(t.render_unicode(
+        root_path=RootPath(os.path.relpath(root_path, os.path.dirname(source))),
+        current_page=source,
+        g=type("Global", (object,), {})
+    ))
+    f.close()
+
+
 def main():
     parser = argparse.ArgumentParser(
         description="""A tool to generate a static web site, with Mako templates."""