Mercurial > piecrust2
comparison piecrust/data/assetor.py @ 837:ad8f48a31c62
assets: Fix crash when a page doesn't have assets.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 05 Feb 2017 22:52:01 -0800 |
parents | 61878590bf96 |
children | 4850f8c21b6e |
comparison
equal
deleted
inserted
replaced
836:dca51cd8147a | 837:ad8f48a31c62 |
---|---|
62 return list(self._cache.keys()) | 62 return list(self._cache.keys()) |
63 | 63 |
64 def _cacheAssets(self): | 64 def _cacheAssets(self): |
65 if self._cache is not None: | 65 if self._cache is not None: |
66 return | 66 return |
67 | 67 |
68 self._cache = dict(self.findAssets()) | 68 self._cache = dict(self.findAssets()) |
69 | 69 |
70 def findAssets(self): | 70 def findAssets(self): |
71 raise NotImplementedError() | 71 raise NotImplementedError() |
72 | 72 |
73 def copyAssets(self, dest_dir): | 73 def copyAssets(self, dest_dir): |
74 raise NotImplementedError() | 74 raise NotImplementedError() |
82 def findAssets(self): | 82 def findAssets(self): |
83 assets = {} | 83 assets = {} |
84 name, ext = os.path.splitext(self._page.path) | 84 name, ext = os.path.splitext(self._page.path) |
85 assets_dir = name + ASSET_DIR_SUFFIX | 85 assets_dir = name + ASSET_DIR_SUFFIX |
86 if not os.path.isdir(assets_dir): | 86 if not os.path.isdir(assets_dir): |
87 return | 87 return assets |
88 | 88 |
89 rel_assets_dir = os.path.relpath(assets_dir, self._page.app.root_dir) | 89 rel_assets_dir = os.path.relpath(assets_dir, self._page.app.root_dir) |
90 base_url = build_base_url(self._page.app, self._uri, rel_assets_dir) | 90 base_url = build_base_url(self._page.app, self._uri, rel_assets_dir) |
91 for fn in os.listdir(assets_dir): | 91 for fn in os.listdir(assets_dir): |
92 full_fn = os.path.join(assets_dir, fn) | 92 full_fn = os.path.join(assets_dir, fn) |
101 assets[name] = (base_url + fn, full_fn) | 101 assets[name] = (base_url + fn, full_fn) |
102 | 102 |
103 cpi = self._page.app.env.exec_info_stack.current_page_info | 103 cpi = self._page.app.env.exec_info_stack.current_page_info |
104 if cpi is not None: | 104 if cpi is not None: |
105 cpi.render_ctx.current_pass_info.used_assets = True | 105 cpi.render_ctx.current_pass_info.used_assets = True |
106 | 106 |
107 return assets | 107 return assets |
108 | 108 |
109 def copyAssets(self, dest_dir): | 109 def copyAssets(self, dest_dir): |
110 page_pathname, _ = os.path.splitext(self._page.path) | 110 page_pathname, _ = os.path.splitext(self._page.path) |
111 in_assets_dir = page_pathname + ASSET_DIR_SUFFIX | 111 in_assets_dir = page_pathname + ASSET_DIR_SUFFIX |
112 for fn in os.listdir(in_assets_dir): | 112 for fn in os.listdir(in_assets_dir): |
113 full_fn = os.path.join(in_assets_dir, fn) | 113 full_fn = os.path.join(in_assets_dir, fn) |