#!/usr/bin/env python
"""
Usage: %s yamlfile
The slide show output is made in an output folder; the name of which is
derived from the yaml file
"""
import sys
sys.path.append('/home/vsbabu/site-packages/')
from slides import Lecture, Slide, Bullet, SubBullet, PRE
import yaml
from types import ListType, DictType
import re
def lecture(data):
title = data[0]['title']
copyright = data[0]['copyright']
publish_date = data[0]['publish_date']
author = data[0]['author']
return Lecture(title, author, publish_date, copyright, *slides(data[1:]))
def slides(items):
return [slide(item) for item in items]
def slide(item):
only_key = item.keys()[0]
return Slide(only_key, *bullets(item[only_key]))
def bullets(items):
return [bullet(item) for item in items]
def bullet(item):
item = listify(item)
return Bullet(*texts(item))
def texts(items):
return [text(item) for item in items]
def text(item):
if type(item) is ListType:
return SubBullet(*bullets(item))
if type(item) is type("") and re.search("\n", item):
return PRE(item)
return item
def listify(data):
if type(data) is DictType:
only_key = data.keys()[0]
return [only_key] + [data[only_key]]
if type(data) is not ListType:
return [data]
return data
class Link:
def __init__(self, data):
self.html = "<a href='%s'>%s</a>" % (data['href'], data['label'])
def tohtml(self):
return self.html
class Resolver:
def read(data):
return [open(data).read()]
def link(data):
return Link(data)
resolvers = {
'!!read': read,
'!!link': link,
}
def resolveType(self, data, typestring):
return Resolver.resolvers[typestring](data)
if __name__ == '__main__':
import sys
import os
if len(sys.argv) == 2:
datafile = sys.argv[1]
data = list(yaml.loadFile(datafile, Resolver()))
lecture(data).render('./', "index-%d.html", css="../main.css")
else:
print __doc__ % sys.argv[0]