Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/haarcuba/yaml_mako

use mako templating in your YAML files
https://github.com/haarcuba/yaml_mako

Last synced: about 16 hours ago
JSON representation

use mako templating in your YAML files

Awesome Lists containing this project

README

        

# YAML-MAKO

These are the facts:

* [Mako](http://www.makotemplates.org/) templates are great.
* [YAML](https://en.wikipedia.org/wiki/YAML) is great.

Let's have them both!

# Installation

$ pip install yaml-mako

# Example

Here's our yaml document, describint a general subscription, say to a newsletter:

```yaml
---
name: "subscription"
details:
start time: ${start_date}
end time: ${end_date}
comment: dates should appear above after temlating
```

If you load this as plain `YAML`, you will get the equivalent of

```python
{'details': {'comment': 'dates should appear above after temlating',
'end time': '${end_date}',
'start time': '${start_date}'},
'name': 'subscription'}
```

Using `yaml-mako` you can to this:

```python
import yaml_mako
import pprint
import datetime

stream = open('example.yaml')
today = datetime.date.today()
tomorrow = today + datetime.timedelta(1)
pprint.pprint(yaml_mako.load(stream, start_date = today, end_date = tomorrow))
```

And we get:

```python
{'details': {'comment': 'dates should appear above after temlating',
'end time': datetime.date(2017, 1, 24),
'start time': datetime.date(2017, 1, 23)},
'name': 'subscription'}
```