Skip to content

Instantly share code, notes, and snippets.

@jbek7
Last active April 20, 2019 20:00
Show Gist options
  • Save jbek7/5934478c89eacd95cf4499876147e817 to your computer and use it in GitHub Desktop.
Save jbek7/5934478c89eacd95cf4499876147e817 to your computer and use it in GitHub Desktop.
Custom Jinja filter for nice order preserved YAML
#!/usr/bin/python
import oyaml as yaml
import os
class FilterModule(object):
def filters(self):
return {
'to_yaml_preserve_order': self.to_yaml_preserve_order
}
def to_yaml_preserve_order(self, file_path):
data = yaml.load(open(os.path.abspath(file_path)))
yaml_dump = yaml.dump(data)
return yaml_dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment