• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

django_libsass.egg-info/H03-May-2022-10978

PKG-INFOH A D02-May-20165.2 KiB10978

README.rstH A D02-May-20163.8 KiB9060

django_libsass.pyH A D02-May-20165.2 KiB14499

setup.cfgH A D02-May-201659 64

setup.pyH A D02-May-20161,010 3430

README.rst

1django-libsass
2==============
3
4A django-compressor filter to compile Sass files using libsass.
5
6Installation
7~~~~~~~~~~~~
8
9Starting from a Django project with `django-compressor <https://github.com/django-compressor/django-compressor/>`_ set up::
10
11 pip install django-libsass
12
13and add django_libsass.SassCompiler to your COMPRESS_PRECOMPILERS setting::
14
15 COMPRESS_PRECOMPILERS = (
16     ('text/x-scss', 'django_libsass.SassCompiler'),
17 )
18
19You can now use the content type text/x-scss on your stylesheets, and have them
20compiled seamlessly into CSS::
21
22 {% compress css %}
23     <link rel="stylesheet" type="text/x-scss" href="{% static "myapp/css/main.scss" %}" />
24 {% endcompress %}
25
26
27Imports
28~~~~~~~
29
30Relative paths in @import lines are followed as you would expect::
31
32 @import "../variables.scss";
33
34Additionally, Django's STATICFILES_FINDERS setting is consulted, and all possible locations
35for static files *on the local filesystem* are included on the search path. This makes it
36possible to import files across different apps::
37
38 @import "myotherapp/css/widget.scss"
39
40
41Settings
42~~~~~~~~
43
44The following settings can be used to control django-libsass's behaviour:
45
46* ``LIBSASS_SOURCE_COMMENTS`` - whether to enable SASS source comments (adds comments about source lines). Defaults to ``True`` when Django's ``DEBUG`` is ``True``, ``False`` otherwise.
47* ``LIBSASS_OUTPUT_STYLE`` - SASS output style. Options are ``'nested'``, ``'expanded'``, ``'compact'`` and ``'compressed'``, although as of libsass 3.0.2 only ``'nested'`` and ``'compressed'`` are implemented. Default is 'nested'. See `SASS documentation for output styles <http://sass-lang.com/documentation/file.SASS_REFERENCE.html#output_style>`_. Note that `django-compressor's settings <http://django-compressor.readthedocs.org/en/latest/settings/>`_ may also affect the formatting of the resulting CSS.
48* ``LIBSASS_CUSTOM_FUNCTIONS`` - A mapping of custom functions to be made available within the SASS compiler. By default, a ``static`` function is provided, analogous to Django's ``static`` template tag.
49* ``LIBSASS_SOURCEMAPS`` - Enable embedding sourcemaps into file output.
50* ``LIBSASS_PRECISION`` - Number of digits of numerical precision (default: 5)
51
52Custom functions
53~~~~~~~~~~~~~~~~
54
55The SASS compiler can be extended with custom Python functions defined in the ``LIBSASS_CUSTOM_FUNCTIONS`` setting. By default, a ``static`` function is provided, for generating static paths to resources such as images and fonts::
56
57    .foo {
58        background: url(static("myapp/image/bar.png"));
59    }
60
61If your ``STATIC_URL`` is '/static/', this will be rendered as::
62
63    .foo {
64        background: url("/static/myapp/image/bar.png"));
65    }
66
67Why django-libsass?
68~~~~~~~~~~~~~~~~~~~
69
70We wanted to use Sass in a Django project without introducing any external (non pip-installable)
71dependencies. (Actually, we wanted to use Less, but the same arguments apply...) There are a few
72pure Python implementations of Sass and Less, but we found that they invariably didn't match the
73behaviour of the reference compilers, either in their handling of @imports or lesser-used CSS
74features such as media queries.
75
76`libsass <http://libsass.org/>`_ is a mature C/C++ port of the Sass engine, co-developed by the
77original creator of Sass, and we can reasonably rely on it to stay in sync with the reference
78Sass compiler - and, being C/C++, it's fast. Thanks to Hong Minhee's
79`libsass-python <https://github.com/dahlia/libsass-python>`_ project, it has Python bindings and
80installs straight from pip.
81
82django-libsass builds on libsass-python to make @import paths aware of Django's staticfiles
83mechanism, and provides a filter module for django-compressor which uses the libsass-python API
84directly, avoiding the overheads of calling an external executable to do the compilation.
85
86Author
87~~~~~~
88
89Matt Westcott matthew.westcott@torchbox.com
90