Mercurial > piecrust2
annotate piecrust/sources/prose.py @ 334:b034f6f15e22
bake: Several bug taxonomy-related fixes for incorrect incremental bakes.
* Improve how the baker processes taxonomy terms and figures out what needs
to be re-baked or not.
* Create bake entries for clean taxnomy terms so they're not deleted by an
incremental bake.
* Add more information to bake records.
* Slugify taxonomy terms is now done by the route in one place.
* Fix a bug where the cache key for invalidating rendered segments was not
computed the same way as when the caching was done.
* Fix how term combinations are passed around, rendered, printed, parsed, etc.
(TODO: more word needed in the routing functions)
* Expose to the template whether a taxonomy term is a combination or not.
* Display term combinations better in the built-in theme.
* Rename `route.taxonomy` to `route.taxonomy_name` to prevent confusion.
* Add options to show bake records for previous bakes.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 03 Apr 2015 10:59:50 -0700 |
parents | f130365568ff |
children | 4b1019bb2533 |
rev | line source |
---|---|
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import os |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import os.path |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 import logging |
242
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
186
diff
changeset
|
4 from piecrust.sources.base import MODE_CREATING |
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
186
diff
changeset
|
5 from piecrust.sources.default import DefaultPageSource |
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
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 logger = logging.getLogger(__name__) |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 |
242
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
186
diff
changeset
|
11 class ProseSource(DefaultPageSource): |
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 SOURCE_NAME = 'prose' |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 def __init__(self, app, name, config): |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 super(ProseSource, self).__init__(app, name, config) |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 self.config_recipe = config.get('config', {}) |
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 |
186
e61fbae61402
sources: Pass any current mode to `_populateMetadata` when finding pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
170
diff
changeset
|
18 def _populateMetadata(self, rel_path, metadata, mode=None): |
e61fbae61402
sources: Pass any current mode to `_populateMetadata` when finding pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
170
diff
changeset
|
19 metadata['config'] = self._makeConfig(rel_path, mode) |
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 |
186
e61fbae61402
sources: Pass any current mode to `_populateMetadata` when finding pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
170
diff
changeset
|
21 def _makeConfig(self, rel_path, mode): |
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 c = dict(self.config_recipe) |
186
e61fbae61402
sources: Pass any current mode to `_populateMetadata` when finding pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
170
diff
changeset
|
23 if c.get('title') == '%first_line%' and mode != MODE_CREATING: |
170
c3831a762bc2
sources: Make the `SimplePageSource` more extensible, fix bugs in `prose` source.
Ludovic Chabant <ludovic@chabant.com>
parents:
157
diff
changeset
|
24 path = os.path.join(self.fs_endpoint_path, rel_path) |
157
55910ab4bfea
First draft of the `prose` page source.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 c['title'] = get_first_line(path) |
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 |