• Stars
    star
    265
  • Rank 153,677 (Top 4 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A django-compressor filter to compile SASS files using libsass

django-libsass

A django-compressor filter to compile Sass files using libsass.

Installation

Starting from a Django project with django-compressor set up:

pip install django-libsass

and add django_libsass.SassCompiler to your COMPRESS_PRECOMPILERS setting:

COMPRESS_PRECOMPILERS = (
    ('text/x-scss', 'django_libsass.SassCompiler'),
)

You can now use the content type text/x-scss on your stylesheets, and have them compiled seamlessly into CSS:

{% load compress %}

{% compress css %}
    <link rel="stylesheet" type="text/x-scss" href="{% static "myapp/css/main.scss" %}" />
{% endcompress %}

Imports

Relative paths in @import lines are followed as you would expect:

@import "../variables.scss";

Additionally, Django's STATICFILES_FINDERS setting is consulted, and all possible locations for static files on the local filesystem are included on the search path. This makes it possible to import files across different apps:

@import "myotherapp/css/widget.scss"

Settings

The following settings can be used to control django-libsass's behaviour:

  • 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.
  • 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. Note that django-compressor's settings may also affect the formatting of the resulting CSS.
  • 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.
  • LIBSASS_SOURCEMAPS - Enable embedding sourcemaps into file output (default: False)
  • LIBSASS_PRECISION - Number of digits of numerical precision (default: 5)
  • LIBSASS_ADDITIONAL_INCLUDE_PATHS - a list of base paths to be recognised in @import lines, in addition to Django's recognised static file locations

Custom functions

The 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:

.foo {
    background: url(static("myapp/image/bar.png"));
}

If your STATIC_URL is '/static/', this will be rendered as:

.foo {
    background: url("/static/myapp/image/bar.png"));
}

Why django-libsass?

We wanted to use Sass in a Django project without introducing any external (non pip-installable) dependencies. (Actually, we wanted to use Less, but the same arguments apply...) There are a few pure Python implementations of Sass and Less, but we found that they invariably didn't match the behaviour of the reference compilers, either in their handling of @imports or lesser-used CSS features such as media queries.

libsass is a mature C/C++ port of the Sass engine, co-developed by the original creator of Sass, and we can reasonably rely on it to stay in sync with the reference Sass compiler - and, being C/C++, it's fast. Thanks to Hong Minhee's libsass-python project, it has Python bindings and installs straight from pip.

django-libsass builds on libsass-python to make @import paths aware of Django's staticfiles mechanism, and provides a filter module for django-compressor which uses the libsass-python API directly, avoiding the overheads of calling an external executable to do the compilation.

Reporting bugs

Please see the troubleshooting page for help with some common setup issues.

I do not provide support for getting django-libsass working with your CSS framework of choice. If you believe you've found a bug, please try to isolate it as a minimal reproducible test case before reporting it - ideally this will consist of a few edits / additions to the hello-django-libsass example project. If you cannot demonstrate the problem in a few standalone SCSS files, it is almost certainly not a django-libsass bug - any bug reports that relate to a third-party CSS framework are likely to be closed without further investigation.

Author

Matt Westcott [email protected]

More Repositories

1

django-recaptcha

New maintainers 🚧 --- Django reCAPTCHA form field/widget integration app.
Python
929
star
2

django-pattern-library

UI pattern libraries for Django templates
Python
359
star
3

vagrant-django-template

Skeleton project for a Django app running under Vagrant
Python
240
star
4

wagtailmedia

A Wagtail module for managing video and audio files within the admin
Python
231
star
5

wagtail-markdown

Markdown support for Wagtail
Python
191
star
6

wagtail-grapple

A Wagtail app that makes building GraphQL endpoints a breeze!
Python
152
star
7

wagtail-torchbox

Wagtail build of Torchbox.com
Python
124
star
8

wagtail-headless-preview

Previews for headless Wagtail setups
Python
116
star
9

wagtail-experiments

A/B testing for Wagtail
Python
105
star
10

vagrant-django-base

Vagrant configuration for a base box for Django development
Shell
90
star
11

storybook-django

Develop Django UI components in isolation, with Storybook
JavaScript
83
star
12

cookiecutter-wagtail

Python
54
star
13

k8s-hostpath-provisioner

Network storage provisioner for Kubernetes
Go
52
star
14

kdtool

Kubernetes deployment utility
Python
45
star
15

kube-ldap-authn

Kubernetes LDAP authentication service
Python
42
star
16

wagtail-wordpress-import

A package for Wagtail CMS to import WordPress blog content from an XML file into Wagtail
Python
41
star
17

wagtail-storages

Use AWS S3 with private documents in Wagtail
Python
40
star
18

design-in-browser-bootstrap

An aid to quickly starting Design In the Browser
JavaScript
34
star
19

wagtail-import-export

UNMAINTAINED. Try wagtail-transfer, the evolution of this package: https://github.com/wagtail/wagtail-transfer/
Python
32
star
20

wagtail-content-import

A module for importing page content into Wagtail from third-party sources. Docs:
Python
32
star
21

rustface-py

Python library for detecting faces in images.
Rust
31
star
22

wagtailquickcreate

Wagtail Quick Create offers shortcut links to create objects from models specified in your settings file.
Python
25
star
23

wagtailguide

An app for adding a CMS guide to your Wagtail CMS
Python
23
star
24

k8s-ts-ingress

Kubernetes Ingress controller as a Traffic Server plugin
C
22
star
25

wagtailsurveys

Python
21
star
26

vagrant-thumbor-base

Vagrant box providing a thumbor service over HTTP
Shell
20
star
27

wagtail-footnotes

Python
19
star
28

wagtail-template

A Django template for starting new Wagtail projects with Vagrant. NO LONGER MAINTANED
Python
19
star
29

wagtail-ab-testing

A/B testing for Wagtail
Python
17
star
30

buckup

Creating S3 buckets for your site with ease.
Python
16
star
31

torchbox-frontend

JavaScript
16
star
32

wagtail-appengine-demo

The simplest possible Wagtail site on Google Cloud
CSS
15
star
33

django-basic-auth-ip-whitelist

Hide your Django site behind basic authentication with IP whitelisting support
Python
14
star
34

verdant-rca

Python
13
star
35

docker-php

Docker PHP Images based on official PHP
Shell
12
star
36

longform

A plugin for longform content in Wagtail
CSS
12
star
37

wagtail-purge

A simple Wagtail admin UI for removing individual pages from your CDN's cache
Python
10
star
38

wagtail-webstories

AMP web story support for Wagtail
Python
9
star
39

cloudflare-recipes

Cloudflare service worker recipes
JavaScript
7
star
40

rca-wagtail-2019

Python
7
star
41

trafficserver-ingress-controller

Apache Traffic Server ingress controller for Kubernetes
Perl
7
star
42

tbxforms

A Torchbox-flavoured template pack for django-crispy-forms, adapted from crispy-forms-gds.
HTML
6
star
43

stylelint-config-torchbox

Shareable stylelint config for CSS and SCSS, following Torchbox’s code style.
JavaScript
6
star
44

wagtailapi

A module for adding a read only, JSON based web API to your Wagtail site (NO LONGER MAINTAINED! Use Wagtails contrib.wagtailapi module instead)
Python
6
star
45

webstories

Parser for AMP web stories
Python
6
star
46

wagtail-makeup

Wagtail plugin to replace all your broken local images with unsplash ones
Python
6
star
47

samaritans-patterns

HTML
5
star
48

wagtail-bookmarklet

Gives Wagtail editors an 'edit this page' bookmarklet, for scenarios where the user bar isn't available
Python
5
star
49

django-registration

Tweaked Django >=1.6-compatible version of django-registration
Python
5
star
50

careers

Torchbox careers site
TypeScript
4
star
51

ample

Cross-browser audio playback library, with HTML5 and Flash backends
JavaScript
4
star
52

nhs-organisations

Python
3
star
53

wagtail-jotform

A plugin for using jotforms in wagtail
Python
3
star
54

wagtail-bynder

Wagtail + Bynder Digital Asset Management System integration
Python
3
star
55

wagtailapidemo

Wagtaildemo with API enabled
Python
3
star
56

eslint-config-torchbox

Shareable ESLint config following Torchbox’s code style
JavaScript
3
star
57

wagtail-mongodb

Python
3
star
58

dit_directory_cms_poc

Proof-of-concepts for potential improvements to uktrade/directory-cms
Python
2
star
59

christmas-video-2017

CSS
2
star
60

wagtail-related

Python
2
star
61

resourcespace_plugin-api_markasused

API plugin for resourcespace that updates a resourcespace entry
PHP
2
star
62

wagtail-azure-cdn

Use Azure CDN with Wagtail CMS.
Python
2
star
63

heroku-cloudflare-app-domain

Create branded herokuapp.com domains through Cloudflare
Python
2
star
64

demo.wagtail.io

Configuration for demo.wagtail.io
Python
2
star
65

christmaschorus

the 2011 musical christmas card
JavaScript
2
star
66

ngxpurged

nginx cache purge daemon
Python
2
star
67

django-tagging

Fork via PyPI v0.3.4 to maintain Django compatibility. Unmaintained for Django >= 1.10
Python
2
star
68

torchbox.com

Torchbox website 2024 incarnation
Python
2
star
69

resourcespace_plugin-api_resource

API plugin for resourcespace that fetches a resource metadata or a resource file in stream
PHP
2
star
70

docker-rsync

Trivial Docker image containing Alpine Linux with rsync installed
Makefile
1
star
71

heroku-restarter

Restarts Heroku applications based on timeout alerts in Papertrail
Python
1
star
72

django-piston

Fork of the popular REST API mini-framework
Python
1
star
73

kube-registry-proxy

Shell
1
star
74

tate-cms

Tate CMS project’s sprint notes
1
star
75

docker-trafficserver

1
star
76

healtheintent-api-python

Python
1
star
77

raxtool

Rackspace Cloud management tool
Python
1
star
78

ceph-rbd-provisioner

1
star
79

django-importo

A developer-friendly framework for importing data into Django apps
Python
1
star
80

wagtail_picture_proposal

Code snippets for an experimental picture tag for Wagtail. Not intended for reuse
Python
1
star
81

nlbq

Natural language interface to BigQuery
Python
1
star
82

nuffield-nhs-timeline

Nuffield NHS Timeline
HTML
1
star