Mercurial > hg > MakeItSo
changeset 41:9956e13558dd
stub out what API templates will look like; put these in a separate file as theres no reason to clutter up the command line entry point any further
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 03 Jan 2011 14:18:59 -0800 |
parents | 6b4c8f23192f |
children | 73dac34d2692 |
files | makeitso/makeitso.py makeitso/template.py |
diffstat | 2 files changed, 50 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/makeitso/makeitso.py Sun Jan 02 00:48:58 2011 -0800 +++ b/makeitso/makeitso.py Mon Jan 03 14:18:59 2011 -0800 @@ -324,7 +324,7 @@ for template in self.templates: template.substitute(**variables) -### command line stuff +### command line interface def invocation(url, **variables): """returns a string appropriate for TTW invocation"""
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/makeitso/template.py Mon Jan 03 14:18:59 2011 -0800 @@ -0,0 +1,49 @@ +""" +basic API template class +""" + +import sys +from makeitso import ContentTemplate + +class Variable(object): + """variable object for MakeItSo templates""" + + def __init__(self, name, default=None, description=None, + cast=None): + self.name = name + self.default = default + self.description = description + + # TODO (maybe): get cast from default variable type if not None + self.cast = cast + + self._set = False + + def set(self, value): + if self.cast: + self.value = self.cast(value) + else: + self.value = value + self._set = True + + def read(self, fd=sys.stdout): + """prompt and read the variable from stdin""" + fd.write(self.display()) + self.set(raw_input()) + + def display(self): + description = self.description or self.name + if self.default: + return 'Enter %s [DEFAULT: %s]:' % (description, repr(self.default)) + else: + return 'Enter %s:' % description + +class MakeItSoTemplate(object): + + def pre(self, **variables): + """do stuff before interpolation""" + + def post(self, **variables): + """do stuff after interpolation""" + +