Skip to content

Instantly share code, notes, and snippets.

@miracle2k
Forked from sveetch/toast.py
Created November 17, 2012 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miracle2k/4093351 to your computer and use it in GitHub Desktop.
Save miracle2k/4093351 to your computer and use it in GitHub Desktop.
Testing a bug with webassets
"""
Usage with the following directory structure : ::
sources/
js/
css/
images/
_build/
static/
css/
js/
images/
index.html
"""
import os
from webassets import Environment as AssetsEnvironment
from webassets import Bundle
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
# Sources directory where the assets will be searched
SOURCES_DIR = 'sources'
SOURCES_DIR = os.path.join(PROJECT_DIR, SOURCES_DIR)
# Templates directory
TEMPLATES_DIR = 'sources/templates'
TEMPLATES_DIR = os.path.join(PROJECT_DIR, TEMPLATES_DIR)
# Directory where all stuff will be builded
PUBLISH_DIR = '_build'
PUBLISH_DIR = os.path.join(PROJECT_DIR, PUBLISH_DIR)
# Path where will be moved all the static files, usually this is a directory in
# the ``PUBLISH_DIR``
STATIC_DIR = '_build/static'
STATIC_DIR = os.path.join(PROJECT_DIR, STATIC_DIR)
# The static url to use in templates and with webassets
# This can be a full URL like http://, a relative path or an absolute path
STATIC_URL = '/static/'
"""
INIT ENVIRONNEMENTS
"""
assets_env = AssetsEnvironment()
assets_env.debug = True
assets_env.url = STATIC_URL
assets_env.directory = STATIC_DIR
assets_env.append_path(SOURCES_DIR, '/url/to/load_path')
assets_env.cache = os.path.join(PROJECT_DIR, ".webassets-external")
BUNDLES = {
'css_screen_common': Bundle(
'css/screen.css',
filters='yui_css',
output='css/screen.min.css'
),
'js_jquery': Bundle(
'js/jquery/jquery-1.7.1.js',
filters='yui_js',
output='js/jquery.min.js'
),
}
# Register enabled assets bundles
for k,v in BUNDLES.items():
assets_env.register(k, v)
# for debugging purpopse
print
for k,v in BUNDLES.items():
print assets_env[k].resolve_output()
print assets_env[k].urls()
print
# Another resolve to simulate an usage within templates like Jinja2
print
for k,v in BUNDLES.items():
print assets_env[k].resolve_output()
print assets_env[k].urls()
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment