Skip to content

Instantly share code, notes, and snippets.

@sveetch
Created November 16, 2012 21:50
Show Gist options
  • Save sveetch/4091232 to your computer and use it in GitHub Desktop.
Save sveetch/4091232 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.append_path("webassets-external", url=os.path.join(STATIC_URL, 'webassets-external'))
assets_env.append_path(os.path.join(STATIC_DIR, "webassets-external"), url=os.path.join(STATIC_URL, 'webassets-external'))
assets_env.url = STATIC_URL
assets_env.directory = STATIC_DIR
assets_env.load_path = [SOURCES_DIR]
#assets_env.cache = ".webassets-external"
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