Giter Club home page Giter Club logo

tgext.webassets's Introduction

About tgext.webassets

tgext.webassets is a TurboGears2 extension for assets management based on WebAssets.

Installing

tgext.webassets can be installed from pypi:

pip install tgext.webassets

should just work for most of the users.

Usage

To enable tgext.webassets put inside your application config/app_cfg.py the following:

from tgext import webassets

webassets.plugme(base_config, bundles={
    'js_all': webassets.Bundle('javascript/jquery.js', 'javascript/bootstrap.min.js',
                               filters='rjsmin', output='assets/js_all.js')
})

or you can use tgext.pluggable when available:

from tgext.pluggable import plug
from tgext.webassets import Bundle

plug(base_config, 'tgext.webassets', bundles={
    'js_all': Bundle('javascript/jquery.js', 'javascript/bootstrap.min.js',
                     filters='rjsmin', output='assets/js_all.js')
})

By default tgext.webassets will load and save assets inside the turbogears static_files path. Which is usually the public directory inside your application.

Note

Due to tgext.webassets writing files to the same place where it loads them, it is suggested you add a subdirectory to the output option of your bundles, so that the resulting files do not mix with the source files.

The webassets environment will then be available as tg.app_globals.webassets, so you can use it inside your templates to load the assets:

<script py:for="asset_url in g.webassets.js_all.urls()" src="$asset_url"></script>

Each registered bundle will be available as a property of the g.webassets object inside templates.

Bundles

ŧgext.webassets accepts the bundles inside the bundles dictionary. Each entry can be a Bundle instance or a webassets loader in case you want to load bundles from a configuration file.

Configuring

Options available in WebAssets Environment are also available in tgext.webassets, pass them as arguments to the plug (inside the options dictionary when using tgext.webassets.plugme) or provide the through AppConfig or .ini file with webassets. namespace.

Some have values that are inherited from your project configuration if not specified:

  • debug: If webassets is running in debug mode or not, by default is False.
  • base_dir: The directory assets will be located. By default is your project static_files directory.
  • base_url: The url static assets are served, by default /. Use this option to serve them from a CDN.
  • cache: If we should use webassets cache (if boolean), or override default path to cache directory by default assets are cached inside the .webassets-cache directory inside base_dir.

Builtin Filters

tgext.webassets comes with builtin the rjsmin and cssmin filter, all webassets filters work if the required tools are available.

tgext.webassets's People

Contributors

amol- avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.