Mercurial > piecrust2
diff piecrust/data/assetor.py @ 25:65ae19c4e8a3
Copy page assets to bake output, use correct slashes when serving assets.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 19 Aug 2014 11:07:42 -0700 |
parents | a8f9c78a6608 |
children | 43091c9837bf |
line wrap: on
line diff
--- a/piecrust/data/assetor.py Tue Aug 19 11:06:48 2014 -0700 +++ b/piecrust/data/assetor.py Tue Aug 19 11:07:42 2014 -0700 @@ -14,7 +14,7 @@ def build_base_url(app, uri, assets_path): base_url_format = app.env.base_asset_url_format site_root = app.config.get('site/root') - rel_path = os.path.relpath(assets_path, app.root_dir) + rel_path = os.path.relpath(assets_path, app.root_dir).replace('\\', '/') pretty = app.config.get('site/pretty_urls') if not pretty: uri, _ = os.path.splitext(uri) @@ -44,17 +44,21 @@ def __getattr__(self, name): try: self._cacheAssets() - return self._cache[name] + return self._cache[name][0] except KeyError: raise AttributeError() def __getitem__(self, key): self._cacheAssets() - return self._cache[key] + return self._cache[key][0] def __iter__(self): self._cacheAssets() - return iter(self._cache.values()) + return map(lambda i: i[0], self._cache.values()) + + def _getAssetPaths(self): + self._cacheAssets() + return map(lambda i: i[1], self._cache.values()) def _debugRenderAssetNames(self): self._cacheAssets() @@ -71,11 +75,19 @@ return base_url = build_base_url(self._page.app, self._uri, assets_dir) - for _, __, filenames in os.walk(assets_dir): - for fn in filenames: - name, ext = os.path.splitext(fn) - if name in self._cache: - raise UnsupportedAssetsError( - "Multiple asset files are named '%s'." % name) - self._cache[name] = base_url + fn + for fn in os.listdir(assets_dir): + full_fn = os.path.join(assets_dir, fn) + if not os.path.isfile(full_fn): + raise Exception("Skipping: %s" % full_fn) + continue + name, ext = os.path.splitext(fn) + if name in self._cache: + raise UnsupportedAssetsError( + "Multiple asset files are named '%s'." % name) + self._cache[name] = (base_url + fn, full_fn) + + cpi = self._page.app.env.exec_info_stack.current_page_info + if cpi is not None: + cpi.render_ctx.used_assets = self +