changeset 240:c1d4e86a3918

less: Generate a proper, available URL for the LESS CSS map file. * The `less` processor now generates a usable URL for map files. * The server can serve files from inside the `_cache` directory.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 15 Feb 2015 23:29:51 -0800
parents f43f19975671
children 85a6c7ba5e3b
files piecrust/processing/less.py piecrust/serving.py
diffstat 2 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/piecrust/processing/less.py	Sun Feb 15 22:48:42 2015 -0800
+++ b/piecrust/processing/less.py	Sun Feb 15 23:29:51 2015 -0800
@@ -56,8 +56,10 @@
         self._ensureInitialized()
 
         map_path = self._getMapPath(in_path)
-        map_path = os.path.relpath(map_path)
-        args = [self._conf['bin'], '--source-map=%s' % map_path]
+        map_url = '/' + os.path.relpath(map_path, self.app.root_dir)
+        args = [self._conf['bin'],
+                '--source-map=%s' % map_path,
+                '--source-map-url=%s' % map_url]
         args += self._conf['options']
         args.append(in_path)
         args.append(out_path)
--- a/piecrust/serving.py	Sun Feb 15 22:48:42 2015 -0800
+++ b/piecrust/serving.py	Sun Feb 15 23:29:51 2015 -0800
@@ -194,7 +194,13 @@
 
     def _try_serve_asset(self, environ, request):
         rel_req_path = request.path.lstrip('/').replace('/', os.sep)
-        full_path = os.path.join(self._out_dir, rel_req_path)
+        if request.path.startswith('/_cache/'):
+            # Some stuff needs to be served directly from the cache directory,
+            # like LESS CSS map files.
+            full_path = os.path.join(self.root_dir, rel_req_path)
+        else:
+            full_path = os.path.join(self._out_dir, rel_req_path)
+
         try:
             response = self._make_wrapped_file_response(
                     environ, full_path)