{"id":13937078,"url":"https://github.com/jaysonsantos/jinja-assets-compressor","last_synced_at":"2025-12-30T07:54:08.755Z","repository":{"id":7120211,"uuid":"8414615","full_name":"jaysonsantos/jinja-assets-compressor","owner":"jaysonsantos","description":"A Jinja extension (compatible with Flask and other frameworks) to compile and/or compress your assets.","archived":true,"fork":false,"pushed_at":"2020-10-01T07:13:34.000Z","size":187,"stargazers_count":93,"open_issues_count":11,"forks_count":10,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-17T20:53:35.644Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaysonsantos.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-25T17:58:23.000Z","updated_at":"2023-10-07T05:31:19.000Z","dependencies_parsed_at":"2022-08-19T13:20:42.846Z","dependency_job_id":null,"html_url":"https://github.com/jaysonsantos/jinja-assets-compressor","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaysonsantos%2Fjinja-assets-compressor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaysonsantos%2Fjinja-assets-compressor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaysonsantos%2Fjinja-assets-compressor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaysonsantos%2Fjinja-assets-compressor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaysonsantos","download_url":"https://codeload.github.com/jaysonsantos/jinja-assets-compressor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226693903,"owners_count":17667757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-07T23:03:15.679Z","updated_at":"2025-12-14T19:11:25.720Z","avatar_url":"https://github.com/jaysonsantos.png","language":"Python","funding_links":[],"categories":["Asset Management","资源列表","Python","介绍","Awesome Python","Uncategorized"],"sub_categories":["Web 资源管理","资源管理","Asset Management","Uncategorized"],"readme":".. image:: https://travis-ci.org/jaysonsantos/jinja-assets-compressor.svg?branch=master\n    :target: https://travis-ci.org/jaysonsantos/jinja-assets-compressor\n    :alt: Build Status\n\njinja-assets-compressor\n=======================\n\nA Jinja2 extension to compile and/or compress your assets.\n\n\nInstalling\n----------\n\n::\n\n    pip install jac\n\nFor LESS and CSS support, install `less \u003chttps://www.npmjs.org/package/less\u003e`_::\n\n    npm install -g less\n\nFor COFFEE support, install `coffee-script \u003chttps://www.npmjs.com/package/coffee-script\u003e`_::\n\n    npm install -g coffee-script\n\nFor Sass and SCSS support, install `sass \u003chttps://rubygems.org/gems/sass\u003e`_::\n\n    gem install sass\n\nJavaScript minification is built-in using the Python\n`rJsmin \u003chttps://pypi.python.org/pypi/rjsmin\u003e`_ package.\n\nWhen installing on Mac OS X set this shell variable, because jac dependencies\ncontain C code::\n\n    export CFLAGS=-Qunused-arguments\n\n\nUsage\n-----\n\nTo use it, you just have to put your css or js inside a compress tag.\n\n.. code-block:: python\n\n    {% compress 'css' %}\n    \u003cstyle type=\"text/sass\"\u003e\n    sass stuff\n    \u003c/style\u003e\n    \u003clink rel=\"stylesheet\" type=\"text/sass\" href=\"file.sass\"\u003e\n    {% endcompress %}\n\n    {% compress 'js' %}\n    \u003cscript type=\"text/coffeescript\"\u003e\n    coffee stuff\n    \u003c/script\u003e\n    \u003cscript type=\"text/coffeescript\" src=\"file.coffee\"\u003e\u003c/script\u003e\n    {% endcompress %}\n\n\nConfiguring Jinja\n-----------------\n\nYou just have to create an environment with jac on it and configure output dir,\nstatic prefix and say where it can find your sources.\n\n.. code-block:: python\n\n    import jinja2\n\n    from jac import CompressorExtension\n\n    env = jinja2.Environment(extensions=[CompressorExtension])\n    env.compressor_output_dir = './static/dist'\n    env.compressor_static_prefix = '/static'\n    env.compressor_source_dirs = './static_files'\n\nAfter that just use ``template = env.from_string(html); template.render()`` to\nget it done.\n\n\nConfiguring Flask\n-----------------\n\nWhere you configure your app, just do this:\n\n.. code-block:: python\n\n    from jac.contrib.flask import JAC\n\n    app = Flask(__name__)\n    app.config['COMPRESSOR_DEBUG'] = app.config.get('DEBUG')\n    app.config['COMPRESSOR_OUTPUT_DIR'] = './static/dist'\n    app.config['COMPRESSOR_STATIC_PREFIX'] = '/static'\n    jac = JAC(app)\n\nAnd you are done.\n\n\nOffline Compression\n-------------------\n\nJAC supports compressing static assets offline, then deploying to a production\nserver. Here is a command to compress your static assets if using Flask: ::\n\n    python -m jac.contrib.flask my_flask_module:create_app\n\nReplace ``my_flask_module`` with the correct import path to find your Flask app.\n\n\nCustom Compressors\n------------------\n\nThe ``compressor_classes`` template env variable tells jac which compressor to\nuse for each mimetype. The default value for ``compressor_classes`` is:\n\n.. code-block:: python\n\n    {\n        'text/css': LessCompressor,\n        'text/coffeescript': CoffeeScriptCompressor,\n        'text/less': LessCompressor,\n        'text/javascript': JavaScriptCompressor,\n        'text/sass': SassCompressor,\n        'text/scss': SassCompressor,\n    }\n\nTo use an alternate compressor class, provide a class with a ``compile`` class\nmethod accepting arg ``text`` and kwargs ``mimetype``, ``cwd``, ``uri_cwd``,\nand ``debug``. For example, to use\n`libsass-python \u003chttps://github.com/dahlia/libsass-python\u003e`_ for SASS files\ninstead of the built-in SassCompressor, create your custom compressor class:\n\n.. code-block:: python\n\n    import sass\n\n    class CustomSassCompressor(object):\n        \"\"\"Custom compressor for text/sass mimetype.\n\n        Uses libsass-python for compression.\n        \"\"\"\n\n        @classmethod\n        def compile(cls, text, cwd=None, **kwargs):\n\n            include_paths = []\n            if cwd:\n                include_paths += [cwd]\n\n            return sass.compile(string=text, include_paths=include_paths)\n\nThen tell jac to use your custom compressor for ``text/sass`` mimetypes:\n\n.. code-block:: python\n\n    env.compressor_classes['text/sass'] = CustomSassCompressor\n\nThe equivalent for Flask is:\n\n.. code-block:: python\n\n    jac.set_compressor('text/sass', CustomSassCompressor)\n\nTo only customize the path of a compressor which forks a subprocess for the\ncompile step (LessCompressor, CoffeeScriptCompressor, and SassCompressor), just\nextend the compressor class and overwrite the ``binary`` class attribute:\n\n.. code-block:: python\n\n    from jac.compressors import SassCompressor\n\n    class CustomSassCompressor(SassCompressor):\n        \"\"\"Custom SASS compressor using Compass binary instead of libsass for text/sass mimetype.\n\n        Uses the faster libsass wrapper sassc for SASS compression.\n        https://github.com/sass/sassc\n        \"\"\"\n\n        binary = '/usr/bin/sassc'\n\n    # Tell Flask to use our custom SASS compressor\n    jac.set_compressor('text/sass', CustomSassCompressor)\n\n\nRunning Tests\n-------------\n\n::\n\n    virtualenv venv\n    . venv/bin/activate\n    pip install -r requirements_tests.txt\n    make coverage\n    make lint\n\nOr use tox to run with multiple python versions:\n\n::\n\n    pip install tox\n    tox\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaysonsantos%2Fjinja-assets-compressor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaysonsantos%2Fjinja-assets-compressor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaysonsantos%2Fjinja-assets-compressor/lists"}