neuland/jade4j — pull request #8 by michaelkrog (2012-06-13 06:52:03+00:00)
Title: Fix missing (promised) support for sub blocks in mixin injections 

This fixes the support for sub blocks in mixins. I have added the tests to really show it.

To make i happen I have done mainly these things:
1): Made MixinNode clonable.
2): At every injection the needed Mixin is cloned before nodes are injected
3): Matcher for block changed to also match the word 'block' without any appended text at all.
4): Added logic to find injectionpoint by looking for an empty block in the mixin.

There is however one thing that bugs me in this commit, and that is the method I have written for finding the injectionpoint. I works, but its ugly.

Perhaps you guys can find a nicer way to find the empty block node within a MixinNode?

This is how it looks like in MixinInjectNode:
```Java
public void execute(IndentWriter writer, JadeModel model, JadeTemplate template) throws JadeCompilerException {
// Code before injection...
if(hasBlock()) {
Node injectionPoint = getInjectionPoint(mixin.getBlock());
if(injectionPoint != null) {
injectionPoint.getNodes().add(block);
}
}
// Code after injection...
}

private Node getInjectionPoint(Node block) {
for(Node node : block.getNodes()) {
if(node instanceof BlockNode && !node.hasNodes()) {
return node;
}

if(node.hasBlock()) {
if(!node.getBlock().hasNodes()) {
return node.getBlock();
}

Node nodeFromTree = getInjectionPoint(node.getBlock());
if(nodeFromTree != null) {
return nodeFromTree;
}
}

Node nodeFromTree = getInjectionPoint(node);
if(nodeFromTree != null) {
return nodeFromTree;
}
}
return null;
}
```