]> Devi Nivas Git - chevron.git/commitdiff
Move get_partial out of render
authornoah morrison <noah@morrison.ph>
Sat, 29 Nov 2014 21:40:07 +0000 (16:40 -0500)
committernoah morrison <noah@morrison.ph>
Sat, 29 Nov 2014 21:40:07 +0000 (16:40 -0500)
Also "hid" it (Put an underscore in front of it)

chevron/renderer.py

index 49f0363c4786b89c65a08b8f30dd8b15c6c647ba..dca6b1fb93f5bb0a6170609644eddd7e969786ff 100644 (file)
@@ -66,6 +66,29 @@ def _get_key(key, scopes):
     # We couldn't find the key in any of the scopes
     return ''
 
+
+def _get_partial(name, partials_dict, partials_path, partials_ext):
+    """Load a partial"""
+    try:
+        # Maybe the partial is in the dictionary
+        return partials_dict[name]
+    except KeyError:
+        # Nope...
+        try:
+            # Maybe it's in the file system
+            path = partials_path + '/' + name + '.' + partials_ext
+            with open(path, 'r') as partial:
+                return partial.read()
+
+        except IOError:
+            # Alright I give up on you
+            return ''
+
+
+#
+# The main rendering function
+#
+
 def render(template='', data={}, partials_path='.', partials_ext='mustache',
            partials_dict={}, padding=0, def_ldel='{{', def_rdel='}}',
            scopes=None):
@@ -101,23 +124,6 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
     A string containing the rendered template.
     """
 
-    def get_partial(name):
-        """Load a partial"""
-        try:
-            # Maybe the partial is in the dictionary
-            return partials_dict[name]
-        except KeyError:
-            # Nope...
-            try:
-                # Maybe it's in the file system
-                path = partials_path + '/' + name + '.' + partials_ext
-                with open(path, 'r') as partial:
-                    return partial.read()
-
-            except IOError:
-                # Alright I give up on you
-                return ''
-
     # If the template is a list
     if type(template) is list:
         # Then we don't need to tokenize it
@@ -212,7 +218,8 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
         # If we're a partial
         elif tag == 'partial':
             # Load the partial
-            partial = get_partial(key)
+            partial = _get_partial(key, partials_dict,
+                                   partials_path, partials_ext)
 
             # Find how much to pad the partial
             left = output.split('\n')[-1]