Skip to main content

Compiles and concatenates JavaScript and CSS assets.

Project description

https://secure.travis-ci.org/gears/gears.png?branch=develop

Gears is a library to compile and concatenate JavaScript and CSS assets, highly inspired by Ruby’s Sprockets. You can also write scripts, styles and client templates using CoffeeScript, Handlebars, Stylus, Less, and compile them using external packages (gears-coffeescript, gears-handlebars, gears-stylus, gears-less). These packages already include all required node.js modules, so you don’t need to worry about installing them yourself.

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.

Features

  • 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 path suffixed with the same extension as the current asset (e.g., if js/app.js.coffee has directive require views, js/views.js.coffee will be included). Supports globbing: require models/*.

    • require_directory :path: includes the contents of the every asset in the directory path with 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 path and all its subdirectories in alphabetical order.

    • require_self: includes the contents of the current asset at the current place. If there is no require_self directive, 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 @import functionality in some CSS pre-processors (Less or Stylus). Supports globbing: depend_on app/*.

    • 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.coffee CoffeeScript compiler will be used. Here are extensions for the supported compilers (through external packages):

    • CoffeeScript - .js.coffee;

    • Handlebars - .js.handlebars;

    • Stylus - .css.styl;

    • Less - .css.less.

  • Caching

  • Compressing. Supported compressors:

    New compilers can be also easily added.

  • Supports Python 3.

Installation

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.

Usage

This example compiles public assets (default: assets/js/script.js, assets/css/style.css, all assets that aren’t compiled to .css or .js and assets marked as public using public directive) from assets directory to static:

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.

Contributing

Feel free to fork, send pull requests or report bugs and issues on github.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Gears-0.7.2.tar.gz (107.2 kB view details)

Uploaded Source

File details

Details for the file Gears-0.7.2.tar.gz.

File metadata

  • Download URL: Gears-0.7.2.tar.gz
  • Upload date:
  • Size: 107.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Gears-0.7.2.tar.gz
Algorithm Hash digest
SHA256 e8c55a30e0b00bc7f0d2910d24eb512157808348878d1bc07533f2370e3445ff
MD5 8e788645833b297c37cd0d3baa452a8a
BLAKE2b-256 c6386fac78b7fde4b4ec5bc45176f23484adc9b8af742cf4f300c4daed8b50fa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page