kriswallsmith/assetic — pull request #574 by webmozart (2014-02-25 09:54:17+00:00)
Title: Added LazyAsseticNode which can be modified by NodeVisitors

Twig allows to modify template nodes in node visitors in order to influence the way they are generated. With the current implementation of `AsseticNode` however, the possibilities are limited, because the assets are already created when the node is created.

I added a separate `LazyAsseticNode` which removes this limitation. There, the asset is only created during compile time (unless it has been created by a visitor already). In this way, you can write node visitors which modify the node's inputs, filters, name etc. before creating the asset:

```php
class MyNodeVisitor implements \Twig_NodeVisitor
{
protected function enterNode(\Twig_NodeInterface $node)
{
if ($node instanceof LazyAsseticNode) {
$inputs = $node->getAttribute('inputs');

foreach ($inputs as $key => $value) {
$inputs[$key] = // do stuff ...
}

$node->setAttribute('inputs', $inputs);
}
}
}
```

Lazy asset creation can be activated by passing `true` to the fourth argument `$lazyAssets` of the AsseticExtension. This way, the implementation is fully backwards compatible.

An alternative solution would be to change the existing `AsseticNode`/`AsseticTokenParser` to create the asset on-demand. A consequence would be that the "asset" attribute of the node would not be available anymore during the traversal of the node tree. Any node visitor that currently uses this attribute would fail.

If you prefer the second solution regardless of the BC break, I can adapt the PR.