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
class ChildContext extends Mustache {
class ChildContext {
public $parent = array(
'child' => 'child works',
);
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
class Comments extends Mustache {
class Comments {
public function title() {
return 'A Comedy of Errors';
}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
class Complex extends Mustache {
class Complex {
public $header = 'Colors';
public $item = array(
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
class Delimiters extends Mustache {
class Delimiters {
public $start = "It worked the first time.";
public function middle() {
+2 -8
View File
@@ -1,19 +1,13 @@
<?php
/**
* DotNotation example class. Uses DOT_NOTATION pragma.
*
* @extends Mustache
*/
class DotNotation extends Mustache {
class DotNotation {
public $person = array(
'name' => array('first' => 'Chris', 'last' => 'Firescythe'),
'age' => 24,
'hobbies' => array('Cycling', 'Fishing'),
'hometown' => array(
'city' => 'Cincinnati',
'state' => 'OH',
),
)
);
public $normal = 'Normal';
@@ -1,5 +1,4 @@
* {{person.name.first}} {{person.name.last}}
* {{person.age}}
* {{person.hobbies.0}}, {{person.hobbies.1}}
* {{person.hometown.city}}, {{person.hometown.state}}
* {{normal}}
-1
View File
@@ -1,5 +1,4 @@
* Chris Firescythe
* 24
* Cycling, Fishing
* Cincinnati, OH
* Normal
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
class DoubleSection extends Mustache {
class DoubleSection {
public function t() {
return true;
}
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
class Escaped extends Mustache {
class Escaped {
public $title = '"Bear" > "Shark"';
}
@@ -1,12 +1,10 @@
<?php
class GrandParentContext extends Mustache {
class GrandParentContext {
public $grand_parent_id = 'grand_parent1';
public $parent_contexts = array();
public function __construct() {
parent::__construct();
$this->parent_contexts[] = array('parent_id' => 'parent1', 'child_contexts' => array(
array('child_id' => 'parent1-child1'),
array('child_id' => 'parent1-child2')
+3 -3
View File
@@ -1,6 +1,6 @@
<?php
class I18n extends Mustache {
class I18n {
// Variable to be interpolated
public $name = 'Bob';
@@ -9,12 +9,12 @@ class I18n extends Mustache {
public $__ = array(__CLASS__, '__trans');
// A *very* small i18n dictionary :)
private $dictionary = array(
private static $dictionary = array(
'Hello.' => 'Hola.',
'My name is {{ name }}.' => 'Me llamo {{ name }}.',
);
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
class ImplicitIterator extends Mustache {
protected $data = array('Donkey Kong', 'Luigi', 'Mario', 'Peach', 'Yoshi');
class ImplicitIterator {
public $data = array('Donkey Kong', 'Luigi', 'Mario', 'Peach', 'Yoshi');
}
@@ -1,6 +1,6 @@
<?php
class InvertedDoubleSection extends Mustache {
class InvertedDoubleSection {
public $t = false;
public $two = 'second';
}
@@ -1,5 +1,5 @@
<?php
class InvertedSection extends Mustache {
class InvertedSection {
public $repo = array();
}
@@ -1,2 +1,6 @@
{{#repo}}<b>{{name}}</b>{{/repo}}
{{^repo}}No repos :({{/repo}}
{{#repo}}
<b>{{name}}</b>
{{/repo}}
{{^repo}}
No repos :(
{{/repo}}
+1 -5
View File
@@ -1,13 +1,9 @@
<?php
class Partials extends Mustache {
class Partials {
public $name = 'ilmich';
public $data = array(
array('name' => 'federica', 'age' => 27, 'gender' => 'female'),
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
class RecursivePartials extends Mustache {
protected $_partials = array(
'child' => " > {{ name }}{{#child}}{{>child}}{{/child}}",
);
class RecursivePartials {
public $name = 'George';
public $child = array(
'name' => 'Dan',
@@ -0,0 +1 @@
> {{ name }}{{#child}}{{>child}}{{/child}}
@@ -1,6 +1,6 @@
<?php
class SectionIteratorObjects extends Mustache {
class SectionIteratorObjects {
public $start = "It worked the first time.";
protected $_data = array(
@@ -1,6 +1,6 @@
<?php
class SectionMagicObjects extends Mustache {
class SectionMagicObjects {
public $start = "It worked the first time.";
public function middle() {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
class SectionObjects extends Mustache {
class SectionObjects {
public $start = "It worked the first time.";
public function middle() {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
class Sections extends Mustache {
class Sections {
public $start = "It worked the first time.";
public function middle() {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
class SectionsNested extends Mustache {
class SectionsNested {
public $name = 'Little Mac';
public function enemies() {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
class Simple extends Mustache {
class Simple {
public $name = "Chris";
public $value = 10000;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
class Unescaped extends Mustache {
class Unescaped {
public $title = "Bear > Shark";
}
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
class UTF8Unescaped extends Mustache {
class UTF8 {
public $test = '中文又来啦';
}
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
class UTF8 extends Mustache {
class UTF8Unescaped {
public $test = '中文又来啦';
}
+1 -7
View File
@@ -7,10 +7,8 @@
* tags should strip leading and trailing whitespace in key names.
*
* `{{> tag }}` and `{{> tag}}` and `{{>tag}}` should all be equivalent.
*
* @extends Mustache
*/
class Whitespace extends Mustache {
class Whitespace {
public $foo = 'alpha';
public $bar = 'beta';
@@ -30,8 +28,4 @@ class Whitespace extends Mustache {
array('key with space' => 'G'),
);
}
protected $_partials = array(
'alphabet' => " * {{.}}\n",
);
}
@@ -0,0 +1 @@
* {{.}}