summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2021-03-19 23:06:08 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2021-03-19 23:06:08 +0100
commit16f62d709c2150abca46c111d07c5d7052111370 (patch)
tree0abc7f4ea3f6c218e115fa65c246b3fc0e7103ca
parent897bd5e601f9a602b2e0aef592780c63d3730048 (diff)
More improvements to to_yaml
-rw-r--r--lesana/templating.py7
-rw-r--r--tests/test_templating.py2
2 files changed, 7 insertions, 2 deletions
diff --git a/lesana/templating.py b/lesana/templating.py
index 8ff9fcb..95c6146 100644
--- a/lesana/templating.py
+++ b/lesana/templating.py
@@ -28,8 +28,11 @@ def to_yaml(data):
data = ruamel.yaml.scalarstring.LiteralScalarString(data + "\n")
elif isinstance(data, decimal.Decimal):
data = str(data)
+ elif data is None:
+ return 'null'
yaml = ruamel.yaml.YAML()
s_io = io.StringIO()
- yaml.dump(data, s_io)
- res = s_io.getvalue().strip('...\n').strip()
+ yaml.dump({'data': data}, s_io)
+ res = s_io.getvalue()
+ res = res.lstrip('{data:').lstrip().strip()
return res
diff --git a/tests/test_templating.py b/tests/test_templating.py
index aadcf66..57d7f7a 100644
--- a/tests/test_templating.py
+++ b/tests/test_templating.py
@@ -52,6 +52,8 @@ class testFilters(unittest.TestCase):
res = templating.to_yaml(s)
self.assertTrue(res.startswith("|\n"))
self.assertNotIn('\n', res.lstrip("|\n"))
+ for line in res.lstrip("|\n").split('\n'):
+ self.assertTrue(line.startswith(" "))
if __name__ == '__main__':