Skip to content

Commit

Permalink
Adding a representer for yaml dumping of Documents.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoramite committed Jul 19, 2017
1 parent 4557301 commit 7c1f309
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions grow/pods/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
import os
import re
import yaml


PATH_LOCALE_REGEX = re.compile(r'@([^-_]+)([-_]?)([^\.]*)(\.[^\.]+)$')
Expand Down Expand Up @@ -455,3 +456,10 @@ def write(self, fields=utils.SENTINEL, body=utils.SENTINEL):
self.format.update(fields=fields, content=body)
new_content = self.format.to_raw_content()
self.pod.write_file(self.pod_path, new_content)


# Allow the yaml dump to write out a representation of the document.
def doc_representer(dumper, data):
return dumper.represent_scalar(u'!g.doc', data.pod_path)

yaml.SafeDumper.add_representer(Document, doc_representer)

0 comments on commit 7c1f309

Please sign in to comment.