]> Devi Nivas Git - chevron.git/commitdiff
Allow for custom falsy data types
authorNoah Morrison <noah@morrison.ph>
Fri, 24 Aug 2018 00:22:34 +0000 (20:22 -0400)
committerNoah Morrison <noah@morrison.ph>
Fri, 24 Aug 2018 00:22:34 +0000 (20:22 -0400)
Helps resolve Issue #35
This allows for a custom data type be outputed even when falsy

chevron/renderer.py

index 4286f5bd5c1768430882d870f5f31942ead35d1c..9392bf08d1abde3e58864d5e7cbea07b2cc71718 100644 (file)
@@ -65,7 +65,13 @@ def _get_key(key, scopes):
             if scope is False:
                 return False
 
-            return scope or ''
+            try:
+                # This allows for custom falsy data types
+                # https://github.com/noahmorrison/chevron/issues/35
+                if scope._CHEVRON_return_scope_when_falsy:
+                    return scope
+            except AttributeError:
+                return scope or ''
         except (AttributeError, KeyError):
             # We couldn't find the key in the current scope
             # We'll try again on the next pass