Package: jac
jinja-assets-compressorA Jinja2 extension to compile and/or compress your assets.Installingpip install jacFor LESS and CSS support, installless:npm install -g lessFor COFFEE support, installcoffee-script:npm install -g coffee-scriptFor Sass and SCSS support, installsass:gem install sassJavaScript minification is built-in using the PythonrJsminpackage.When installing on Mac OS X set this shell variable, because jac dependencies
contain C code:export CFLAGS=-Qunused-argumentsUsageTo use it, you just have to put your css or js inside a compress tag.{%compress'css'%}<styletype="text/sass">sassstuff</style><linkrel="stylesheet"type="text/sass"href="file.sass">{%endcompress%}{%compress'js'%}<scripttype="text/coffeescript">coffeestuff</script><scripttype="text/coffeescript"src="file.coffee"></script>{%endcompress%}Configuring JinjaYou just have to create an environment with jac on it and configure output dir,
static prefix and say where it can find your sources.importjinja2fromjacimportCompressorExtensionenv=jinja2.Environment(extensions=[CompressorExtension])env.compressor_output_dir='./static/dist'env.compressor_static_prefix='/static'env.compressor_source_dirs='./static_files'After that just usetemplate = env.from_string(html); template.render()to
get it done.Configuring FlaskWhere you configure your app, just do this:fromjac.contrib.flaskimportJACapp=Flask(__name__)app.config['COMPRESSOR_DEBUG']=app.config.get('DEBUG')app.config['COMPRESSOR_OUTPUT_DIR']='./static/dist'app.config['COMPRESSOR_STATIC_PREFIX']='/static'jac=JAC(app)And you are done.Offline CompressionJAC supports compressing static assets offline, then deploying to a production
server. Here is a command to compress your static assets if using Flask:python -m jac.contrib.flask my_flask_module:create_appReplacemy_flask_modulewith the correct import path to find your Flask app.Custom CompressorsThecompressor_classestemplate env variable tells jac which compressor to
use for each mimetype. The default value forcompressor_classesis:{'text/css':LessCompressor,'text/coffeescript':CoffeeScriptCompressor,'text/less':LessCompressor,'text/javascript':JavaScriptCompressor,'text/sass':SassCompressor,'text/scss':SassCompressor,}To use an alternate compressor class, provide a class with acompileclass
method accepting argtextand kwargsmimetype,cwd,uri_cwd,
anddebug. For example, to uselibsass-pythonfor SASS files
instead of the built-in SassCompressor, create your custom compressor class:importsassclassCustomSassCompressor(object):"""Custom compressor for text/sass mimetype.

    Uses libsass-python for compression.
    """@classmethoddefcompile(cls,text,cwd=None,**kwargs):include_paths=[]ifcwd:include_paths+=[cwd]returnsass.compile(string=text,include_paths=include_paths)Then tell jac to use your custom compressor fortext/sassmimetypes:env.compressor_classes['text/sass']=CustomSassCompressorThe equivalent for Flask is:jac.set_compressor('text/sass',CustomSassCompressor)To only customize the path of a compressor which forks a subprocess for the
compile step (LessCompressor, CoffeeScriptCompressor, and SassCompressor), just
extend the compressor class and overwrite thebinaryclass attribute:fromjac.compressorsimportSassCompressorclassCustomSassCompressor(SassCompressor):"""Custom SASS compressor using Compass binary instead of libsass for text/sass mimetype.

    Uses the faster libsass wrapper sassc for SASS compression.
    https://github.com/sass/sassc
    """binary='/usr/bin/sassc'# Tell Flask to use our custom SASS compressorjac.set_compressor('text/sass',CustomSassCompressor)Running Testsvirtualenv venv
. venv/bin/activate
pip install -r requirements_tests.txt
make coverage
make lintOr use tox to run with multiple python versions:pip install tox
toxCHANGELOG0.17.2Make sure that flask contrib script always push an app context.0.17.1Fix error when the blueprint cannot be found (i.e. flask debug toolbar)0.17.0Fix app factory initializationChange how tests and linters runAdd compress command tojac.contrib.flask