22"""
33
44todo = """
5+ - Document parameters to Template.render() method
56- Add tests for Loader.load() method
67- Most methods should have a "default" arg to supply a value
78 when none appears in the hyperdb or request.
@@ -88,7 +89,43 @@ def precompile(self):
8889 """ This method may be called when tracker is loaded to precompile
8990 templates that support this ability.
9091 """
91- # [ ] move implementation out of API
92+ pass
93+
94+ def load (self , tplname ):
95+ """ Load template and return template object with render() method.
96+
97+ "tplname" is a template name. For filesystem loaders it is a
98+ filename without extensions, typically in the "classname.view"
99+ format.
100+ """
101+ raise NotImplementedError
102+
103+ def check (self , name ):
104+ """ Check if template with the given name exists. Should return
105+ false if template can not be found.
106+ """
107+ raise NotImplementedError
108+
109+ class TALLoaderBase (LoaderBase ):
110+ """ Common methods for the legacy TAL loaders."""
111+
112+ def __init__ (self , dir ):
113+ self .dir = dir
114+
115+ def _find (self , name ):
116+ """ Find template, return full path and filename of the
117+ template if it is found, None otherwise."""
118+ for extension in ['' , '.html' , '.xml' ]:
119+ f = name + extension
120+ src = os .path .join (self .dir , f )
121+ if os .path .exists (src ):
122+ return (src , f )
123+
124+ def check (self , name ):
125+ return bool (self ._find (name ))
126+
127+ def precompile (self ):
128+ """ Precompile templates in load directory by loading them """
92129 for filename in os .listdir (self .dir ):
93130 # skip subdirs
94131 if os .path .isdir (filename ):
@@ -105,24 +142,8 @@ def precompile(self):
105142 filename = filename [:- len (extension )]
106143 self .load (filename )
107144
108- def load (self , tplname ):
109- """ Load template and return template object with render() method.
110-
111- "tplname" is a template name. For filesystem loaders it is a
112- filename without extensions, typically in the "classname.view"
113- format.
114- """
115- raise NotImplementedError
116-
117- def check (self , name ):
118- """ Check if template with the given name exists. Return None or
119- a tuple (src, filename) that can be reused in load() method.
120- """
121- raise NotImplementedError
122-
123145 def __getitem__ (self , name ):
124146 """Special method to access templates by loader['name']"""
125- # [ ] not sure if it is needed for anything except TAL templates
126147 try :
127148 return self .load (name )
128149 except NoTemplate , message :
0 commit comments