Update examples for v2.0

This commit is contained in:
Justin Hileman
2012-02-29 18:02:36 -08:00
parent d2136d91b3
commit 1d116d1b77
40 changed files with 69 additions and 132 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
class ChildContext extends Mustache { class ChildContext {
public $parent = array( public $parent = array(
'child' => 'child works', 'child' => 'child works',
); );
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
class Comments extends Mustache { class Comments {
public function title() { public function title() {
return 'A Comedy of Errors'; return 'A Comedy of Errors';
} }
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
class Complex extends Mustache { class Complex {
public $header = 'Colors'; public $header = 'Colors';
public $item = array( public $item = array(
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
class Delimiters extends Mustache { class Delimiters {
public $start = "It worked the first time."; public $start = "It worked the first time.";
public function middle() { public function middle() {
+2 -8
View File
@@ -1,19 +1,13 @@
<?php <?php
/** class DotNotation {
* DotNotation example class. Uses DOT_NOTATION pragma.
*
* @extends Mustache
*/
class DotNotation extends Mustache {
public $person = array( public $person = array(
'name' => array('first' => 'Chris', 'last' => 'Firescythe'), 'name' => array('first' => 'Chris', 'last' => 'Firescythe'),
'age' => 24, 'age' => 24,
'hobbies' => array('Cycling', 'Fishing'),
'hometown' => array( 'hometown' => array(
'city' => 'Cincinnati', 'city' => 'Cincinnati',
'state' => 'OH', 'state' => 'OH',
), )
); );
public $normal = 'Normal'; public $normal = 'Normal';
@@ -1,5 +1,4 @@
* {{person.name.first}} {{person.name.last}} * {{person.name.first}} {{person.name.last}}
* {{person.age}} * {{person.age}}
* {{person.hobbies.0}}, {{person.hobbies.1}}
* {{person.hometown.city}}, {{person.hometown.state}} * {{person.hometown.city}}, {{person.hometown.state}}
* {{normal}} * {{normal}}
-1
View File
@@ -1,5 +1,4 @@
* Chris Firescythe * Chris Firescythe
* 24 * 24
* Cycling, Fishing
* Cincinnati, OH * Cincinnati, OH
* Normal * Normal
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
class DoubleSection extends Mustache { class DoubleSection {
public function t() { public function t() {
return true; return true;
} }
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
class Escaped extends Mustache { class Escaped {
public $title = '"Bear" > "Shark"'; public $title = '"Bear" > "Shark"';
} }
@@ -1,12 +1,10 @@
<?php <?php
class GrandParentContext extends Mustache { class GrandParentContext {
public $grand_parent_id = 'grand_parent1'; public $grand_parent_id = 'grand_parent1';
public $parent_contexts = array(); public $parent_contexts = array();
public function __construct() { public function __construct() {
parent::__construct();
$this->parent_contexts[] = array('parent_id' => 'parent1', 'child_contexts' => array( $this->parent_contexts[] = array('parent_id' => 'parent1', 'child_contexts' => array(
array('child_id' => 'parent1-child1'), array('child_id' => 'parent1-child1'),
array('child_id' => 'parent1-child2') array('child_id' => 'parent1-child2')
+3 -3
View File
@@ -1,6 +1,6 @@
<?php <?php
class I18n extends Mustache { class I18n {
// Variable to be interpolated // Variable to be interpolated
public $name = 'Bob'; public $name = 'Bob';
@@ -9,12 +9,12 @@ class I18n extends Mustache {
public $__ = array(__CLASS__, '__trans'); public $__ = array(__CLASS__, '__trans');
// A *very* small i18n dictionary :) // A *very* small i18n dictionary :)
private $dictionary = array( private static $dictionary = array(
'Hello.' => 'Hola.', 'Hello.' => 'Hola.',
'My name is {{ name }}.' => 'Me llamo {{ name }}.', 'My name is {{ name }}.' => 'Me llamo {{ name }}.',
); );
public function __trans($text) { public function __trans($text) {
return isset($this->dictionary[$text]) ? $this->dictionary[$text] : $text; return isset(self::$dictionary[$text]) ? self::$dictionary[$text] : $text;
} }
} }
@@ -1,5 +1,5 @@
<?php <?php
class ImplicitIterator extends Mustache { class ImplicitIterator {
protected $data = array('Donkey Kong', 'Luigi', 'Mario', 'Peach', 'Yoshi'); public $data = array('Donkey Kong', 'Luigi', 'Mario', 'Peach', 'Yoshi');
} }
@@ -1,6 +1,6 @@
<?php <?php
class InvertedDoubleSection extends Mustache { class InvertedDoubleSection {
public $t = false; public $t = false;
public $two = 'second'; public $two = 'second';
} }
@@ -1,5 +1,5 @@
<?php <?php
class InvertedSection extends Mustache { class InvertedSection {
public $repo = array(); public $repo = array();
} }
@@ -1,2 +1,6 @@
{{#repo}}<b>{{name}}</b>{{/repo}} {{#repo}}
{{^repo}}No repos :({{/repo}} <b>{{name}}</b>
{{/repo}}
{{^repo}}
No repos :(
{{/repo}}
@@ -1 +1 @@
No repos :( No repos :(
+1 -5
View File
@@ -1,13 +1,9 @@
<?php <?php
class Partials extends Mustache { class Partials {
public $name = 'ilmich'; public $name = 'ilmich';
public $data = array( public $data = array(
array('name' => 'federica', 'age' => 27, 'gender' => 'female'), array('name' => 'federica', 'age' => 27, 'gender' => 'female'),
array('name' => 'marco', 'age' => 32, 'gender' => 'male'), array('name' => 'marco', 'age' => 32, 'gender' => 'male'),
); );
protected $_partials = array(
'children' => "{{#data}}{{name}} - {{age}} - {{gender}}\n{{/data}}",
);
} }
@@ -0,0 +1,2 @@
{{#data}}{{name}} - {{age}} - {{gender}}
{{/data}}
@@ -1,19 +0,0 @@
<?php
class PartialsWithViewClass extends Mustache {
public function __construct($template = null, $view = null, $partials = null) {
// Use an object of an arbitrary class as a View for this Mustache instance:
$view = new StdClass();
$view->name = 'ilmich';
$view->data = array(
array('name' => 'federica', 'age' => 27, 'gender' => 'female'),
array('name' => 'marco', 'age' => 32, 'gender' => 'male'),
);
$partials = array(
'children' => "{{#data}}{{name}} - {{age}} - {{gender}}\n{{/data}}",
);
parent::__construct($template, $view, $partials);
}
}
@@ -1,2 +0,0 @@
Children of {{name}}:
{{>children}}
@@ -1,3 +0,0 @@
Children of ilmich:
federica - 27 - female
marco - 32 - male
@@ -1,5 +0,0 @@
<?php
class PragmaUnescaped extends Mustache {
public $vs = 'Bear > Shark';
}
@@ -1,3 +0,0 @@
{{%UNESCAPED}}
{{vs}}
{{{vs}}}
@@ -1,2 +0,0 @@
Bear > Shark
Bear &gt; Shark
@@ -1,8 +0,0 @@
<?php
class PragmasInPartials extends Mustache {
public $say = '< RAWR!! >';
protected $_partials = array(
'dinosaur' => '{{say}}'
);
}
@@ -1,3 +0,0 @@
{{%UNESCAPED}}
{{say}}
{{>dinosaur}}
@@ -1,2 +0,0 @@
< RAWR!! >
&lt; RAWR!! &gt;
@@ -1,10 +1,6 @@
<?php <?php
class RecursivePartials extends Mustache { class RecursivePartials {
protected $_partials = array(
'child' => " > {{ name }}{{#child}}{{>child}}{{/child}}",
);
public $name = 'George'; public $name = 'George';
public $child = array( public $child = array(
'name' => 'Dan', 'name' => 'Dan',
@@ -0,0 +1 @@
> {{ name }}{{#child}}{{>child}}{{/child}}
@@ -1,6 +1,6 @@
<?php <?php
class SectionIteratorObjects extends Mustache { class SectionIteratorObjects {
public $start = "It worked the first time."; public $start = "It worked the first time.";
protected $_data = array( protected $_data = array(
@@ -1,6 +1,6 @@
<?php <?php
class SectionMagicObjects extends Mustache { class SectionMagicObjects {
public $start = "It worked the first time."; public $start = "It worked the first time.";
public function middle() { public function middle() {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
class SectionObjects extends Mustache { class SectionObjects {
public $start = "It worked the first time."; public $start = "It worked the first time.";
public function middle() { public function middle() {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
class Sections extends Mustache { class Sections {
public $start = "It worked the first time."; public $start = "It worked the first time.";
public function middle() { public function middle() {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
class SectionsNested extends Mustache { class SectionsNested {
public $name = 'Little Mac'; public $name = 'Little Mac';
public function enemies() { public function enemies() {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
class Simple extends Mustache { class Simple {
public $name = "Chris"; public $name = "Chris";
public $value = 10000; public $value = 10000;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
class Unescaped extends Mustache { class Unescaped {
public $title = "Bear > Shark"; public $title = "Bear > Shark";
} }
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
class UTF8Unescaped extends Mustache { class UTF8 {
public $test = '中文又来啦'; public $test = '中文又来啦';
} }
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
class UTF8 extends Mustache { class UTF8Unescaped {
public $test = '中文又来啦'; public $test = '中文又来啦';
} }
+1 -7
View File
@@ -7,10 +7,8 @@
* tags should strip leading and trailing whitespace in key names. * tags should strip leading and trailing whitespace in key names.
* *
* `{{> tag }}` and `{{> tag}}` and `{{>tag}}` should all be equivalent. * `{{> tag }}` and `{{> tag}}` and `{{>tag}}` should all be equivalent.
*
* @extends Mustache
*/ */
class Whitespace extends Mustache { class Whitespace {
public $foo = 'alpha'; public $foo = 'alpha';
public $bar = 'beta'; public $bar = 'beta';
@@ -30,8 +28,4 @@ class Whitespace extends Mustache {
array('key with space' => 'G'), array('key with space' => 'G'),
); );
} }
protected $_partials = array(
'alphabet' => " * {{.}}\n",
);
} }
@@ -0,0 +1 @@
* {{.}}