Skip to content

Commit

Permalink
Merge pull request #266 from noirbizarre/less-include-path
Browse files Browse the repository at this point in the history
Added LESS_PATHS option
  • Loading branch information
miracle2k committed Oct 26, 2013
2 parents fe5ce37 + 90bd620 commit ea1d6ae
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/webassets/filter/less.py
@@ -1,5 +1,9 @@
from __future__ import with_statement

import os

from os.path import abspath, join, isabs

from webassets.filter import ExternalTool
from webassets.utils import working_directory

Expand Down Expand Up @@ -29,6 +33,11 @@ class Less(ExternalTool):
browser, you can set this to ``False`` to have your original less
source files served (see below).
LESS_PATHS (paths)
Add include paths for less command line.
It should be a list of paths relatives to Environment.directory or absolute paths.
Order matters as less will pick the first file found in path order.
.. admonition:: Compiling less in the browser
less is an interesting case because it is written in Javascript and
Expand Down Expand Up @@ -76,6 +85,7 @@ class Less(ExternalTool):
'run_in_debug': 'LESS_RUN_IN_DEBUG',
'line_numbers': 'LESS_LINE_NUMBERS',
'extra_args': 'LESS_EXTRA_ARGS',
'paths': 'LESS_PATHS',
}
max_debug_level = None

Expand All @@ -90,6 +100,9 @@ def input(self, in_, out, source_path, **kw):
args = [self.less or 'lessc']
if self.line_numbers:
args.append('--line-numbers=%s' % self.line_numbers)
if self.paths:
paths = [path if isabs(path) else self.env.resolver.resolve_source(path) for path in self.paths]
args.append('--include-path={0}'.format(os.pathsep.join(paths)))
if self.extra_args:
args.extend(self.extra_args)
args.append('-')
Expand Down
30 changes: 28 additions & 2 deletions tests/test_filters.py
Expand Up @@ -545,12 +545,12 @@ def test_find_pyc_files( self ):
self.create_files({'test.pyc':'testing', 'test.py':'blue', 'boo.pyc':'boo'})
modules = list( unique_modules(self.tempdir))
assert modules == ['boo','test'],modules

def test_find_packages( self ):
self.create_files({'moo/__init__.pyc':'testing','voo/__init__.py':'testing'})
modules = list( unique_modules(self.tempdir))
assert modules == ['moo','voo'],modules


class TestCSSPrefixer(TempEnvironmentHelper):

Expand Down Expand Up @@ -771,6 +771,32 @@ def test_run_in_debug_mode(self):
self.mkbundle('foo.less', filters='less', output='out.css').build()
assert self.get('out.css') == self.default_files['foo.less']

def test_include_path(self):
'''It should allow specifying extra include paths'''
self.create_files({
'import.less': '''
@import "extra.less";
span { color: @c }
''',
'extra/path/extra.less': '@c: red;'})
self.env.config['less_paths'] = ['extra/path']
self.mkbundle('import.less', filters='less', output='out.css').build()
assert self.get('out.css') == 'span {\n color: #ff0000;\n}\n'

def test_include_path_order(self):
'''It should preserve extra include paths order'''
self.create_files({
'import.less': '''
@import "extra.less";
span { color: @c }
''',
'extra/path/extra.less': '@c: red;',
'other/path/extra.less': '@c: blue;'})
self.env.config['less_paths'] = ['extra/path', 'other/path']
self.mkbundle('import.less', filters='less', output='out.css').build()
assert self.get('out.css') == 'span {\n color: #ff0000;\n}\n'




class TestSass(TempEnvironmentHelper):
Expand Down

0 comments on commit ea1d6ae

Please sign in to comment.