Răsfoiți Sursa

Adding examples.

Justin Hileman 15 ani în urmă
părinte
comite
5e99b15252

+ 7 - 0
examples/comments/Comments.php

@@ -0,0 +1,7 @@
+<?php
+
+class Comments extends Mustache {
+	public function title() {
+		return 'A Comedy of Errors';
+	}
+}

+ 1 - 0
examples/comments/comments.mustache

@@ -0,0 +1 @@
+<h1>{{title}}{{! just something interesting... or not... }}</h1>

+ 1 - 0
examples/comments/comments.txt

@@ -0,0 +1 @@
+<h1>A Comedy of Errors</h1>

+ 16 - 0
examples/complex/complex.mustache

@@ -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 - 0
examples/complex/complex.php

@@ -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 - 0
examples/complex/complex.txt

@@ -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 - 0
examples/simple/Simple.php

@@ -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 - 0
examples/simple/simple.mustache

@@ -0,0 +1,5 @@
+Hello {{name}}
+You have just won ${{value}}!
+{{#in_ca}}
+Well, ${{ taxed_value }}, after taxes.
+{{/in_ca}}

+ 3 - 0
examples/simple/simple.txt

@@ -0,0 +1,3 @@
+Hello Chris
+You have just won $10000!
+Well, $6000, after taxes.

+ 5 - 0
examples/unescaped/Unescaped.php

@@ -0,0 +1,5 @@
+<?php
+
+class Unescaped extends Mustache {
+	public $title = "Bear > Shark";
+}

+ 1 - 0
examples/unescaped/unescaped.mustache

@@ -0,0 +1 @@
+<h1>{{{title}}}</h1>

+ 1 - 0
examples/unescaped/unescaped.txt

@@ -0,0 +1 @@
+<h1>Bear > Shark</h1>