comparison makeitso/template.py @ 42:73dac34d2692

more stubbing of API class; first get something off the ground; then rewrite
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 04 Jan 2011 07:38:49 -0800
parents 9956e13558dd
children 6e08cca7d656
comparison
equal deleted inserted replaced
41:9956e13558dd 42:73dac34d2692
1 """ 1 """
2 basic API template class 2 basic API template class
3 """ 3 """
4 4
5 import os
5 import sys 6 import sys
6 from makeitso import ContentTemplate 7 from makeitso import ContentTemplate
8 from makeitso import PolyTemplate
7 9
8 class Variable(object): 10 class Variable(object):
9 """variable object for MakeItSo templates""" 11 """variable object for MakeItSo templates"""
10 12
11 def __init__(self, name, default=None, description=None, 13 def __init__(self, name, default=None, description=None,
36 if self.default: 38 if self.default:
37 return 'Enter %s [DEFAULT: %s]:' % (description, repr(self.default)) 39 return 'Enter %s [DEFAULT: %s]:' % (description, repr(self.default))
38 else: 40 else:
39 return 'Enter %s:' % description 41 return 'Enter %s:' % description
40 42
41 class MakeItSoTemplate(object): 43 class MakeItSoTemplate(ContentTemplate):
44 """API template for MakeItSo"""
45
46 # name of the template
47 name = ''
48
49 # templates to interpolate
50 # paths are relative to __file__ unless absolute or URIs
51 templates = []
52
53 # variables
54 vars = []
55
56 # inspect the templates for more variables
57 look = False
58
59 def __init__(self, output=None, interactive=True, **variables):
60 assert self.templates
61 self.output = output
62 self.interactive = interactive
63 self.location = os.path.dirnme(os.path.abspath(__file__))
64 self.defaults = variables.copy
65
66 # ensure all of these templates exist
67 for template in self.templates:
68 if template.startswith('http://') or template.startswith('https://'):
69 continue
70 if os.path.isabs(template):
71 path = template
72 else:
73 path = os.path.join(self.location, template)
74 assert os.path.exists(template)
42 75
43 def pre(self, **variables): 76 def pre(self, **variables):
44 """do stuff before interpolation""" 77 """do stuff before interpolation"""
45 78
46 def post(self, **variables): 79 def post(self, **variables):
47 """do stuff after interpolation""" 80 """do stuff after interpolation"""
48 81
49 82
83 class PasteScriptTemplate(MakeItSoTemplate):
84 """template for backwards compatability with PasteScript"""