comparison decoupage/web.py @ 85:3262010f7f79

add command line serving
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 28 Dec 2013 21:56:06 -0800
parents 95820b36d7e3
children ced29a73c561
comparison
equal deleted inserted replaced
84:95820b36d7e3 85:3262010f7f79
187 data['directory'] = directory 187 data['directory'] = directory
188 data['css'] = () 188 data['css'] = ()
189 data['scripts'] = () 189 data['scripts'] = ()
190 190
191 # apply formatters 191 # apply formatters
192 # XXX this should be cached if not self.auto_reload 192 formatters = self.get_formatters(path)
193 if '/formatters' in conf: 193 for formatter in formatters:
194 # ordered list of formatters to be applied first
195 formatters = [ i for i in conf['/formatters'].split()
196 if i in self.formatters ]
197 else:
198 formatters = []
199 for key in conf:
200 if key.startswith('/'):
201 key = key[1:]
202 if key in self.formatters and key not in formatters:
203 formatters.append(key)
204 for name in formatters:
205 formatter = self.formatters[name](conf.get('/%s' % name, ''))
206 formatter(request, data) 194 formatter(request, data)
207 195
208 # return an alternate format if specified 196 # return an alternate format if specified
209 # decoupage.formats should return a 2-tuple: 197 # decoupage.formats should return a 2-tuple:
210 # (content_type, body) 198 # (content_type, body)
350 self._conf = {} 338 self._conf = {}
351 self._conf[path_tuple] = conf 339 self._conf[path_tuple] = conf
352 340
353 return conf 341 return conf
354 342
355 def fmtrs(self, path): 343 def get_formatters(self, path):
356 formatters = [] 344 """return formatters for a path"""
357 for key, value in self.conf(path).items(): 345 retval = []
346 conf = self.conf(path)
347 # apply formatters
348 # XXX this should be cached if not self.auto_reload
349 if '/formatters' in conf:
350 # ordered list of formatters to be applied first
351 formatters = [ i for i in conf['/formatters'].split()
352 if i in self.formatters ]
353 else:
354 formatters = []
355 for key in conf:
358 if key.startswith('/'): 356 if key.startswith('/'):
359 key = key[1:] 357 key = key[1:]
360 if key in self.formatters: 358 if key in self.formatters and key not in formatters:
361 formatter = self.formatters[key](value) 359 formatters.append(key)
362 360 for name in formatters:
361 retval.append(self.formatters[name](conf.get('/%s' % name, '')))
362