Mercurial > piecrust2
comparison piecrust/sources/base.py @ 230:016d42c23ba9
internal: Make the simple page source use `slug` everywhere.
Before, it would use `slug` in some places, and `path` in other places, which
would be quite confusing.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 11 Feb 2015 08:29:09 -0800 |
parents | e9dc18a275ff |
children | 4dce0e61b48c |
comparison
equal
deleted
inserted
replaced
229:a951cd4ef361 | 230:016d42c23ba9 |
---|---|
334 for f in filter(self._filterPageFilename, filenames): | 334 for f in filter(self._filterPageFilename, filenames): |
335 fac_path = f | 335 fac_path = f |
336 if rel_dirpath != '.': | 336 if rel_dirpath != '.': |
337 fac_path = os.path.join(rel_dirpath, f) | 337 fac_path = os.path.join(rel_dirpath, f) |
338 slug = self._makeSlug(fac_path) | 338 slug = self._makeSlug(fac_path) |
339 metadata = {'path': slug} | 339 metadata = {'slug': slug} |
340 fac_path = fac_path.replace('\\', '/') | 340 fac_path = fac_path.replace('\\', '/') |
341 self._populateMetadata(fac_path, metadata) | 341 self._populateMetadata(fac_path, metadata) |
342 yield PageFactory(self, fac_path, metadata) | 342 yield PageFactory(self, fac_path, metadata) |
343 | 343 |
344 def resolveRef(self, ref_path): | 344 def resolveRef(self, ref_path): |
345 return os.path.normpath( | 345 return os.path.normpath( |
346 os.path.join(self.fs_endpoint_path, ref_path.lstrip("\\/"))) | 346 os.path.join(self.fs_endpoint_path, ref_path.lstrip("\\/"))) |
347 | 347 |
348 def findPagePath(self, metadata, mode): | 348 def findPagePath(self, metadata, mode): |
349 uri_path = metadata.setdefault('path', '') | 349 uri_path = metadata.get('slug', '') |
350 if not uri_path: | 350 if not uri_path: |
351 uri_path = '_index' | 351 uri_path = '_index' |
352 path = os.path.normpath(os.path.join(self.fs_endpoint_path, uri_path)) | 352 path = os.path.join(self.fs_endpoint_path, uri_path) |
353 _, ext = os.path.splitext(path) | 353 _, ext = os.path.splitext(path) |
354 | 354 |
355 if mode == MODE_CREATING: | 355 if mode == MODE_CREATING: |
356 if ext == '': | 356 if ext == '': |
357 path = '%s.%s' % (path, self.default_auto_format) | 357 path = '%s.%s' % (path, self.default_auto_format) |
385 rel_subdir = os.path.join(rel_path, name) | 385 rel_subdir = os.path.join(rel_path, name) |
386 items.append((True, name, rel_subdir)) | 386 items.append((True, name, rel_subdir)) |
387 else: | 387 else: |
388 if self._filterPageFilename(name): | 388 if self._filterPageFilename(name): |
389 slug = self._makeSlug(os.path.join(rel_path, name)) | 389 slug = self._makeSlug(os.path.join(rel_path, name)) |
390 metadata = {'path': slug} | 390 metadata = {'slug': slug} |
391 | 391 |
392 fac_path = name | 392 fac_path = name |
393 if rel_path != '.': | 393 if rel_path != '.': |
394 fac_path = os.path.join(rel_path, name) | 394 fac_path = os.path.join(rel_path, name) |
395 fac_path = fac_path.replace('\\', '/') | 395 fac_path = fac_path.replace('\\', '/') |
409 | 409 |
410 def setupPrepareParser(self, parser, app): | 410 def setupPrepareParser(self, parser, app): |
411 parser.add_argument('uri', help='The URI for the new page.') | 411 parser.add_argument('uri', help='The URI for the new page.') |
412 | 412 |
413 def buildMetadata(self, args): | 413 def buildMetadata(self, args): |
414 return {'path': args.uri} | 414 return {'slug': args.uri} |
415 | 415 |
416 def _makeSlug(self, rel_path): | 416 def _makeSlug(self, rel_path): |
417 slug, ext = os.path.splitext(rel_path) | 417 slug, ext = os.path.splitext(rel_path) |
418 slug = slug.replace('\\', '/') | 418 slug = slug.replace('\\', '/') |
419 if ext.lstrip('.') not in self.supported_extensions: | 419 if ext.lstrip('.') not in self.supported_extensions: |
420 slug += ext | 420 slug += ext |
421 if slug.startswith('./') or slug.startswith('.\\'): | 421 if slug.startswith('./'): |
422 slug = slug[2:] | 422 slug = slug[2:] |
423 if slug == '_index': | 423 if slug == '_index': |
424 slug = '' | 424 slug = '' |
425 return slug | 425 return slug |
426 | 426 |