# HG changeset patch # User Jeff Hammel # Date 1294093139 28800 # Node ID 9956e13558dd448cb54792081dcd861956221bf9 # Parent 6b4c8f23192ff2dafbdd2bf06620af01e5eaf317 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 diff -r 6b4c8f23192f -r 9956e13558dd makeitso/makeitso.py --- 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""" diff -r 6b4c8f23192f -r 9956e13558dd makeitso/template.py --- /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""" + +