Adding examples.

This commit is contained in:
Justin Hileman
2010-03-30 14:57:18 -04:00
parent a51146f5e2
commit 5e99b15252
12 changed files with 82 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
<?php
class Comments extends Mustache {
public function title() {
return 'A Comedy of Errors';
}
}
+1
View File
@@ -0,0 +1 @@
<h1>{{title}}{{! just something interesting... or not... }}</h1>
+1
View File
@@ -0,0 +1 @@
<h1>A Comedy of Errors</h1>
+16
View File
@@ -0,0 +1,16 @@
<h1>{{header}}</h1>
{{#list}}
<ul>
{{#item}}
{{#current}}
<li><strong>{{name}}</strong></li>
{{/current}}
{{#link}}
<li><a href="{{url}}">{{name}}</a></li>
{{/link}}
{{/item}}
</ul>
{{/list}}
{{#empty}}
<p>The list is empty.</p>
{{/empty}}
+24
View File
@@ -0,0 +1,24 @@
<?php
class Complex extends Mustache {
public $header = 'Colors';
public $item = array(
array('name' => 'red', 'current' => true, 'url' => '#Red'),
array('name' => 'green', 'current' => false, 'url' => '#Green'),
array('name' => 'blue', 'current' => false, 'url' => '#Blue'),
);
public function link() {
// Exploit the fact that the current iteration item is at the top of the context stack.
return $this->getVariable($current) != true;
}
public function list() {
return !($this->empty());
}
public function empty() {
return count($this->item) === 0;
}
}
+6
View File
@@ -0,0 +1,6 @@
<h1>Colors</h1>
<ul>
<li><strong>red</strong></li>
<li><a href="#Green">green</a></li>
<li><a href="#Blue">blue</a></li>
</ul>
+12
View File
@@ -0,0 +1,12 @@
<?php
class Simple extends Mustache {
public $name = "Chris";
public $value = 10000;
public function taxed_value() {
return $this->value - ($this->value * 0.4);
}
public $in_ca = true;
};
+5
View File
@@ -0,0 +1,5 @@
Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{ taxed_value }}, after taxes.
{{/in_ca}}
+3
View File
@@ -0,0 +1,3 @@
Hello Chris
You have just won $10000!
Well, $6000, after taxes.
+5
View File
@@ -0,0 +1,5 @@
<?php
class Unescaped extends Mustache {
public $title = "Bear > Shark";
}
+1
View File
@@ -0,0 +1 @@
<h1>{{{title}}}</h1>
+1
View File
@@ -0,0 +1 @@
<h1>Bear > Shark</h1>