Pedro Algarvio avatar Pedro Algarvio committed 2fa285c

Add support for `Flask-Themes` and a custom path for the `lessc` binary.

Comments (0)

Files changed (2)

flaskext/lesscss.py

     application.
 
     :copyright: (c) 2010 by Steve Losh.
+    :copyright: (c) 2011 by Pedro Algarvio.
     :license: MIT, see LICENSE for more details.
 """
 
+__all__ = ['lesscss']
+
 import os, subprocess
 
-def lesscss(app):
+def find_dot_less_files(search_path):
+    less_paths = []
+    for path, subdirs, filenames in os.walk(search_path):
+        less_paths.extend([
+            (os.path.join(path, f),
+             os.path.join(path, f.replace('.less', '.css')))
+            for f in filenames if f.endswith('.less')
+        ])
+    return less_paths
+
+def lesscss(app, lessc_bin_path='lessc'):
     @app.before_request
     def _render_less_css():
-        static_dir = app.root_path + app.static_path
-        
-        less_paths = []
-        for path, subdirs, filenames in os.walk(static_dir):
-            less_paths.extend([
-                os.path.join(path, f)
-                for f in filenames if os.path.splitext(f)[1] == '.less'
-            ])
-        
-        for less_path in less_paths:
-            css_path = os.path.splitext(less_path)[0] + '.css'
+        search_paths = set()
+        search_paths.add(app.root_path + app.static_path)
+        if hasattr(app, 'theme_manager'):
+            for theme in app.theme_manager.themes.values():
+                search_paths.add(theme.static_path)
+        dot_less_filepaths = set()
+        for search_path in search_paths:
+            dot_less_filepaths.update(find_dot_less_files(search_path))
+        for less_path, css_path in dot_less_filepaths:
             if not os.path.isfile(css_path):
                 css_mtime = -1
             else:
                 css_mtime = os.path.getmtime(css_path)
             less_mtime = os.path.getmtime(less_path)
             if less_mtime >= css_mtime:
-                subprocess.call(['lessc', less_path, css_path], shell=False)
+                subprocess.call(
+                    [lessc_bin_path, less_path, css_path], shell=False
+                )
 
 
 
 setup(
     name='flask-lesscss',
-    version='0.9.1',
+    version='0.9.2',
     url='http://sjl.bitbucket.org/flask-lesscss/',
     license='MIT',
     author='Steve Losh',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.