Mercurial > hg > MakeItSo
annotate makeitso/template.py @ 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 | |
| children | 73dac34d2692 | 
| rev | line source | 
|---|---|
| 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
1 """ | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
2 basic API template class | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
3 """ | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
4 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
5 import sys | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
6 from makeitso import ContentTemplate | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
7 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
8 class Variable(object): | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
9 """variable object for MakeItSo templates""" | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
10 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
11 def __init__(self, name, default=None, description=None, | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
12 cast=None): | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
13 self.name = name | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
14 self.default = default | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
15 self.description = description | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
16 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
17 # TODO (maybe): get cast from default variable type if not None | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
18 self.cast = cast | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
19 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
20 self._set = False | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
21 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
22 def set(self, value): | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
23 if self.cast: | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
24 self.value = self.cast(value) | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
25 else: | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
26 self.value = value | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
27 self._set = True | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
28 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
29 def read(self, fd=sys.stdout): | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
30 """prompt and read the variable from stdin""" | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
31 fd.write(self.display()) | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
32 self.set(raw_input()) | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
33 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
34 def display(self): | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
35 description = self.description or self.name | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
36 if self.default: | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
37 return 'Enter %s [DEFAULT: %s]:' % (description, repr(self.default)) | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
38 else: | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
39 return 'Enter %s:' % description | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
40 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
41 class MakeItSoTemplate(object): | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
42 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
43 def pre(self, **variables): | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
44 """do stuff before interpolation""" | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
45 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
46 def post(self, **variables): | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
47 """do stuff after interpolation""" | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
48 | 
| 
 
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
 
Jeff Hammel <jhammel@mozilla.com> 
parents:  
diff
changeset
 | 
49 | 
