Skip to content
This repository was archived by the owner on Jun 28, 2018. It is now read-only.

Commit f386b60

Browse files
committed
Add option to specify compression type.
1 parent 27c3007 commit f386b60

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Sample Brubeck and web.py projects are in `examples` folder.
2323
- **exclude_dirs**: Directories you don't want to be searched. It'd be pointless to search for `less` files in an images directory. This parameter is expected to be a list.
2424
- **based**: If it's set `True` then LessCSS will generate the `style-(base60).css` version as well (for example; `style-dHCFD.css`). This is useful if you set expire times of static files to a distant future since browsers will not retrieve those files unless the name is different or the cache has expired. This parameter is expected to be a boolean value.
2525
- **compressed**: If it's set `True` then LessCSS will minimize the generated CSS files. This parameter is expected to be a boolean value.
26-
- **output_dir**: Absolute path of the folder where compiled CSS files
27-
should be put.
26+
- **compression**: Specifies the type of compression to use. Default to the normal compression, 'x'. Other option is to use the [YUI Compressor](http://developer.yahoo.com/yui/compressor/css.html), 'yui'. See "Command-line Usage" at http://lesscss.org/.
27+
- **output_dir**: Absolute path of the folder where compiled CSS files should be put.
2828

2929

3030
##TODO

lesscss/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class LessCSS(object):
2727
"""
2828

2929
def __init__(self, media_dir='static', exclude_dirs=None, based=True,
30-
compressed=True, output_dir=None):
30+
compressed=True, compression='x', output_dir=None):
3131
""" Initialize LessCSS. When you wrap your web application you need to
3232
define the following parameters:
3333
@@ -50,7 +50,13 @@ def __init__(self, media_dir='static', exclude_dirs=None, based=True,
5050
``compressed``
5151
If this is set to `True`, then the compiled CSS file will be
5252
minimized.
53-
53+
54+
``compression``
55+
The type of compression to use. Default to standard 'x' compression.
56+
Set to 'yui' to use YUI Compressor
57+
(http://developer.yahoo.com/yui/compressor/css.html).
58+
See "Command-line Usage" at http://lesscss.org/
59+
5460
``output_dir``
5561
Define the absolute path of the folder where compiled CSS files
5662
should be put.
@@ -59,6 +65,7 @@ def __init__(self, media_dir='static', exclude_dirs=None, based=True,
5965
self._media = media_dir
6066
self._based = based
6167
self._compressed = compressed
68+
self._compression = compression
6269
self._excluded = exclude_dirs
6370
self._output = output_dir.rstrip('/') if output_dir else None
6471
self.compile()
@@ -109,6 +116,8 @@ def compile(self):
109116
command_opt = ['lessc', '-x']
110117
if not self._compressed:
111118
del command_opt[-1]
119+
if self._compressed and self._compression.lower() == 'yui':
120+
command_opt[1] = '--yui-compress'
112121
for i in less:
113122
filename = os.path.splitext(i)[0]
114123
css = '%s.css' % filename

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
::
3131
3232
from lesscss import LessCSS
33-
LessCSS(media_dir='media', exclude_dirs=['img', 'src'], based=True, compressed=True, output_dir=None)
33+
LessCSS(media_dir='media', exclude_dirs=['img', 'src'], based=True, compressed=True, compression='x', output_dir=None)
3434
3535
3636
Parameters
@@ -40,6 +40,7 @@
4040
- **exclude_dirs:** Directories you don't want to be searched. It'd be pointless to search for less files in an images directory. This parameter is expected to be a list.
4141
- **based:** If it's set True then LessCSS will generate the style-(base60).css version as well (for example; style-dHCFD.css). This is useful if you set expire times of static files to a distant future since browsers will not retrieve those files unless the name is different or the cache has expired. This parameter is expected to be a boolean value.
4242
- **compressed**: If it's set `True` then LessCSS will minimize the generated CSS files. This parameter is expected to be a boolean value.
43+
- **compression**: Specifies the type of compression to use. Default to the normal compression, 'x'. Other option is to use the [YUI Compressor](http://developer.yahoo.com/yui/compressor/css.html), 'yui'. See "Command-line Usage" at http://lesscss.org/.
4344
- **output_dir:** Directory where you put compiled CSS files if different than location of .less file.
4445
4546

0 commit comments

Comments
 (0)