Skip to content

Instantly share code, notes, and snippets.

@abourget
Created April 3, 2012 16:55
Show Gist options
  • Save abourget/2293632 to your computer and use it in GitHub Desktop.
Save abourget/2293632 to your computer and use it in GitHub Desktop.
Using DustJS + WebAssets + Pyramid
webassets.base_dir=%(here)s/myapp
webassets.base_url=/
webassets.debug=True
webassets.updater=timestamp
webassets.cache=True
webassets.DUSTY_PATH=/path/to/myapp/node_modules/dusty/bin/dusty
# after installation, following instructions here:
# https://github.com/abourget/webassets/blob/master/src/webassets/filter/dust.py#LC16

Setting these things up

Until everyone has merged my pull requests, you should get these:

https://github.com/abourget/webassets https://github.com/abourget/pyramid_webassets

Pending pull requests:

miracle2k/webassets#123 sontek/pyramid_webassets#3

Of course, you should learn a bit about WebAssets first :)

Minifying the dust core

When you install with "npm install" (see development.ini around here), look into node_modules/dust/dist.

You can also run:

make dust make min

from within node_modules/

Then you need the 'minmin' module from https://github.com/akdubya/minmin .. etc.. I didn't finish this

from pyramid_webassets import IWebAssetsEnvironment
def add_renderer_globals(event):
...
event['webassets'] = request.registry.queryUtility(IWebAssetsEnvironment)
<!--
dust-core...min.js is taken from the dust repository, minified if you will.
-->
<script type="text/javascript" src="/path/to/your/dust/dust-core-0.3.0.min.js"></script>
% for link in webassets['dust_templates'].urls():
<script type="text/javascript" src="${link}"></script>
% endfor
from webassets import Bundle
dust_bundle = Bundle('templates/dust',
filters="dustjs",
output="static/gen/dust_templates.%(version)s.js",
debug=False)
def main(...):
config = Configurator(...)
config.include('pyramid_webassets')
config.add_webasset('dust_templates', dust_bundle)
config.add_subscriber('myapp.subscribers.add_renderer_globals',
'pyramid.events.BeforeRender')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment