There is also:
- django-gears, an app for Django that integrates Gears with Django project;
- Flask-Gears, an extension that integrates Gears with Flask application;
- gears-cli, a command-line utility that compiles assets. It also can watch assets for changes and automaticaly re-compile them.
Dependency management using directives in header comments. For example:
/* Dependencies: *= require jquery *= require underscore *= require backbone *= require_tree views *= require_directory templates */
Six directive types is supported for now:
require :path: includes the contents of the asset
pathsuffixed with the same extension as the current asset (e.g., if
js/views.js.coffeewill be included). Supports globbing:
require_directory :path: includes the contents of the every asset in the directory
pathwith the same suffix as the current asset in alphabetical order.
require_tree :path: includes the contents of the every asset with the same suffix as the current asset in the directory
pathand all its subdirectories in alphabetical order.
require_self: includes the contents of the current asset at the current place. If there is no
require_selfdirective, the contents will be appended at the end of asset.
depend_on :path: it is useful when you need to specify files that affect an asset, but not to include them into bundled asset or to include them using compilers. E.g., if you use
@importfunctionality in some CSS pre-processors (Less or Stylus). Supports globbing:
public: mark the asset as public.
Scripting and styling in modern languages like CoffeeScript, Stylus, Less (support for new languages can be easily added).
Writing client templates using Handlebars.
The list of compilers for the asset is specified with asset extensions appended to the original extension. E.g., for the asset named
js/app.js.coffeeCoffeeScript compiler will be used. Here are extensions for the supported compilers (through external packages):
- CoffeeScript -
- Handlebars -
- Stylus -
- Less -
- CoffeeScript -
Compressing. Supported compressors:
- SlimIt (Python, 2.X only);
- cssmin (Python, 2.X only);
- UglifyJS (Node.js, using gears-uglifyjs);
- clean-css (Node.js, using gears-clean-css).
New compilers can be also easily added.
Supports Python 3.
You can install
Gears using pip:
$ pip install Gears
If you want to use node.js-dependent compilers or compressors, you need to install other dependencies:
$ pip install gears-less # LESS $ pip install gears-stylus # Stylus $ pip install gears-handlebars # Handlebars $ pip install gears-coffeescript # CoffeeScript $ pip install gears-uglifyjs # UglifyJS $ pip install gears-clean-css # clean-css
Please note that all these compilers and compressors require node.js to be installed on your system.
This example compiles public assets (default:
assets/css/style.css, all assets that aren't compiled to .css or .js and
assets marked as public using
public directive) from
import os from gears.environment import Environment from gears.finders import FileSystemFinder ROOT_DIR = os.path.abspath(os.path.dirname(__file__)) ASSETS_DIR = os.path.join(ROOT_DIR, 'assets') STATIC_DIR = os.path.join(ROOT_DIR, 'static') env = Environment(STATIC_DIR) env.finders.register(FileSystemFinder([ASSETS_DIR])) env.register_defaults() if __name__ == '__main__': env.save()
There is already mentioned django-gears app, which you may want to use in your Django projects.
Feel free to fork, send pull requests or report bugs and issues on github.