]> Devi Nivas Git - chevron.git/commitdiff
Updated main function to not need data file
authornoah morrison <noah@morrison.ph>
Wed, 19 Nov 2014 04:42:41 +0000 (23:42 -0500)
committernoah morrison <noah@morrison.ph>
Wed, 19 Nov 2014 04:42:41 +0000 (23:42 -0500)
If no data file is present it defaults to an empty dictionary

chevron/chevron.py
test_spec.py

index 921d8ee3d39ed3b143acfbdbc01d3571cdec6db5..23efd000edf78e4b5ffd4183c7e34005cb3bb151 100755 (executable)
@@ -379,19 +379,22 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
         return output.encode('utf-8')
 
 
-def main(data, template, **kwargs):
-    data = data
-    template = template
-
+def main(template, data=None, **kwargs):
     with open(template, 'r') as template_file:
-        with open(data, 'r') as data_file:
-            args = {
-                'template': template_file,
-                'data': json.load(data_file)
-            }
-
-            args.update(kwargs)
-            return render(**args)
+        if data is not None:
+            data_file = open(data, 'r')
+            data = json.load(data_file)
+            data_file.close()
+        else:
+            data = {}
+
+        args = {
+            'template': template_file,
+            'data': data
+        }
+
+        args.update(kwargs)
+        return render(**args)
 
 
 def cli_main():
index e5c88106306ca8745ea18bde28c467bf44d8f93c..eb780e2837681a6f811bf8f63a8eb84b5e5b6ff5 100755 (executable)
@@ -107,7 +107,7 @@ class ExpandedCoverage(unittest.TestCase):
         self.assertEqual(result, expected)
 
     def test_main(self):
-        result = chevron.main('tests/data.json', 'tests/test.mustache',
+        result = chevron.main('tests/test.mustache', 'tests/data.json',
                               partials_path='tests')
 
         with open('tests/test.rendered', 'r') as f: