Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita58ea3c

Browse files
authored
Merge pull request#56 from goetas/fix-55
Handle "t:block-inner" within an "extends"
2 parents4bec6f1 +bceb64f commita58ea3c

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/.project
44
/vendor
55
.idea
6+
composer.lock

‎.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,25 @@ matrix:
2020
dist:trusty
2121
group:edge
2222
-php:5.3
23+
dist:precise
2324
-php:5.4
2425
-php:5.5
2526
-php:5.6
2627
-php:7.0
2728
-php:7.1
29+
-php:7.2
2830

2931
# Twig 2
3032
-php:7.0
3133
env:TWIG_VERSION='^2.0'
3234
-php:7.1
3335
env:TWIG_VERSION='^2.0'
36+
-php:7.2
37+
env:TWIG_VERSION='^2.0'
3438

3539
# oldest possible deps for twig 1.x
3640
-php:5.3# for twig 1.x
41+
dist:precise
3742
env:COMPOSER_FLAGS='--prefer-lowest --prefer-stable' TWIG_VERSION=^1.28
3843
-php:7.0# for twig 2.x
3944
env:COMPOSER_FLAGS='--prefer-lowest --prefer-stable' TWIG_VERSION=^2.0

‎src/Attribute/BlockInnerAttribute.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,5 @@ public function visit(\DOMAttr $att, Compiler $context)
3939
$sandbox->appendChild($end);
4040

4141
DOMHelper::replaceWithSet($sandbox,iterator_to_array($sandbox->childNodes));
42-
if ($node->parentNode ===$node->ownerDocument->documentElement) {
43-
DOMHelper::replaceWithSet($node,iterator_to_array($node->childNodes));
44-
}
4542
}
4643
}

‎src/Attribute/ExtendsAttribute.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function visit(\DOMAttr $att, Compiler $context)
3131
}
3232
}
3333

34+
// having block-inner makes no sense when child of an t:extends (t:extend can have only t:block child)
35+
// so lets convert them to t:block nodes
36+
$candidates =$this->convertBlockInnerIntoBlock($candidates,$node);
37+
3438
foreach ($candidatesas$candidate) {
3539
if ($candidate->parentNode !==$node) {
3640
$candidate->parentNode->removeChild($candidate);
@@ -57,4 +61,37 @@ public function visit(\DOMAttr $att, Compiler $context)
5761

5862
DOMHelper::replaceWithSet($node,$set);
5963
}
64+
65+
/**
66+
* @param array $candidates
67+
* @param \DOMNode $node
68+
* @return array
69+
*/
70+
privatefunctionconvertBlockInnerIntoBlock(array$candidates,\DOMNode$node)
71+
{
72+
/**
73+
* @var $candidate \DOMElement
74+
*/
75+
foreach ($candidatesas$k =>$candidate) {
76+
if ($candidate->hasAttributeNS(Twital::NS,"block-inner")) {
77+
78+
$blockName =$candidate->getAttributeNS(Twital::NS,"block-inner");
79+
80+
$block =$node->ownerDocument->createElementNS(Twital::NS,"block");
81+
$block->setAttribute("name",$blockName);
82+
83+
$candidate->parentNode->insertBefore($block,$candidate);
84+
85+
// move all child to the new block node
86+
while ($candidate->firstChild) {
87+
$child =$candidate->removeChild($candidate->firstChild);
88+
$block->appendChild($child);
89+
}
90+
$candidate->parentNode->removeChild($candidate);
91+
$candidates[$k] =$block;
92+
}
93+
}
94+
95+
return$candidates;
96+
}
6097
}

‎tests/Tests/CoreNodesTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ public function getData()
134134

135135
array('<t:omit>foo</t:omit>','foo'),
136136
array('<t:omit><div>foo</div></t:omit>','<div>foo</div>'),
137+
138+
array('<t:omit><div t:block="aaa">foo</div></t:omit>','<div>{% block aaa %}foo{% endblock %}</div>'),
139+
array('<t:omit><div t:block="aaa">foo</div><div t:block="bbb">bar</div></t:omit>','<div>{% block aaa %}foo{% endblock %}</div><div>{% block bbb %}bar{% endblock %}</div>'),
140+
array('<t:omit><div t:block="aaa">foo<div t:block="bbb">bar</div></div></t:omit>','<div>{% block aaa %}foo<div>{% block bbb %}bar{% endblock %}</div>{% endblock %}</div>'),
141+
137142
array('<div><t:omit t:if="0">foo</t:omit>bar</div>','<div>{% if 0 %}foo{% endif %}bar</div>'),
138143
array('<div><![CDATA[aa]]></div>','<div><![CDATA[aa]]></div>'),
139144
array('<div><!-- foo --></div>','<div><!-- foo --></div>'),
@@ -181,7 +186,6 @@ public function getDataFormTemplates()
181186
$expected,
182187
);
183188
}
184-
185189
return$data;
186190
}
187191

@@ -191,7 +195,6 @@ public function getDataFormTemplates()
191195
publicfunctiontestVisitNodeTemplates($source,$expected)
192196
{
193197
$compiled =$this->twital->compile($this->sourceAdapter,$source);
194-
195198
$cleanup =function ($str) {
196199
returnpreg_replace("/\s+/","",$str);
197200
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp