comparison makeitso/template.py @ 122:b2152efec89a

get the description from the docstring if applicable
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 19 Jan 2011 18:24:58 -0800
parents c3b8ce33d3ad
children cfd4f1e91090
comparison
equal deleted inserted replaced
121:d28cde6c942e 122:b2152efec89a
10 class Undefined(object): 10 class Undefined(object):
11 """marker class for variables""" 11 """marker class for variables"""
12 def __nonzero__(self): 12 def __nonzero__(self):
13 return False 13 return False
14 Undefined = Undefined() # singleton 14 Undefined = Undefined() # singleton
15
15 16
16 class Variable(object): 17 class Variable(object):
17 """variable object for MakeItSo templates""" 18 """variable object for MakeItSo templates"""
18 19
19 def __init__(self, name, description=None, default=Undefined, 20 def __init__(self, name, description=None, default=Undefined,
122 path = template 123 path = template
123 else: 124 else:
124 path = os.path.join(self.location, template) 125 path = os.path.join(self.location, template)
125 assert os.path.exists(path), "%s does not exist" % path 126 assert os.path.exists(path), "%s does not exist" % path
126 self._templates.append(path) 127 self._templates.append(path)
128
129 @classmethod
130 def get_description(cls):
131 if hasattr(cls, 'description'):
132 if cls.description:
133 return cls.description
134 if hasattr(cls, '__doc__'):
135 return cls.__doc__
127 136
128 def get_variables(self, **variables): 137 def get_variables(self, **variables):
129 # XXX could do this in the ctor 138 # XXX could do this in the ctor
130 vars = ContentTemplate.get_variables(self, **variables) 139 vars = ContentTemplate.get_variables(self, **variables)
131 if self.usedefaults: 140 if self.usedefaults: