Mercurial > hg > MakeItSo
changeset 63:b91133e3b02d
override get_variables for API template; could instead do this in the ctor, alternately
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 06 Jan 2011 17:58:34 -0800 |
parents | 30100690ad3f |
children | c20277dbf8fa |
files | makeitso/makeitso.py makeitso/template.py |
diffstat | 2 files changed, 22 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/makeitso/makeitso.py Thu Jan 06 17:49:40 2011 -0800 +++ b/makeitso/makeitso.py Thu Jan 06 17:58:34 2011 -0800 @@ -134,6 +134,12 @@ tempita.Template.__init__(self, content, name=name) + def get_variables(self, **variables): + """the template's augmented variable set""" + vars = self.defaults.copy() + vars.update(variables) + return vars + def missing(self, **variables): """return additional variables needed""" vars = self.get_variables(**variables) @@ -148,11 +154,6 @@ vars[missed] = '' return missing - def get_variables(self, **variables): - vars = self.defaults.copy() - vars.update(variables) - return vars - def check_missing(self, vars): """ check for missing variables and, if applicable,
--- a/makeitso/template.py Thu Jan 06 17:49:40 2011 -0800 +++ b/makeitso/template.py Thu Jan 06 17:58:34 2011 -0800 @@ -72,12 +72,14 @@ - interactive : whether tointeractively get variables - usedefaults : try to use the default values if not specified """ - + + # boilerplate assert self.templates self.output = output self.interactive = interactive self.location = os.path.dirname(os.path.abspath(__file__)) self.defaults = variables.copy() + self.usedefaults = usedefaults # make a dictionary of the variables for lookup convenience self.vardict = {} @@ -94,14 +96,26 @@ path = os.path.join(self.location, template) assert os.path.exists(template) + def get_variables(self, **variables): + # XXX could do this in the ctor + vars = ContentTemplate.get_variables(self, **variables) + if self.usedefaults: + for variable in self.vars: + if variable.name in vars: + continue + if variable.default is not Undefined: + vars[variable.name] = variable.default + return vars + def missing(self, **variables): + vars = self.get_variables(**variables) missing = set([]) if self.look: pass else: for var in self.vars: if self.usedefaults: - pass + import pdb; pdb.set_trace() else: pass