Mercurial > piecrust2
annotate piecrust/sources/prose.py @ 853:f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
The asset pipeline is still the only function pipeline at this point.
* No more `QualifiedPage`, and several other pieces of code deleted.
* Data providers are simpler and more focused. For instance, the page iterator
doesn't try to support other types of items.
* Route parameters are proper known source metadata to remove the confusion
between the two.
* Make the baker and pipeline more correctly manage records and record
histories.
* Add support for record collapsing and deleting stale outputs in the asset
pipeline.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 21 May 2017 00:06:59 -0700 |
parents | 4850f8c21b6e |
children | d9059257743c |
rev | line source |
---|---|
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
1 import copy |
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import logging |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
394
diff
changeset
|
3 from piecrust.sources.default import DefaultContentSource |
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 logger = logging.getLogger(__name__) |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
394
diff
changeset
|
9 class ProseSource(DefaultContentSource): |
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 SOURCE_NAME = 'prose' |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 def __init__(self, app, name, config): |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
13 super().__init__(app, name, config) |
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 self.config_recipe = config.get('config', {}) |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
16 def _doCreateItemMetadata(self, path): |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
17 metadata = super()._doCreateItemMetadata(path) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
18 config = metadata.setdefault('config', {}) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
19 config.update(self._makeConfig(path)) |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
20 return config |
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
22 def _makeConfig(self, path): |
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
242
diff
changeset
|
23 c = copy.deepcopy(self.config_recipe) |
853
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
24 if c.get('title') == '%first_line%': |
f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
25 c['title'] = get_first_line(path) |
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 return c |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 def get_first_line(path): |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 with open(path, 'r') as f: |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 while True: |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 l = f.readline() |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 if not l: |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 break |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 l = l.strip() |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 if not l: |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 continue |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 return l |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 return None |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
40 |