Mercurial > piecrust2
comparison piecrust/sources/base.py @ 11:617191dec18e
Fixes for Windows, make `findPagePath` return a ref path.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 18 Aug 2014 16:47:44 -0700 |
parents | 343d08ef5668 |
children | 105f24f490cb |
comparison
equal
deleted
inserted
replaced
10:cd35d356ccce | 11:617191dec18e |
---|---|
292 def __init__(self, app, name, config): | 292 def __init__(self, app, name, config): |
293 super(SimplePageSource, self).__init__(app, name, config) | 293 super(SimplePageSource, self).__init__(app, name, config) |
294 self.fs_endpoint = config.get('fs_endpoint', name) | 294 self.fs_endpoint = config.get('fs_endpoint', name) |
295 self.fs_endpoint_path = os.path.join(self.root_dir, CONTENT_DIR, self.fs_endpoint) | 295 self.fs_endpoint_path = os.path.join(self.root_dir, CONTENT_DIR, self.fs_endpoint) |
296 self.supported_extensions = list(app.config.get('site/auto_formats').keys()) | 296 self.supported_extensions = list(app.config.get('site/auto_formats').keys()) |
297 self.default_auto_format = app.config.get('site/default_auto_format') | |
297 | 298 |
298 def buildPageFactories(self): | 299 def buildPageFactories(self): |
299 logger.debug("Scanning for pages in: %s" % self.fs_endpoint_path) | 300 logger.debug("Scanning for pages in: %s" % self.fs_endpoint_path) |
300 if not os.path.isdir(self.fs_endpoint_path): | 301 if not os.path.isdir(self.fs_endpoint_path): |
301 raise InvalidFileSystemEndpointError(self.name, self.fs_endpoint_path) | 302 raise InvalidFileSystemEndpointError(self.name, self.fs_endpoint_path) |
311 slug = '' | 312 slug = '' |
312 metadata = {'path': slug} | 313 metadata = {'path': slug} |
313 fac_path = f | 314 fac_path = f |
314 if rel_dirpath != '.': | 315 if rel_dirpath != '.': |
315 fac_path = os.path.join(rel_dirpath, f) | 316 fac_path = os.path.join(rel_dirpath, f) |
317 fac_path = fac_path.replace('\\', '/') | |
316 yield PageFactory(self, fac_path, metadata) | 318 yield PageFactory(self, fac_path, metadata) |
317 | 319 |
318 def resolveRef(self, ref_path): | 320 def resolveRef(self, ref_path): |
319 return os.path.join(self.fs_endpoint_path, ref_path) | 321 return os.path.normpath( |
322 os.path.join(self.fs_endpoint_path, ref_path)) | |
320 | 323 |
321 def findPagePath(self, metadata, mode): | 324 def findPagePath(self, metadata, mode): |
322 uri_path = metadata['path'] | 325 uri_path = metadata['path'] |
323 if uri_path == '': | 326 if uri_path == '': |
324 uri_path = '_index' | 327 uri_path = '_index' |
325 path = os.path.join(self.fs_endpoint_path, uri_path) | 328 path = os.path.normpath(os.path.join(self.fs_endpoint_path, uri_path)) |
326 _, ext = os.path.splitext(path) | 329 _, ext = os.path.splitext(path) |
327 | 330 |
328 if mode == MODE_CREATING: | 331 if mode == MODE_CREATING: |
329 if ext == '': | 332 if ext == '': |
330 return '%s.*' % path | 333 path = '%s.%s' % (path, self.default_auto_format) |
331 return path, metadata | 334 rel_path = os.path.relpath(path, self.fs_endpoint_path) |
335 rel_path = rel_path.replace('\\', '/') | |
336 return rel_path, metadata | |
332 | 337 |
333 if ext == '': | 338 if ext == '': |
334 paths_to_check = ['%s.%s' % (path, e) | 339 paths_to_check = ['%s.%s' % (path, e) |
335 for e in self.supported_extensions] | 340 for e in self.supported_extensions] |
336 else: | 341 else: |
337 paths_to_check = [path] | 342 paths_to_check = [path] |
338 for path in paths_to_check: | 343 for path in paths_to_check: |
339 if os.path.isfile(path): | 344 if os.path.isfile(path): |
340 return path, metadata | 345 rel_path = os.path.relpath(path, self.fs_endpoint_path) |
346 rel_path = rel_path.replace('\\', '/') | |
347 return rel_path, metadata | |
341 | 348 |
342 return None, None | 349 return None, None |
343 | 350 |
344 def _filterPageDirname(self, d): | 351 def _filterPageDirname(self, d): |
345 return not d.endswith('-assets') | 352 return not d.endswith('-assets') |
391 def __init__(self, it): | 398 def __init__(self, it): |
392 self.it = it | 399 self.it = it |
393 | 400 |
394 def __iter__(self): | 401 def __iter__(self): |
395 for page in self.it: | 402 for page in self.it: |
396 yield PaginationData(page) | 403 if page is None: |
397 | 404 yield None |
405 else: | |
406 yield PaginationData(page) | |
407 |