1
|
|
|
<?php |
2
|
|
|
namespace Goetas\Twital\Attribute; |
3
|
|
|
|
4
|
|
|
use Goetas\Twital\Attribute as AttributeBase; |
5
|
|
|
use Goetas\Twital\Compiler; |
6
|
|
|
use Goetas\Twital\Helper\DOMHelper; |
7
|
|
|
use Goetas\Twital\Twital; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* This will translate '<div t:block-inner="name">foo</div>' into '<div>{% block name%}foo{% endblock %}</div>' |
11
|
|
|
* @author Asmir Mustafic <[email protected]> |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
class BlockInnerAttribute implements AttributeBase |
15
|
|
|
{ |
16
|
6 |
|
public function visit(\DOMAttr $att, Compiler $context) |
17
|
|
|
{ |
18
|
6 |
|
$node = $att->ownerElement; |
19
|
6 |
|
$node->removeAttributeNode($att); |
20
|
|
|
|
21
|
|
|
// create sandbox and append it to the node |
22
|
6 |
|
$sandbox = $node->ownerDocument->createElementNS(Twital::NS, "sandbox"); |
23
|
|
|
|
24
|
|
|
// move all child to sandbox to sandbox |
25
|
6 |
|
while ($node->firstChild) { |
26
|
6 |
|
$child = $node->removeChild($node->firstChild); |
27
|
6 |
|
$sandbox->appendChild($child); |
28
|
6 |
|
} |
29
|
6 |
|
$node->appendChild($sandbox); |
30
|
|
|
|
31
|
|
|
//$context->compileAttributes($node); |
32
|
6 |
|
$context->compileChilds($sandbox); |
33
|
|
|
|
34
|
|
|
|
35
|
6 |
|
$start = $context->createControlNode("block " . $att->value); |
36
|
6 |
|
$end = $context->createControlNode("endblock"); |
37
|
|
|
|
38
|
6 |
|
$sandbox->insertBefore($start, $sandbox->firstChild); |
39
|
6 |
|
$sandbox->appendChild($end); |
40
|
|
|
|
41
|
6 |
|
DOMHelper::replaceWithSet($sandbox, iterator_to_array($sandbox->childNodes)); |
42
|
6 |
|
if ($node->parentNode === $node->ownerDocument->documentElement) { |
43
|
3 |
|
DOMHelper::replaceWithSet($node, iterator_to_array($node->childNodes)); |
44
|
3 |
|
} |
45
|
6 |
|
} |
46
|
|
|
} |
47
|
|
|
|