Upload MVP

This commit is contained in:
Jake Howard 2017-03-14 18:38:54 +00:00
parent 0564f2a66f
commit fe8ab3d36c
4 changed files with 69 additions and 0 deletions

0
build.sh Normal file → Executable file
View file

View file

@ -0,0 +1,3 @@
Jinja2==2.9.5
Markdown==2.6.8
PyYAML==3.12

20
test.yml Normal file
View file

@ -0,0 +1,20 @@
---
foo: bar
---
foo: bar
{% for i in range(5) %}
bar{{ i }}: baz
{% endfor %}
test: |
test1
{% for i in range(10) %}
- test2
{% endfor %}
food:
test:
- test 2
test 2:
- test
---
bar: biz

46
ymd/main.py Normal file
View file

@ -0,0 +1,46 @@
from jinja2 import Template
import yaml
import markdown
def parse_item(item, h):
item_type = type(item)
if item_type is list:
if len(item) == 1:
return parse_item(item[0], h+1)
if len(item) == 0:
return ''
return parse_item('\n'.join(['- ' + str(sub_item) for sub_item in item]), h+1)
if item_type is dict:
return {
"<h{0}>{1}</h{0}>".format(h, key): parse_item(value, h+1) for key, value in item.items()
}
if item_type in [int, float]:
return item
return markdown.markdown(str(item))
def output(item):
item_type = type(item)
if item_type is list:
[output(sub_item) for sub_item in item]
return
if item_type is dict:
for key, value in item.items():
output(key)
output(value)
return
print(item)
with open('test.yml') as f:
data = ''.join(f.read())
template = Template(data, trim_blocks=True, lstrip_blocks=True)
raw = template.render()
formatted = list(yaml.load_all(raw))
if len(formatted) > 1:
meta = formatted[0]
for doc in formatted[1:]:
output(parse_item(doc, 1))
else:
output(parse_item(formatted, 1))