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

chevron/renderer.py

index 2879625b1dc4f099ec1eb46bad19d545ea17fec6..e707bf6cde9676dd992c413a2f0fa1224c5503f2 100644 (file)
@@ -21,6 +21,25 @@ except:
     python3 = True
 
 
+#
+# Helper functions
+#
+
+def _html_escape(string):
+    """HTML escape all of these " & < >"""
+
+    html_codes = {
+        '"': '&quot;',
+        '<': '&lt;',
+        '>': '&gt;',
+    }
+
+    # & must be handled first
+    string = string.replace('&', '&amp;')
+    for char in html_codes:
+        string = string.replace(char, html_codes[char])
+    return string
+
 def render(template='', data={}, partials_path='.', partials_ext='mustache',
            partials_dict={}, padding=0, def_ldel='{{', def_rdel='}}',
            scopes=None):
@@ -56,21 +75,6 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
     A string containing the rendered template.
     """
 
-    def html_escape(string):
-        """HTML escape all of these " & < >"""
-
-        html_codes = {
-            '"': '&quot;',
-            '<': '&lt;',
-            '>': '&gt;',
-        }
-
-        # & must be handled first
-        string = string.replace('&', '&amp;')
-        for char in html_codes:
-            string = string.replace(char, html_codes[char])
-        return string
-
     def get_key(key):
         """Get a key from the current scope"""
 
@@ -161,7 +165,7 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
             thing = get_key(key)
             if type(thing) != unicode:
                 thing = unicode(str(thing), 'utf-8')
-            output += html_escape(thing)
+            output += _html_escape(thing)
 
         # If we're a no html escape tag
         elif tag == 'no escape':