From a5d4842f9cb03bec44d63c06ae209f7c9838882f Mon Sep 17 00:00:00 2001
From: Mike Bayer <mike_mp@zzzcomputing.com>
Date: Mon, 25 Jun 2007 22:01:43 +0000
Subject: [PATCH] - fix to turbogears plugin to work with dot-separated names
 (i.e. load_template('foo.bar')).  also takes file extension as a keyword
 argument (default is 'mak').

---
 CHANGES                    |  3 +++
 lib/mako/ext/turbogears.py |  6 +++---
 test/alltests.py           |  7 ++++---
 test/tgplugin.py           | 38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 6 deletions(-)
 create mode 100644 test/tgplugin.py

diff --git a/CHANGES b/CHANGES
index 58194a9..4017fe6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,9 @@ with user code
 - added a Babel (http://babel.edgewall.org/) extractor entry
 point, allowing extraction of gettext messages directly from
 mako templates via Babel [ticket:45]
+- fix to turbogears plugin to work with dot-separated names
+(i.e. load_template('foo.bar')).  also takes file extension
+as a keyword argument (default is 'mak').
 
 0.1.7
 - one small fix to the unit tests to support python 2.3
diff --git a/lib/mako/ext/turbogears.py b/lib/mako/ext/turbogears.py
index c98893e..035377f 100644
--- a/lib/mako/ext/turbogears.py
+++ b/lib/mako/ext/turbogears.py
@@ -4,10 +4,10 @@ from mako.template import Template
 
 class TGPlugin(object):
     """TurboGears compatible Template Plugin."""
-    extension = 'mak'
 
-    def __init__(self, extra_vars_func=None, options=None):
+    def __init__(self, extra_vars_func=None, options=None, extension='mak'):
         self.extra_vars_func = extra_vars_func
+        self.extension = extension
         if not options:
             options = {}
 
@@ -26,7 +26,7 @@ class TGPlugin(object):
         if template_string is not None:
             return Template(template_string, **self.tmpl_options)
         # Translate TG dot notation to normal / template path
-        if '/' not in templatename and '.' not in templatename:
+        if '/' not in templatename:
             templatename = '/' + templatename.replace('.', '/') + '.' + self.extension
 
         # Lookup template
diff --git a/test/alltests.py b/test/alltests.py
index 59bdb1b..a60c8c9 100644
--- a/test/alltests.py
+++ b/test/alltests.py
@@ -13,9 +13,10 @@ def suite():
         'filters',
         'inheritance',
         'call',
-	'cache',
-	'exceptions_',
-	'babelplugin'
+        'cache',
+        'exceptions_',
+        'babelplugin',
+        'tgplugin'
         )
     alltests = unittest.TestSuite()
     for name in modules_to_test:
diff --git a/test/tgplugin.py b/test/tgplugin.py
new file mode 100644
index 0000000..cc8771b
--- /dev/null
+++ b/test/tgplugin.py
@@ -0,0 +1,38 @@
+import unittest
+
+from mako.ext.turbogears import TGPlugin
+from util import flatten_result, result_lines
+
+tl = TGPlugin(options=dict(directories=['./test_htdocs']), extension='html')
+
+class TestTGPlugun(unittest.TestCase):
+    def test_basic(self):
+        t = tl.load_template('/index.html')
+        assert result_lines(t.render()) == [
+            "this is index"
+        ]
+    def test_subdir(self):
+        t = tl.load_template('/subdir/index.html')
+        assert result_lines(t.render()) == [
+            "this is sub index",
+            "this is include 2"
+
+        ]
+
+        assert tl.load_template('/subdir/index.html').module_id == '_subdir_index_html'
+
+    def test_basic_dot(self):
+        t = tl.load_template('index')
+        assert result_lines(t.render()) == [
+            "this is index"
+        ]
+    def test_subdir_dot(self):
+        t = tl.load_template('subdir.index')
+        assert result_lines(t.render()) == [
+            "this is sub index",
+            "this is include 2"
+
+        ]
+
+        assert tl.load_template('subdir.index').module_id == '_subdir_index_html'
+        
\ No newline at end of file
-- 
GitLab