]> Devi Nivas Git - chevron.git/commitdiff
Added some documentation
authornoah morrison <noah@morrison.ph>
Mon, 3 Nov 2014 04:43:51 +0000 (23:43 -0500)
committernoah morrison <noah@morrison.ph>
Mon, 3 Nov 2014 04:43:51 +0000 (23:43 -0500)
And fixed some pep8 problems.

also... the code seems to not be rendering right...
how long has that been happening?

chevron.py
test_spec.py

index 996b02b497cae6a9dd1a60a666b24dd89b16933d..a81497cf491c4054d49d26bafbfbb8d68590706c 100755 (executable)
@@ -62,7 +62,6 @@ def tokenize(template):
 
         return literal
 
-
     tag_types = {
         '!': 'comment',
         '#': 'section',
@@ -124,6 +123,31 @@ def tokenize(template):
 
 
 def render(template, data, partials_path='.', partials_ext='mustache'):
+    """Render a mustache template.
+
+    Renders a mustache template with a data scope and partial capability.
+    Given the file structure...
+    .
+    |- main.py
+    |- main.ms
+    |- partials
+     |- part.ms
+
+    then main.py would make the following call:
+
+    render(open('main.ms', 'r'), {...}, 'partials', 'ms')
+
+    Arguments:
+    template      -- A file-like object or a string containing the template
+    data          -- A python dictionary with your data scope
+    partials_path -- The path to where your partials are stored
+                     (defaults to '.')
+    partials_ext  -- The extension that you want the parser to look for
+                     (defaults to 'mustache')
+
+    Returns:
+    A string containing the rendered template.
+    """
     def get_key(key):
         for scope in scopes:
             try:
index 484cf73ca686f663d44f9965cf17f5028c4a2c92..f28ecbbb223a62b230a782fa8653beadf6d94dac 100755 (executable)
@@ -18,7 +18,8 @@ def _test_case_from_path(json_path):
             def test_case(self):
                 self.assertEqual(STACHE(obj['template'], obj['data']),
                                  obj['expected'])
-            test_case.__doc__ = 'suite: {}    desc: {}'.format(spec, obj['desc'])
+            test_case.__doc__ = 'suite: {}    desc: {}'.format(spec,
+                                                               obj['desc'])
             return test_case
         with open(json_path, 'r') as f:
             yaml = json.load(f)