Skip to content

haarcuba/yaml_mako

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4c77bee · Feb 26, 2020

History

15 Commits
Feb 26, 2020
Jan 22, 2017
Feb 26, 2020
Jan 22, 2017
Feb 26, 2020
Feb 26, 2020

Repository files navigation

YAML-MAKO

These are the facts:

  • Mako templates are great.
  • 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:

---
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

{'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:

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:

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

About

use mako templating in your YAML files

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages