Mercurial > piecrust2
diff piecrust/sources/base.py @ 186:e61fbae61402
sources: Pass any current mode to `_populateMetadata` when finding pages.
Page sources like the `prose` source may need to open an existing page's
file to read stuff from it. This won't work if the metadata is populated as
part of finding a path to create a page (like when running `chef prepare`).
We pass the mode to `_populateMetadata` so the underlying class now knows
the current context in which it is called.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 04 Jan 2015 15:48:29 -0800 |
parents | d5991525801d |
children | 0b2d8f6df4ce |
line wrap: on
line diff
--- a/piecrust/sources/base.py Sun Jan 04 14:59:12 2015 -0800 +++ b/piecrust/sources/base.py Sun Jan 04 15:48:29 2015 -0800 @@ -309,7 +309,8 @@ yield CachedPageFactory(p) -class SimplePageSource(PageSource, IListableSource): +class SimplePageSource(PageSource, IListableSource, IPreparingSource, + SimplePaginationSourceMixin): def __init__(self, app, name, config): super(SimplePageSource, self).__init__(app, name, config) self.fs_endpoint = config.get('fs_endpoint', name) @@ -353,7 +354,7 @@ path = '%s.%s' % (path, self.default_auto_format) rel_path = os.path.relpath(path, self.fs_endpoint_path) rel_path = rel_path.replace('\\', '/') - self._populateMetadata(rel_path, metadata) + self._populateMetadata(rel_path, metadata, mode) return rel_path, metadata if ext == '': @@ -366,7 +367,7 @@ if os.path.isfile(path): rel_path = os.path.relpath(path, self.fs_endpoint_path) rel_path = rel_path.replace('\\', '/') - self._populateMetadata(rel_path, metadata) + self._populateMetadata(rel_path, metadata, mode) return rel_path, metadata return None, None @@ -403,6 +404,12 @@ name, _ = os.path.splitext(filename) return name + def setupPrepareParser(self, parser, app): + parser.add_argument('uri', help='The URI for the new page.') + + def buildMetadata(self, args): + return {'path': args.uri} + def _makeSlug(self, rel_path): slug, ext = os.path.splitext(rel_path) slug = slug.replace('\\', '/') @@ -422,24 +429,16 @@ f[-1] != '~' and # Vim temp files and what-not f not in ['Thumbs.db']) # Windows bullshit - def _populateMetadata(self, rel_path, metadata): + def _populateMetadata(self, rel_path, metadata, mode=None): pass -class DefaultPageSource(SimplePageSource, - IPreparingSource, IListableSource, - SimplePaginationSourceMixin): +class DefaultPageSource(SimplePageSource): SOURCE_NAME = 'default' def __init__(self, app, name, config): super(DefaultPageSource, self).__init__(app, name, config) - def setupPrepareParser(self, parser, app): - parser.add_argument('uri', help='The URI for the new page.') - - def buildMetadata(self, args): - return {'path': args.uri} - class SourceFactoryIterator(object): def __init__(self, source):