Mercurial > piecrust2
comparison piecrust/data/linker.py @ 852:4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
* Everything is a `ContentSource`, including assets directories.
* Most content sources are subclasses of the base file-system source.
* A source is processed by a "pipeline", and there are 2 built-in pipelines,
one for assets and one for pages. The asset pipeline is vaguely functional,
but the page pipeline is completely broken right now.
* Rewrite the baking process as just running appropriate pipelines on each
content item. This should allow for better parallelization.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 17 May 2017 00:11:48 -0700 |
parents | 3cca1f6bd610 |
children | f070a4fc033c |
comparison
equal
deleted
inserted
replaced
851:2c7e57d80bba | 852:4850f8c21b6e |
---|---|
1 import logging | 1 import logging |
2 import collections | 2 import collections |
3 from piecrust.data.iterators import PageIterator | 3 from piecrust.data.iterators import PageIterator |
4 from piecrust.data.pagedata import LazyPageConfigLoaderHasNoValue | 4 from piecrust.data.pagedata import LazyPageConfigLoaderHasNoValue |
5 from piecrust.data.paginationdata import PaginationData | 5 from piecrust.data.paginationdata import PaginationData |
6 from piecrust.sources.interfaces import IPaginationSource, IListableSource | 6 from piecrust.sources.interfaces import IPaginationSource |
7 | 7 |
8 | 8 |
9 logger = logging.getLogger(__name__) | 9 logger = logging.getLogger(__name__) |
10 | 10 |
11 | 11 |
12 class PageLinkerData(object): | 12 class PageLinkerData(object): |
13 """ Entry template data to get access to related pages from a given | 13 """ Entry template data to get access to related pages from a given |
14 root page. | 14 root page. |
15 """ | 15 """ |
16 debug_render = ['parent', 'ancestors', 'siblings', 'children', 'root', | 16 debug_render = ['parent', 'ancestors', 'siblings', 'children', 'root', |
17 'forpath'] | 17 'forpath'] |
18 debug_render_invoke = ['parent', 'ancestors', 'siblings', 'children', | 18 debug_render_invoke = ['parent', 'ancestors', 'siblings', 'children', |
19 'root'] | 19 'root'] |
20 debug_render_redirect = { | 20 debug_render_redirect = { |
21 'ancestors': '_debugRenderAncestors', | 21 'ancestors': '_debugRenderAncestors', |
22 'siblings': '_debugRenderSiblings', | 22 'siblings': '_debugRenderSiblings', |
23 'children': '_debugRenderChildren', | 23 'children': '_debugRenderChildren', |
24 'root': '_debugRenderRoot'} | 24 'root': '_debugRenderRoot'} |
25 | 25 |
26 def __init__(self, source, page_path): | 26 def __init__(self, source, page_path): |
27 self._source = source | 27 self._source = source |
28 self._root_page_path = page_path | 28 self._root_page_path = page_path |
29 self._linker = None | 29 self._linker = None |
79 def _load(self): | 79 def _load(self): |
80 if self._is_loaded: | 80 if self._is_loaded: |
81 return | 81 return |
82 | 82 |
83 self._is_loaded = True | 83 self._is_loaded = True |
84 | |
85 is_listable = isinstance(self._source, IListableSource) | |
86 if not is_listable: | |
87 return | |
88 | 84 |
89 dir_path = self._source.getDirpath(self._root_page_path) | 85 dir_path = self._source.getDirpath(self._root_page_path) |
90 self._linker = Linker(self._source, dir_path, | 86 self._linker = Linker(self._source, dir_path, |
91 root_page_path=self._root_page_path) | 87 root_page_path=self._root_page_path) |
92 | 88 |
258 if not is_dir and name == parent_name: | 254 if not is_dir and name == parent_name: |
259 parent_page = data.buildPage() | 255 parent_page = data.buildPage() |
260 item = _LinkedPage(parent_page) | 256 item = _LinkedPage(parent_page) |
261 item._linker_info.name = parent_name | 257 item._linker_info.name = parent_name |
262 item._linker_info.child_linker = Linker( | 258 item._linker_info.child_linker = Linker( |
263 self._source, parent_dir_path, | 259 self._source, parent_dir_path, |
264 root_page_path=self._root_page_path) | 260 root_page_path=self._root_page_path) |
265 self._parent = LinkedPageData(item) | 261 self._parent = LinkedPageData(item) |
266 break | 262 break |
267 else: | 263 else: |
268 self._parent = Linker(self._source, parent_dir_path, | 264 self._parent = Linker(self._source, parent_dir_path, |
269 root_page_path=self._root_page_path) | 265 root_page_path=self._root_page_path) |
305 return PageIterator(src) | 301 return PageIterator(src) |
306 | 302 |
307 def _load(self): | 303 def _load(self): |
308 if self._items is not None: | 304 if self._items is not None: |
309 return | 305 return |
310 | |
311 is_listable = isinstance(self._source, IListableSource) | |
312 if not is_listable: | |
313 raise Exception("Source '%s' can't be listed." % self._source.name) | |
314 | 306 |
315 items = list(self._source.listPath(self._dir_path)) | 307 items = list(self._source.listPath(self._dir_path)) |
316 self._items = collections.OrderedDict() | 308 self._items = collections.OrderedDict() |
317 for is_dir, name, data in items: | 309 for is_dir, name, data in items: |
318 # If `is_dir` is true, `data` will be the directory's source | 310 # If `is_dir` is true, `data` will be the directory's source |