On Wed, Jun 13, 2012 at 10:27 AM, Mark Huang <[email protected]> wrote: > Hi everyone, > > Thanks to everyone that contributed to this thread, I really appreciate it. I > have one more question that's been bothering me though: > > Managing assets in you python code, be it writing a bundle/library OR calling > a jquery.need() while writing your pyramid view, this just feels a bit weird. > I was actually hoping for a solution much like minimattic where by the > minification/combination of assets are specified in your templates. Maybe > it's just me, but don't you guys think it's more natural ?
I prefer not setting minification in my templates because I want it to be a runtime option (to be flipped off during development for easier debugging). The debug mode of webassets makes that easy. Fanstatic has something similar as well. Instead, I set up most of my assets using the yaml support in webassets: https://github.com/hypothesis/h/blob/bff441621535674adcd2834a64927c6665de3e67/h/resources.yaml Combining that with my resources.py, I end up with the webassets environment in my template globals, as I said before: https://github.com/hypothesis/h/blob/bff441621535674adcd2834a64927c6665de3e67/h/resources.py#L38 If you try webassets, you also need to turn off the cache and manifest depending on the assets that are being bundled. This may only be necessary if you're using things that need to be forced debug=False, such as SASS/SCSS or CoffeeScript which cannot be served directly to the browser. https://github.com/hypothesis/h/blob/bff441621535674adcd2834a64927c6665de3e67/development.ini#L27 Note that I haven't actually added the minifiers to the end of my filter chains, but you can see by the output names where I plan to. > > And what if I had base templates that always use jquery and jqueryui, must I > specify that I need to use it in every single vie/controller ( I come from a > pylons world ) that I write? This is part of why I switched to webassets. At first I thought .need() was neat, but then I realized that it's more often my templates than my view functions that need to specify the assets. Also, it bothered me that some injector middleware would need to read the body on the way out looking for the </head> or </body> and injecting the assets. That seems like extra work when I could just write it in to my template. To answer your previous question, the mako syntax would be something like: % for href in environment['css_bundle'].urls(): <link rel="stylesheet" href="${href}" /> % endfor Also, it should go without saying these are just my preferences. There are also other projects like https://github.com/tav/assetgen and probably others. -Randall -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
