sassutils.wsgi — WSGI middleware for development purpose

class sassutils.wsgi.SassMiddleware(app, manifests, package_dir={}, error_status='200 OK')

WSGI middleware for development purpose. Everytime a CSS file has requested it finds a matched SASS/SCSS source file and then compiled it into CSS.

It shows syntax errors in three ways:

Heading comment

The result CSS includes detailed error message in the heading CSS comment e.g.:

/*
Error: invalid property name
*/
Red text in body:before

The result CSS draws detailed error message in :before pseudo-class of body element e.g.:

body:before {
    content: 'Error: invalid property name';
    color: maroon;
    background-color: white;
}

In most cases you could be aware of syntax error by refreshing your working document because it will removes all other styles and leaves only a red text.

logging

It logs syntax errors if exist during compilation to sassutils.wsgi.SassMiddleware logger with level ERROR.

To enable this:

from logging import Formatter, StreamHandler, getLogger
logger = getLogger('sassutils.wsgi.SassMiddleware')
handler = StreamHandler(level=logging.ERROR)
formatter = Formatter(fmt='*' * 80 + '\n%(message)s\n' + '*' * 80)
handler.setFormatter(formatter)
logger.addHandler(handler)

Or simply:

import logging
logging.basicConfig()
Parameters:
  • app (collections.Callable) – the WSGI application to wrap
  • manifests (collections.Mapping) – build settings. the same format to setup.py script’s sass_manifests option
  • package_dir (collections.Mapping) – optional mapping of package names to directories. the same format to setup.py script’s package_dir option

Changed in version 0.4.0: It creates also source map files with filenames followed by .map suffix.

New in version 0.8.0: It logs syntax errors if exist during compilation to sassutils.wsgi.SassMiddleware logger with level ERROR.

static quote_css_string(s)

Quotes a string as CSS string literal.