Massive overhaul of Mustache.php's whitespace handling.

Move regex preparation into methods, use named subpatterns so the regex makes more sense. Fix the logic around eating newlines adjacent to tags. Update tests to reflect the changes.
This commit is contained in:
Justin Hileman
2010-11-24 07:45:24 -05:00
parent d026315a2c
commit 3e6b8102b7
13 changed files with 87 additions and 98 deletions
+11 -11
View File
@@ -1,16 +1,16 @@
<h1>{{header}}</h1>
{{#notEmpty}}
<ul>
{{#item}}
{{#current}}
<li><strong>{{name}}</strong></li>
{{/current}}
{{^current}}
<li><a href="{{url}}">{{name}}</a></li>
{{/current}}
{{/item}}
</ul>
<ul>
{{#item}}
{{#current}}
<li><strong>{{name}}</strong></li>
{{/current}}
{{^current}}
<li><a href="{{url}}">{{name}}</a></li>
{{/current}}
{{/item}}
</ul>
{{/notEmpty}}
{{#isEmpty}}
<p>The list is empty.</p>
<p>The list is empty.</p>
{{/isEmpty}}
+2 -2
View File
@@ -1,6 +1,6 @@
<h1>Colors</h1>
<ul>
<li><strong>red</strong></li>
<li><strong>red</strong></li>
<li><a href="#Green">green</a></li>
<li><a href="#Blue">blue</a></li>
</ul>
</ul>
@@ -1,7 +1,7 @@
{{#t}}
* first
* first
{{/t}}
* {{two}}
{{#t}}
* third
* third
{{/t}}
@@ -1,10 +1,7 @@
{{grand_parent_id}}
{{#parent_contexts}}
{{grand_parent_id}}
{{parent_id}}
{{#child_contexts}}
{{grand_parent_id}}
{{parent_id}}
{{child_id}}
{{/child_contexts}}
{{parent_id}} ({{grand_parent_id}})
{{#child_contexts}}
{{child_id}} ({{parent_id}} << {{grand_parent_id}})
{{/child_contexts}}
{{/parent_contexts}}
@@ -1,17 +1,7 @@
grand_parent1
grand_parent1
parent1
grand_parent1
parent1
parent1-child1
grand_parent1
parent1
parent1-child2
grand_parent1
parent2
grand_parent1
parent2
parent2-child1
grand_parent1
parent2
parent2-child2
parent1 (grand_parent1)
parent1-child1 (parent1 << grand_parent1)
parent1-child2 (parent1 << grand_parent1)
parent2 (grand_parent1)
parent2-child1 (parent2 << grand_parent1)
parent2-child2 (parent2 << grand_parent1)
@@ -1,7 +1,7 @@
{{^t}}
* first
* first
{{/t}}
* {{two}}
{{^t}}
* third
* third
{{/t}}
@@ -1,14 +0,0 @@
<?php
class SectionsSpaces extends Mustache {
public $start = "It worked the first time.";
public function middle() {
return array(
array('item' => "And it worked the second time."),
array('item' => "As well as the third."),
);
}
public $final = "Then, surprisingly, it worked the final time.";
}
@@ -1,9 +0,0 @@
* {{ start }}
{{# middle }}
* {{ item }}
{{/ middle }}
* {{ final }}
* {{ start }}
{{# middle }} * {{ item }}{{/ middle }}
* {{ final }}
@@ -1,9 +0,0 @@
* It worked the first time.
* And it worked the second time.
* As well as the third.
* Then, surprisingly, it worked the final time.
* It worked the first time.
* And it worked the second time.
* As well as the third.
* Then, surprisingly, it worked the final time.