Update examples for v2.0
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ChildContext extends Mustache {
|
class ChildContext {
|
||||||
public $parent = array(
|
public $parent = array(
|
||||||
'child' => 'child works',
|
'child' => 'child works',
|
||||||
);
|
);
|
||||||
|
|
||||||
public $grandparent = array(
|
public $grandparent = array(
|
||||||
'parent' => array(
|
'parent' => array(
|
||||||
'child' => 'grandchild works',
|
'child' => 'grandchild works',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?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,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Complex extends Mustache {
|
class Complex {
|
||||||
public $header = 'Colors';
|
public $header = 'Colors';
|
||||||
|
|
||||||
public $item = array(
|
public $item = array(
|
||||||
@@ -16,4 +16,4 @@ class Complex extends Mustache {
|
|||||||
public function isEmpty() {
|
public function isEmpty() {
|
||||||
return count($this->item) === 0;
|
return count($this->item) === 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() {
|
||||||
@@ -11,4 +11,4 @@ class Delimiters extends Mustache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public $final = "Then, surprisingly, it worked the final time.";
|
public $final = "Then, surprisingly, it worked the final time.";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,5 +1,4 @@
|
|||||||
* Chris Firescythe
|
* Chris Firescythe
|
||||||
* 24
|
* 24
|
||||||
* Cycling, Fishing
|
|
||||||
* Cincinnati, OH
|
* Cincinnati, OH
|
||||||
* Normal
|
* Normal
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class DoubleSection extends Mustache {
|
class DoubleSection {
|
||||||
public function t() {
|
public function t() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public $two = "second";
|
public $two = "second";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Escaped extends Mustache {
|
class Escaped {
|
||||||
public $title = '"Bear" > "Shark"';
|
public $title = '"Bear" > "Shark"';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
<?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')
|
||||||
));
|
));
|
||||||
|
|
||||||
$parent2 = new stdClass();
|
$parent2 = new stdClass();
|
||||||
$parent2->parent_id = 'parent2';
|
$parent2->parent_id = 'parent2';
|
||||||
$parent2->child_contexts = array(
|
$parent2->child_contexts = array(
|
||||||
array('child_id' => 'parent2-child1'),
|
array('child_id' => 'parent2-child1'),
|
||||||
array('child_id' => 'parent2-child2')
|
array('child_id' => 'parent2-child2')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->parent_contexts[] = $parent2;
|
$this->parent_contexts[] = $parent2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,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 > 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!! >
|
|
||||||
< RAWR!! >
|
|
||||||
@@ -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',
|
||||||
@@ -13,4 +9,4 @@ class RecursivePartials extends Mustache {
|
|||||||
'child' => false,
|
'child' => false,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(
|
||||||
@@ -13,4 +13,4 @@ class SectionIteratorObjects extends Mustache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public $final = "Then, surprisingly, it worked the final time.";
|
public $final = "Then, surprisingly, it worked the final time.";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() {
|
||||||
@@ -23,4 +23,4 @@ class MagicObject {
|
|||||||
public function __isset($key) {
|
public function __isset($key) {
|
||||||
return isset($this->_data[$key]);
|
return isset($this->_data[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() {
|
||||||
@@ -13,4 +13,4 @@ class SectionObjects extends Mustache {
|
|||||||
class SectionObject {
|
class SectionObject {
|
||||||
public $foo = 'And it worked the second time.';
|
public $foo = 'And it worked the second time.';
|
||||||
public $bar = 'As well as the third.';
|
public $bar = 'As well as the third.';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() {
|
||||||
@@ -11,4 +11,4 @@ class Sections extends Mustache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public $final = "Then, surprisingly, it worked the final time.";
|
public $final = "Then, surprisingly, it worked the final time.";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() {
|
||||||
@@ -30,4 +30,4 @@ class SectionsNested extends Mustache {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Simple extends Mustache {
|
class Simple {
|
||||||
public $name = "Chris";
|
public $name = "Chris";
|
||||||
public $value = 10000;
|
public $value = 10000;
|
||||||
|
|
||||||
@@ -9,4 +9,4 @@ class Simple extends Mustache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public $in_ca = true;
|
public $in_ca = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Unescaped extends Mustache {
|
class Unescaped {
|
||||||
public $title = "Bear > Shark";
|
public $title = "Bear > Shark";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class UTF8Unescaped extends Mustache {
|
class UTF8 {
|
||||||
public $test = '中文又来啦';
|
public $test = '中文又来啦';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class UTF8 extends Mustache {
|
class UTF8Unescaped {
|
||||||
public $test = '中文又来啦';
|
public $test = '中文又来啦';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 @@
|
|||||||
|
* {{.}}
|
||||||
Reference in New Issue
Block a user