Add support for PHP 5.2.x
This commit is contained in:
+2
-2
@@ -11,7 +11,7 @@ A quick example:
|
|||||||
|
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
$m = new Mustache;
|
$m = new Mustache_Mustache;
|
||||||
echo $m->render('Hello {{planet}}', array('planet' => 'World!')); // "Hello World!"
|
echo $m->render('Hello {{planet}}', array('planet' => 'World!')); // "Hello World!"
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ And render it:
|
|||||||
|
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
$m = new Mustache;
|
$m = new Mustache_Mustache;
|
||||||
$chris = new Chris;
|
$chris = new Chris;
|
||||||
echo $m->render($template, $chris);
|
echo $m->render($template, $chris);
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -9,12 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache class autoloader.
|
* Mustache class autoloader.
|
||||||
*/
|
*/
|
||||||
class Autoloader {
|
class Mustache_Autoloader {
|
||||||
|
|
||||||
private $baseDir;
|
private $baseDir;
|
||||||
|
|
||||||
@@ -32,7 +30,7 @@ class Autoloader {
|
|||||||
*
|
*
|
||||||
* @param string $baseDir Mustache library base directory (default: __DIR__.'/..')
|
* @param string $baseDir Mustache library base directory (default: __DIR__.'/..')
|
||||||
*
|
*
|
||||||
* @return \Mustache\Autoloader Registered Autoloader instance
|
* @return Mustache_Autoloader Registered Autoloader instance
|
||||||
*/
|
*/
|
||||||
static public function register($baseDir = null) {
|
static public function register($baseDir = null) {
|
||||||
$loader = new self($baseDir);
|
$loader = new self($baseDir);
|
||||||
@@ -55,7 +53,7 @@ class Autoloader {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = sprintf('%s/%s.php', $this->baseDir, str_replace('\\', '/', $class));
|
$file = sprintf('%s/%s.php', $this->baseDir, str_replace('_', '/', $class));
|
||||||
if (is_file($file)) {
|
if (is_file($file)) {
|
||||||
require $file;
|
require $file;
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-32
@@ -9,14 +9,12 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache Compiler class.
|
* Mustache Compiler class.
|
||||||
*
|
*
|
||||||
* This class is responsible for turning a Mustache token parse tree into normal PHP source code.
|
* This class is responsible for turning a Mustache token parse tree into normal PHP source code.
|
||||||
*/
|
*/
|
||||||
class Compiler {
|
class Mustache_Compiler {
|
||||||
|
|
||||||
private $sections;
|
private $sections;
|
||||||
private $source;
|
private $source;
|
||||||
@@ -46,7 +44,7 @@ class Compiler {
|
|||||||
/**
|
/**
|
||||||
* Helper function for walking the Mustache token parse tree.
|
* Helper function for walking the Mustache token parse tree.
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException upon encountering unknown token types.
|
* @throws InvalidArgumentException upon encountering unknown token types.
|
||||||
*
|
*
|
||||||
* @param array $tree Parse tree of Mustache tokens
|
* @param array $tree Parse tree of Mustache tokens
|
||||||
* @param int $level (default: 0)
|
* @param int $level (default: 0)
|
||||||
@@ -57,46 +55,46 @@ class Compiler {
|
|||||||
$code = '';
|
$code = '';
|
||||||
$level++;
|
$level++;
|
||||||
foreach ($tree as $node) {
|
foreach ($tree as $node) {
|
||||||
switch (is_string($node) ? 'text' : $node[Tokenizer::TYPE]) {
|
switch (is_string($node) ? 'text' : $node[Mustache_Tokenizer::TYPE]) {
|
||||||
case Tokenizer::T_SECTION:
|
case Mustache_Tokenizer::T_SECTION:
|
||||||
$code .= $this->section(
|
$code .= $this->section(
|
||||||
$node[Tokenizer::NODES],
|
$node[Mustache_Tokenizer::NODES],
|
||||||
$node[Tokenizer::NAME],
|
$node[Mustache_Tokenizer::NAME],
|
||||||
$node[Tokenizer::INDEX],
|
$node[Mustache_Tokenizer::INDEX],
|
||||||
$node[Tokenizer::END],
|
$node[Mustache_Tokenizer::END],
|
||||||
$node[Tokenizer::OTAG],
|
$node[Mustache_Tokenizer::OTAG],
|
||||||
$node[Tokenizer::CTAG],
|
$node[Mustache_Tokenizer::CTAG],
|
||||||
$level
|
$level
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tokenizer::T_INVERTED:
|
case Mustache_Tokenizer::T_INVERTED:
|
||||||
$code .= $this->invertedSection(
|
$code .= $this->invertedSection(
|
||||||
$node[Tokenizer::NODES],
|
$node[Mustache_Tokenizer::NODES],
|
||||||
$node[Tokenizer::NAME],
|
$node[Mustache_Tokenizer::NAME],
|
||||||
$level
|
$level
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tokenizer::T_PARTIAL:
|
case Mustache_Tokenizer::T_PARTIAL:
|
||||||
case Tokenizer::T_PARTIAL_2:
|
case Mustache_Tokenizer::T_PARTIAL_2:
|
||||||
$code .= $this->partial(
|
$code .= $this->partial(
|
||||||
$node[Tokenizer::NAME],
|
$node[Mustache_Tokenizer::NAME],
|
||||||
isset($node[Tokenizer::INDENT]) ? $node[Tokenizer::INDENT] : '',
|
isset($node[Mustache_Tokenizer::INDENT]) ? $node[Mustache_Tokenizer::INDENT] : '',
|
||||||
$level
|
$level
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tokenizer::T_UNESCAPED:
|
case Mustache_Tokenizer::T_UNESCAPED:
|
||||||
case Tokenizer::T_UNESCAPED_2:
|
case Mustache_Tokenizer::T_UNESCAPED_2:
|
||||||
$code .= $this->variable($node[Tokenizer::NAME], false, $level);
|
$code .= $this->variable($node[Mustache_Tokenizer::NAME], false, $level);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tokenizer::T_COMMENT:
|
case Mustache_Tokenizer::T_COMMENT:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tokenizer::T_ESCAPED:
|
case Mustache_Tokenizer::T_ESCAPED:
|
||||||
$code .= $this->variable($node[Tokenizer::NAME], true, $level);
|
$code .= $this->variable($node[Mustache_Tokenizer::NAME], true, $level);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@@ -105,7 +103,7 @@ class Compiler {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new \InvalidArgumentException('Unknown node type: '.json_encode($node));
|
throw new InvalidArgumentException('Unknown node type: '.json_encode($node));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +112,8 @@ class Compiler {
|
|||||||
|
|
||||||
const KLASS = '<?php
|
const KLASS = '<?php
|
||||||
|
|
||||||
class %s extends \Mustache\Template {
|
class %s extends Mustache_Template {
|
||||||
public function renderInternal(\Mustache\Context $context, $indent = \'\', $escape = false) {
|
public function renderInternal(Mustache_Context $context, $indent = \'\', $escape = false) {
|
||||||
$buffer = \'\';
|
$buffer = \'\';
|
||||||
%s
|
%s
|
||||||
|
|
||||||
@@ -149,7 +147,7 @@ class Compiler {
|
|||||||
';
|
';
|
||||||
|
|
||||||
const SECTION = '
|
const SECTION = '
|
||||||
private function section%s(\Mustache\Context $context, $indent, $value) {
|
private function section%s(Mustache_Context $context, $indent, $value) {
|
||||||
$buffer = \'\';
|
$buffer = \'\';
|
||||||
if (!is_string($value) && is_callable($value)) {
|
if (!is_string($value) && is_callable($value)) {
|
||||||
$source = %s;
|
$source = %s;
|
||||||
@@ -329,9 +327,9 @@ class Compiler {
|
|||||||
*
|
*
|
||||||
* The return value will be one of `find`, `findDot` or `last`.
|
* The return value will be one of `find`, `findDot` or `last`.
|
||||||
*
|
*
|
||||||
* @see \Mustache\Context::find
|
* @see Mustache_Context::find
|
||||||
* @see \Mustache\Context::findDot
|
* @see Mustache_Context::findDot
|
||||||
* @see \Mustache\Context::last
|
* @see Mustache_Context::last
|
||||||
*
|
*
|
||||||
* @param string $id Variable name
|
* @param string $id Variable name
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -9,12 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache Template rendering Context.
|
* Mustache Template rendering Context.
|
||||||
*/
|
*/
|
||||||
class Context {
|
class Mustache_Context {
|
||||||
private $stack = array();
|
private $stack = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,7 +116,7 @@ class Context {
|
|||||||
/**
|
/**
|
||||||
* Helper function to find a variable in the Context stack.
|
* Helper function to find a variable in the Context stack.
|
||||||
*
|
*
|
||||||
* @see \Mustache\Context::find
|
* @see Mustache_Context::find
|
||||||
*
|
*
|
||||||
* @param string $id Variable name
|
* @param string $id Variable name
|
||||||
* @param array $stack Context stack
|
* @param array $stack Context stack
|
||||||
|
|||||||
@@ -9,27 +9,25 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of helpers for a Mustache instance.
|
* A collection of helpers for a Mustache instance.
|
||||||
*/
|
*/
|
||||||
class HelperCollection {
|
class Mustache_HelperCollection {
|
||||||
private $helpers = array();
|
private $helpers = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper Collection constructor.
|
* Helper Collection constructor.
|
||||||
*
|
*
|
||||||
* Optionally accepts an array (or \Traversable) of `$name => $helper` pairs.
|
* Optionally accepts an array (or Traversable) of `$name => $helper` pairs.
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if the $helpers argument isn't an array or \Traversable
|
* @throws InvalidArgumentException if the $helpers argument isn't an array or Traversable
|
||||||
*
|
*
|
||||||
* @param array|Traversable $helpers (default: null)
|
* @param array|Traversable $helpers (default: null)
|
||||||
*/
|
*/
|
||||||
public function __construct($helpers = null) {
|
public function __construct($helpers = null) {
|
||||||
if ($helpers !== null) {
|
if ($helpers !== null) {
|
||||||
if (!is_array($helpers) && !$helpers instanceof \Traversable) {
|
if (!is_array($helpers) && !$helpers instanceof Traversable) {
|
||||||
throw new \InvalidArgumentException('HelperCollection constructor expects an array of helpers');
|
throw new InvalidArgumentException('HelperCollection constructor expects an array of helpers');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($helpers as $name => $helper) {
|
foreach ($helpers as $name => $helper) {
|
||||||
@@ -41,7 +39,7 @@ class HelperCollection {
|
|||||||
/**
|
/**
|
||||||
* Magic mutator.
|
* Magic mutator.
|
||||||
*
|
*
|
||||||
* @see \Mustache\HelperCollection::add
|
* @see Mustache_HelperCollection::add
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $helper
|
* @param mixed $helper
|
||||||
@@ -63,7 +61,7 @@ class HelperCollection {
|
|||||||
/**
|
/**
|
||||||
* Magic accessor.
|
* Magic accessor.
|
||||||
*
|
*
|
||||||
* @see \Mustache\HelperCollection::get
|
* @see Mustache_HelperCollection::get
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
@@ -82,7 +80,7 @@ class HelperCollection {
|
|||||||
*/
|
*/
|
||||||
public function get($name) {
|
public function get($name) {
|
||||||
if (!$this->has($name)) {
|
if (!$this->has($name)) {
|
||||||
throw new \InvalidArgumentException('Unknown helper: '.$name);
|
throw new InvalidArgumentException('Unknown helper: '.$name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->helpers[$name];
|
return $this->helpers[$name];
|
||||||
@@ -91,7 +89,7 @@ class HelperCollection {
|
|||||||
/**
|
/**
|
||||||
* Magic isset().
|
* Magic isset().
|
||||||
*
|
*
|
||||||
* @see \Mustache\HelperCollection::has
|
* @see Mustache_HelperCollection::has
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
@@ -115,7 +113,7 @@ class HelperCollection {
|
|||||||
/**
|
/**
|
||||||
* Magic unset().
|
* Magic unset().
|
||||||
*
|
*
|
||||||
* @see \Mustache\HelperCollection::remove
|
* @see Mustache_HelperCollection::remove
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
@@ -126,13 +124,13 @@ class HelperCollection {
|
|||||||
/**
|
/**
|
||||||
* Check whether a given helper is present in the collection.
|
* Check whether a given helper is present in the collection.
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if the requested helper is not present.
|
* @throws InvalidArgumentException if the requested helper is not present.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
public function remove($name) {
|
public function remove($name) {
|
||||||
if (!$this->has($name)) {
|
if (!$this->has($name)) {
|
||||||
throw new \InvalidArgumentException('Unknown helper: '.$name);
|
throw new InvalidArgumentException('Unknown helper: '.$name);
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($this->helpers[$name]);
|
unset($this->helpers[$name]);
|
||||||
|
|||||||
@@ -9,12 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache Template Loader interface.
|
* Mustache Template Loader interface.
|
||||||
*/
|
*/
|
||||||
interface Loader {
|
interface Mustache_Loader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a Template by name.
|
* Load a Template by name.
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Loader;
|
|
||||||
|
|
||||||
use Mustache\Loader;
|
|
||||||
use Mustache\Loader\MutableLoader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache Template array Loader implementation.
|
* Mustache Template array Loader implementation.
|
||||||
*
|
*
|
||||||
@@ -26,13 +21,13 @@ use Mustache\Loader\MutableLoader;
|
|||||||
*
|
*
|
||||||
* $tpl = $loader->load('foo'); // '{{ bar }}'
|
* $tpl = $loader->load('foo'); // '{{ bar }}'
|
||||||
*
|
*
|
||||||
* The ArrayLoader is used internally as a partials loader by \Mustache\Mustache instance when an array of partials
|
* The ArrayLoader is used internally as a partials loader by Mustache_Mustache instance when an array of partials
|
||||||
* is set. It can also be used as a quick-and-dirty Template loader.
|
* is set. It can also be used as a quick-and-dirty Template loader.
|
||||||
*
|
*
|
||||||
* @implements Loader
|
* @implements Loader
|
||||||
* @implements MutableLoader
|
* @implements MutableLoader
|
||||||
*/
|
*/
|
||||||
class ArrayLoader implements Loader, MutableLoader {
|
class Mustache_Loader_ArrayLoader implements Mustache_Loader, Mustache_Loader_MutableLoader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ArrayLoader constructor.
|
* ArrayLoader constructor.
|
||||||
@@ -52,7 +47,7 @@ class ArrayLoader implements Loader, MutableLoader {
|
|||||||
*/
|
*/
|
||||||
public function load($name) {
|
public function load($name) {
|
||||||
if (!isset($this->templates[$name])) {
|
if (!isset($this->templates[$name])) {
|
||||||
throw new \InvalidArgumentException('Template '.$name.' not found.');
|
throw new InvalidArgumentException('Template '.$name.' not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->templates[$name];
|
return $this->templates[$name];
|
||||||
|
|||||||
@@ -9,10 +9,6 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Loader;
|
|
||||||
|
|
||||||
use Mustache\Loader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache Template filesystem Loader implementation.
|
* Mustache Template filesystem Loader implementation.
|
||||||
*
|
*
|
||||||
@@ -30,7 +26,7 @@ use Mustache\Loader;
|
|||||||
*
|
*
|
||||||
* @implements Loader
|
* @implements Loader
|
||||||
*/
|
*/
|
||||||
class FilesystemLoader implements Loader {
|
class Mustache_Loader_FilesystemLoader implements Mustache_Loader {
|
||||||
private $baseDir;
|
private $baseDir;
|
||||||
private $extension = '.mustache';
|
private $extension = '.mustache';
|
||||||
private $templates = array();
|
private $templates = array();
|
||||||
@@ -45,7 +41,7 @@ class FilesystemLoader implements Loader {
|
|||||||
* 'extension' => '.ms',
|
* 'extension' => '.ms',
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException if $baseDir does not exist.
|
* @throws RuntimeException if $baseDir does not exist.
|
||||||
*
|
*
|
||||||
* @param string $baseDir Base directory containing Mustache template files.
|
* @param string $baseDir Base directory containing Mustache template files.
|
||||||
* @param array $options Array of Loader options (default: array())
|
* @param array $options Array of Loader options (default: array())
|
||||||
@@ -54,7 +50,7 @@ class FilesystemLoader implements Loader {
|
|||||||
$this->baseDir = rtrim(realpath($baseDir), '/');
|
$this->baseDir = rtrim(realpath($baseDir), '/');
|
||||||
|
|
||||||
if (!is_dir($this->baseDir)) {
|
if (!is_dir($this->baseDir)) {
|
||||||
throw new \RuntimeException('FilesystemLoader baseDir must be a directory: '.$baseDir);
|
throw new RuntimeException('FilesystemLoader baseDir must be a directory: '.$baseDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['extension'])) {
|
if (isset($options['extension'])) {
|
||||||
@@ -83,7 +79,7 @@ class FilesystemLoader implements Loader {
|
|||||||
/**
|
/**
|
||||||
* Helper function for loading a Mustache file by name.
|
* Helper function for loading a Mustache file by name.
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if a template file is not found.
|
* @throws InvalidArgumentException if a template file is not found.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
@@ -93,7 +89,7 @@ class FilesystemLoader implements Loader {
|
|||||||
$fileName = $this->getFileName($name);
|
$fileName = $this->getFileName($name);
|
||||||
|
|
||||||
if (!file_exists($fileName)) {
|
if (!file_exists($fileName)) {
|
||||||
throw new \InvalidArgumentException('Template '.$name.' not found.');
|
throw new InvalidArgumentException('Template '.$name.' not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return file_get_contents($fileName);
|
return file_get_contents($fileName);
|
||||||
|
|||||||
@@ -9,12 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Loader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache Template mutable Loader interface.
|
* Mustache Template mutable Loader interface.
|
||||||
*/
|
*/
|
||||||
interface MutableLoader {
|
interface Mustache_Loader_MutableLoader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an associative array of Template sources for this loader.
|
* Set an associative array of Template sources for this loader.
|
||||||
|
|||||||
@@ -9,10 +9,6 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Loader;
|
|
||||||
|
|
||||||
use Mustache\Loader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache Template string Loader implementation.
|
* Mustache Template string Loader implementation.
|
||||||
*
|
*
|
||||||
@@ -29,7 +25,7 @@ use Mustache\Loader;
|
|||||||
*
|
*
|
||||||
* @implements Loader
|
* @implements Loader
|
||||||
*/
|
*/
|
||||||
class StringLoader implements Loader {
|
class Mustache_Loader_StringLoader implements Mustache_Loader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a Template by source.
|
* Load a Template by source.
|
||||||
|
|||||||
+51
-57
@@ -9,12 +9,6 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache;
|
|
||||||
|
|
||||||
use Mustache\Loader\ArrayLoader;
|
|
||||||
use Mustache\Loader\MutableLoader;
|
|
||||||
use Mustache\Loader\StringLoader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Mustache implementation in PHP.
|
* A Mustache implementation in PHP.
|
||||||
*
|
*
|
||||||
@@ -27,7 +21,7 @@ use Mustache\Loader\StringLoader;
|
|||||||
*
|
*
|
||||||
* @author Justin Hileman {@link http://justinhileman.com}
|
* @author Justin Hileman {@link http://justinhileman.com}
|
||||||
*/
|
*/
|
||||||
class Mustache {
|
class Mustache_Mustache {
|
||||||
const VERSION = '2.0.0-dev';
|
const VERSION = '2.0.0-dev';
|
||||||
const SPEC_VERSION = '1.1.2';
|
const SPEC_VERSION = '1.1.2';
|
||||||
|
|
||||||
@@ -50,16 +44,16 @@ class Mustache {
|
|||||||
*
|
*
|
||||||
* $options = array(
|
* $options = array(
|
||||||
* // The class prefix for compiled templates. Defaults to '__Mustache_'
|
* // The class prefix for compiled templates. Defaults to '__Mustache_'
|
||||||
* 'template_class_prefix' => '\My\Namespace\Template\',
|
* 'template_class_prefix' => '__MyTemplates_',
|
||||||
*
|
*
|
||||||
* // A cache directory for compiled templates. Mustache will not cache templates unless this is set
|
* // A cache directory for compiled templates. Mustache will not cache templates unless this is set
|
||||||
* 'cache' => __DIR__.'/tmp/cache/mustache',
|
* 'cache' => __DIR__.'/tmp/cache/mustache',
|
||||||
*
|
*
|
||||||
* // A Mustache template loader instance. Uses a StringLoader if not specified
|
* // A Mustache template loader instance. Uses a StringLoader if not specified
|
||||||
* 'loader' => new \Mustache\Loader\FilesystemLoader(__DIR__.'/views'),
|
* 'loader' => new Mustache_Loader_FilesystemLoader(__DIR__.'/views'),
|
||||||
*
|
*
|
||||||
* // A Mustache loader instance for partials.
|
* // A Mustache loader instance for partials.
|
||||||
* 'partials_loader' => new \Mustache\Loader\FilesystemLoader(__DIR__.'/views/partials'),
|
* 'partials_loader' => new Mustache_Loader_FilesystemLoader(__DIR__.'/views/partials'),
|
||||||
*
|
*
|
||||||
* // An array of Mustache partials. Useful for quick-and-dirty string template loading, but not as
|
* // An array of Mustache partials. Useful for quick-and-dirty string template loading, but not as
|
||||||
* // efficient or lazy as a Filesystem (or database) loader.
|
* // efficient or lazy as a Filesystem (or database) loader.
|
||||||
@@ -126,8 +120,8 @@ class Mustache {
|
|||||||
*
|
*
|
||||||
* Equivalent to calling `$mustache->loadTemplate($template)->render($data);`
|
* Equivalent to calling `$mustache->loadTemplate($template)->render($data);`
|
||||||
*
|
*
|
||||||
* @see \Mustache\Mustache::loadTemplate
|
* @see Mustache_Mustache::loadTemplate
|
||||||
* @see \Mustache\Template::render
|
* @see Mustache_Template::render
|
||||||
*
|
*
|
||||||
* @param string $template
|
* @param string $template
|
||||||
* @param mixed $data
|
* @param mixed $data
|
||||||
@@ -159,9 +153,9 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Set the Mustache template Loader instance.
|
* Set the Mustache template Loader instance.
|
||||||
*
|
*
|
||||||
* @param \Mustache\Loader $loader
|
* @param Mustache_Loader $loader
|
||||||
*/
|
*/
|
||||||
public function setLoader(Loader $loader) {
|
public function setLoader(Mustache_Loader $loader) {
|
||||||
$this->loader = $loader;
|
$this->loader = $loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,11 +165,11 @@ class Mustache {
|
|||||||
* If no Loader instance has been explicitly specified, this method will instantiate and return
|
* If no Loader instance has been explicitly specified, this method will instantiate and return
|
||||||
* a StringLoader instance.
|
* a StringLoader instance.
|
||||||
*
|
*
|
||||||
* @return \Mustache\Loader
|
* @return Mustache_Loader
|
||||||
*/
|
*/
|
||||||
public function getLoader() {
|
public function getLoader() {
|
||||||
if (!isset($this->loader)) {
|
if (!isset($this->loader)) {
|
||||||
$this->loader = new StringLoader;
|
$this->loader = new Mustache_Loader_StringLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->loader;
|
return $this->loader;
|
||||||
@@ -184,9 +178,9 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Set the Mustache partials Loader instance.
|
* Set the Mustache partials Loader instance.
|
||||||
*
|
*
|
||||||
* @param \Mustache\Loader $partialsLoader
|
* @param Mustache_Loader $partialsLoader
|
||||||
*/
|
*/
|
||||||
public function setPartialsLoader(Loader $partialsLoader) {
|
public function setPartialsLoader(Mustache_Loader $partialsLoader) {
|
||||||
$this->partialsLoader = $partialsLoader;
|
$this->partialsLoader = $partialsLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,11 +190,11 @@ class Mustache {
|
|||||||
* If no Loader instance has been explicitly specified, this method will instantiate and return
|
* If no Loader instance has been explicitly specified, this method will instantiate and return
|
||||||
* an ArrayLoader instance.
|
* an ArrayLoader instance.
|
||||||
*
|
*
|
||||||
* @return \Mustache\Loader
|
* @return Mustache_Loader
|
||||||
*/
|
*/
|
||||||
public function getPartialsLoader() {
|
public function getPartialsLoader() {
|
||||||
if (!isset($this->partialsLoader)) {
|
if (!isset($this->partialsLoader)) {
|
||||||
$this->partialsLoader = new ArrayLoader;
|
$this->partialsLoader = new Mustache_Loader_ArrayLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->partialsLoader;
|
return $this->partialsLoader;
|
||||||
@@ -209,14 +203,14 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Set partials for the current partials Loader instance.
|
* Set partials for the current partials Loader instance.
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException If the current Loader instance is immutable
|
* @throws RuntimeException If the current Loader instance is immutable
|
||||||
*
|
*
|
||||||
* @param array $partials (default: array())
|
* @param array $partials (default: array())
|
||||||
*/
|
*/
|
||||||
public function setPartials(array $partials = array()) {
|
public function setPartials(array $partials = array()) {
|
||||||
$loader = $this->getPartialsLoader();
|
$loader = $this->getPartialsLoader();
|
||||||
if (!$loader instanceof MutableLoader) {
|
if (!$loader instanceof Mustache_Loader_MutableLoader) {
|
||||||
throw new \RuntimeException('Unable to set partials on an immutable Mustache Loader instance');
|
throw new RuntimeException('Unable to set partials on an immutable Mustache Loader instance');
|
||||||
}
|
}
|
||||||
|
|
||||||
$loader->setTemplates($partials);
|
$loader->setTemplates($partials);
|
||||||
@@ -229,13 +223,13 @@ class Mustache {
|
|||||||
* any other valid Mustache context value. They will be prepended to the context stack, so they will be available in
|
* any other valid Mustache context value. They will be prepended to the context stack, so they will be available in
|
||||||
* any template loaded by this Mustache instance.
|
* any template loaded by this Mustache instance.
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if $helpers is not an array or \Traversable
|
* @throws InvalidArgumentException if $helpers is not an array or Traversable
|
||||||
*
|
*
|
||||||
* @param array|Traversable $helpers
|
* @param array|Traversable $helpers
|
||||||
*/
|
*/
|
||||||
public function setHelpers($helpers) {
|
public function setHelpers($helpers) {
|
||||||
if (!is_array($helpers) && !$helpers instanceof \Traversable) {
|
if (!is_array($helpers) && !$helpers instanceof Traversable) {
|
||||||
throw new \InvalidArgumentException('setHelpers expects an array of helpers');
|
throw new InvalidArgumentException('setHelpers expects an array of helpers');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->getHelpers()->clear();
|
$this->getHelpers()->clear();
|
||||||
@@ -248,13 +242,13 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Get the current set of Mustache helpers.
|
* Get the current set of Mustache helpers.
|
||||||
*
|
*
|
||||||
* @see \Mustache\Mustache::setHelpers
|
* @see Mustache_Mustache::setHelpers
|
||||||
*
|
*
|
||||||
* @return \Mustache\HelperCollection
|
* @return Mustache_HelperCollection
|
||||||
*/
|
*/
|
||||||
public function getHelpers() {
|
public function getHelpers() {
|
||||||
if (!isset($this->helpers)) {
|
if (!isset($this->helpers)) {
|
||||||
$this->helpers = new HelperCollection;
|
$this->helpers = new Mustache_HelperCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->helpers;
|
return $this->helpers;
|
||||||
@@ -263,7 +257,7 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Add a new Mustache helper.
|
* Add a new Mustache helper.
|
||||||
*
|
*
|
||||||
* @see \Mustache\Mustache::setHelpers
|
* @see Mustache_Mustache::setHelpers
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $helper
|
* @param mixed $helper
|
||||||
@@ -275,7 +269,7 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Get a Mustache helper by name.
|
* Get a Mustache helper by name.
|
||||||
*
|
*
|
||||||
* @see \Mustache\Mustache::setHelpers
|
* @see Mustache_Mustache::setHelpers
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
@@ -288,7 +282,7 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Check whether this Mustache instance has a helper.
|
* Check whether this Mustache instance has a helper.
|
||||||
*
|
*
|
||||||
* @see \Mustache\Mustache::setHelpers
|
* @see Mustache_Mustache::setHelpers
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
@@ -301,7 +295,7 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Remove a helper by name.
|
* Remove a helper by name.
|
||||||
*
|
*
|
||||||
* @see \Mustache\Mustache::setHelpers
|
* @see Mustache_Mustache::setHelpers
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
@@ -312,9 +306,9 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Set the Mustache Tokenizer instance.
|
* Set the Mustache Tokenizer instance.
|
||||||
*
|
*
|
||||||
* @param \Mustache\Tokenizer $tokenizer
|
* @param Mustache_Tokenizer $tokenizer
|
||||||
*/
|
*/
|
||||||
public function setTokenizer(Tokenizer $tokenizer) {
|
public function setTokenizer(Mustache_Tokenizer $tokenizer) {
|
||||||
$this->tokenizer = $tokenizer;
|
$this->tokenizer = $tokenizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,11 +317,11 @@ class Mustache {
|
|||||||
*
|
*
|
||||||
* If no Tokenizer instance has been explicitly specified, this method will instantiate and return a new one.
|
* If no Tokenizer instance has been explicitly specified, this method will instantiate and return a new one.
|
||||||
*
|
*
|
||||||
* @return \Mustache\Tokenizer
|
* @return Mustache_Tokenizer
|
||||||
*/
|
*/
|
||||||
public function getTokenizer() {
|
public function getTokenizer() {
|
||||||
if (!isset($this->tokenizer)) {
|
if (!isset($this->tokenizer)) {
|
||||||
$this->tokenizer = new Tokenizer;
|
$this->tokenizer = new Mustache_Tokenizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->tokenizer;
|
return $this->tokenizer;
|
||||||
@@ -336,9 +330,9 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Set the Mustache Parser instance.
|
* Set the Mustache Parser instance.
|
||||||
*
|
*
|
||||||
* @param \Mustache\Parser $parser
|
* @param Mustache_Parser $parser
|
||||||
*/
|
*/
|
||||||
public function setParser(Parser $parser) {
|
public function setParser(Mustache_Parser $parser) {
|
||||||
$this->parser = $parser;
|
$this->parser = $parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,11 +341,11 @@ class Mustache {
|
|||||||
*
|
*
|
||||||
* If no Parser instance has been explicitly specified, this method will instantiate and return a new one.
|
* If no Parser instance has been explicitly specified, this method will instantiate and return a new one.
|
||||||
*
|
*
|
||||||
* @return \Mustache\Parser
|
* @return Mustache_Parser
|
||||||
*/
|
*/
|
||||||
public function getParser() {
|
public function getParser() {
|
||||||
if (!isset($this->parser)) {
|
if (!isset($this->parser)) {
|
||||||
$this->parser = new Parser;
|
$this->parser = new Mustache_Parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->parser;
|
return $this->parser;
|
||||||
@@ -360,9 +354,9 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Set the Mustache Compiler instance.
|
* Set the Mustache Compiler instance.
|
||||||
*
|
*
|
||||||
* @param \Mustache\Compiler $compiler
|
* @param Mustache_Compiler $compiler
|
||||||
*/
|
*/
|
||||||
public function setCompiler(Compiler $compiler) {
|
public function setCompiler(Mustache_Compiler $compiler) {
|
||||||
$this->compiler = $compiler;
|
$this->compiler = $compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,11 +365,11 @@ class Mustache {
|
|||||||
*
|
*
|
||||||
* If no Compiler instance has been explicitly specified, this method will instantiate and return a new one.
|
* If no Compiler instance has been explicitly specified, this method will instantiate and return a new one.
|
||||||
*
|
*
|
||||||
* @return \Mustache\Compiler
|
* @return Mustache_Compiler
|
||||||
*/
|
*/
|
||||||
public function getCompiler() {
|
public function getCompiler() {
|
||||||
if (!isset($this->compiler)) {
|
if (!isset($this->compiler)) {
|
||||||
$this->compiler = new Compiler;
|
$this->compiler = new Mustache_Compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->compiler;
|
return $this->compiler;
|
||||||
@@ -403,7 +397,7 @@ class Mustache {
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
* @return \Mustache\Template
|
* @return Mustache_Template
|
||||||
*/
|
*/
|
||||||
public function loadTemplate($name) {
|
public function loadTemplate($name) {
|
||||||
return $this->loadSource($this->getLoader()->load($name));
|
return $this->loadSource($this->getLoader()->load($name));
|
||||||
@@ -417,7 +411,7 @@ class Mustache {
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
* @return \Mustache\Template
|
* @return Mustache_Template
|
||||||
*/
|
*/
|
||||||
public function loadPartial($name) {
|
public function loadPartial($name) {
|
||||||
return $this->loadSource($this->getPartialsLoader()->load($name));
|
return $this->loadSource($this->getPartialsLoader()->load($name));
|
||||||
@@ -432,7 +426,7 @@ class Mustache {
|
|||||||
* @param string $source
|
* @param string $source
|
||||||
* @param string $delims (default: null)
|
* @param string $delims (default: null)
|
||||||
*
|
*
|
||||||
* @return \Mustache\Template
|
* @return Mustache_Template
|
||||||
*/
|
*/
|
||||||
public function loadLambda($source, $delims = null) {
|
public function loadLambda($source, $delims = null) {
|
||||||
if ($delims !== null) {
|
if ($delims !== null) {
|
||||||
@@ -445,13 +439,13 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Instantiate and return a Mustache Template instance by source.
|
* Instantiate and return a Mustache Template instance by source.
|
||||||
*
|
*
|
||||||
* @see \Mustache\Mustache::loadTemplate
|
* @see Mustache_Mustache::loadTemplate
|
||||||
* @see \Mustache\Mustache::loadPartial
|
* @see Mustache_Mustache::loadPartial
|
||||||
* @see \Mustache\Mustache::loadLambda
|
* @see Mustache_Mustache::loadLambda
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
*
|
*
|
||||||
* @return \Mustache\Template
|
* @return Mustache_Template
|
||||||
*/
|
*/
|
||||||
private function loadSource($source) {
|
private function loadSource($source) {
|
||||||
$className = $this->getTemplateClassName($source);
|
$className = $this->getTemplateClassName($source);
|
||||||
@@ -478,7 +472,7 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Helper method to tokenize a Mustache template.
|
* Helper method to tokenize a Mustache template.
|
||||||
*
|
*
|
||||||
* @see \Mustache\Tokenizer::scan
|
* @see Mustache_Tokenizer::scan
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
*
|
*
|
||||||
@@ -491,7 +485,7 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Helper method to parse a Mustache template.
|
* Helper method to parse a Mustache template.
|
||||||
*
|
*
|
||||||
* @see \Mustache\Parser::parse
|
* @see Mustache_Parser::parse
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
*
|
*
|
||||||
@@ -504,7 +498,7 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Helper method to compile a Mustache template.
|
* Helper method to compile a Mustache template.
|
||||||
*
|
*
|
||||||
* @see \Mustache\Compiler::compile
|
* @see Mustache_Compiler::compile
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
*
|
*
|
||||||
@@ -533,7 +527,7 @@ class Mustache {
|
|||||||
/**
|
/**
|
||||||
* Helper method to dump a generated Mustache Template subclass to the file cache.
|
* Helper method to dump a generated Mustache Template subclass to the file cache.
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException if unable to write to $fileName.
|
* @throws RuntimeException if unable to write to $fileName.
|
||||||
*
|
*
|
||||||
* @param string $fileName
|
* @param string $fileName
|
||||||
* @param string $source
|
* @param string $source
|
||||||
@@ -552,6 +546,6 @@ class Mustache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $fileName));
|
throw new RuntimeException(sprintf('Failed to write cache file "%s".', $fileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-17
@@ -9,14 +9,12 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache Parser class.
|
* Mustache Parser class.
|
||||||
*
|
*
|
||||||
* This class is responsible for turning a set of Mustache tokens into a parse tree.
|
* This class is responsible for turning a set of Mustache tokens into a parse tree.
|
||||||
*/
|
*/
|
||||||
class Parser {
|
class Mustache_Parser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process an array of Mustache tokens and convert them into a parse tree.
|
* Process an array of Mustache tokens and convert them into a parse tree.
|
||||||
@@ -26,20 +24,20 @@ class Parser {
|
|||||||
* @return array Mustache token parse tree
|
* @return array Mustache token parse tree
|
||||||
*/
|
*/
|
||||||
public function parse(array $tokens = array()) {
|
public function parse(array $tokens = array()) {
|
||||||
return $this->buildTree(new \ArrayIterator($tokens));
|
return $this->buildTree(new ArrayIterator($tokens));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method for recursively building a parse tree.
|
* Helper method for recursively building a parse tree.
|
||||||
*
|
*
|
||||||
* @throws \LogicException when nesting errors or mismatched section tags are encountered.
|
* @throws LogicException when nesting errors or mismatched section tags are encountered.
|
||||||
*
|
*
|
||||||
* @param \ArrayIterator $tokens Stream of Mustache tokens
|
* @param ArrayIterator $tokens Stream of Mustache tokens
|
||||||
* @param array $parent Parent token (default: null)
|
* @param array $parent Parent token (default: null)
|
||||||
*
|
*
|
||||||
* @return array Mustache Token parse tree
|
* @return array Mustache Token parse tree
|
||||||
*/
|
*/
|
||||||
private function buildTree(\ArrayIterator $tokens, array $parent = null) {
|
private function buildTree(ArrayIterator $tokens, array $parent = null) {
|
||||||
$nodes = array();
|
$nodes = array();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -49,23 +47,23 @@ class Parser {
|
|||||||
if ($token === null) {
|
if ($token === null) {
|
||||||
continue;
|
continue;
|
||||||
} elseif (is_array($token)) {
|
} elseif (is_array($token)) {
|
||||||
switch ($token[Tokenizer::TYPE]) {
|
switch ($token[Mustache_Tokenizer::TYPE]) {
|
||||||
case Tokenizer::T_SECTION:
|
case Mustache_Tokenizer::T_SECTION:
|
||||||
case Tokenizer::T_INVERTED:
|
case Mustache_Tokenizer::T_INVERTED:
|
||||||
$nodes[] = $this->buildTree($tokens, $token);
|
$nodes[] = $this->buildTree($tokens, $token);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tokenizer::T_END_SECTION:
|
case Mustache_Tokenizer::T_END_SECTION:
|
||||||
if (!isset($parent)) {
|
if (!isset($parent)) {
|
||||||
throw new \LogicException('Unexpected closing tag: /'. $token[Tokenizer::NAME]);
|
throw new LogicException('Unexpected closing tag: /'. $token[Mustache_Tokenizer::NAME]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($token[Tokenizer::NAME] !== $parent[Tokenizer::NAME]) {
|
if ($token[Mustache_Tokenizer::NAME] !== $parent[Mustache_Tokenizer::NAME]) {
|
||||||
throw new \LogicException('Nesting error: ' . $parent[Tokenizer::NAME] . ' vs. ' . $token[Tokenizer::NAME]);
|
throw new LogicException('Nesting error: ' . $parent[Mustache_Tokenizer::NAME] . ' vs. ' . $token[Mustache_Tokenizer::NAME]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent[Tokenizer::END] = $token[Tokenizer::INDEX];
|
$parent[Mustache_Tokenizer::END] = $token[Mustache_Tokenizer::INDEX];
|
||||||
$parent[Tokenizer::NODES] = $nodes;
|
$parent[Mustache_Tokenizer::NODES] = $nodes;
|
||||||
|
|
||||||
return $parent;
|
return $parent;
|
||||||
break;
|
break;
|
||||||
@@ -81,7 +79,7 @@ class Parser {
|
|||||||
} while ($tokens->valid());
|
} while ($tokens->valid());
|
||||||
|
|
||||||
if (isset($parent)) {
|
if (isset($parent)) {
|
||||||
throw new \LogicException('Missing closing tag: ' . $parent[Tokenizer::NAME]);
|
throw new LogicException('Missing closing tag: ' . $parent[Mustache_Tokenizer::NAME]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $nodes;
|
return $nodes;
|
||||||
|
|||||||
+11
-13
@@ -9,37 +9,35 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract Mustache Template class.
|
* Abstract Mustache Template class.
|
||||||
*
|
*
|
||||||
* @abstract
|
* @abstract
|
||||||
*/
|
*/
|
||||||
abstract class Template {
|
abstract class Mustache_Template {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Mustache\Mustache
|
* @var Mustache_Mustache
|
||||||
*/
|
*/
|
||||||
protected $mustache;
|
protected $mustache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache Template constructor.
|
* Mustache Template constructor.
|
||||||
*
|
*
|
||||||
* @param \Mustache\Mustache $mustache
|
* @param Mustache_Mustache $mustache
|
||||||
*/
|
*/
|
||||||
public function __construct(Mustache $mustache) {
|
public function __construct(Mustache_Mustache $mustache) {
|
||||||
$this->mustache = $mustache;
|
$this->mustache = $mustache;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache Template instances can be treated as a function and rendered by simply calling them:
|
* Mustache Template instances can be treated as a function and rendered by simply calling them:
|
||||||
*
|
*
|
||||||
* $m = new Mustache;
|
* $m = new Mustache_Mustache;
|
||||||
* $tpl = $m->loadTemplate('Hello, {{ name }}!');
|
* $tpl = $m->loadTemplate('Hello, {{ name }}!');
|
||||||
* echo $tpl(array('name' => 'World')); // "Hello, World!"
|
* echo $tpl(array('name' => 'World')); // "Hello, World!"
|
||||||
*
|
*
|
||||||
* @see \Mustache\Template::render
|
* @see Mustache_Template::render
|
||||||
*
|
*
|
||||||
* @param mixed $context Array or object rendering context (default: array())
|
* @param mixed $context Array or object rendering context (default: array())
|
||||||
*
|
*
|
||||||
@@ -67,11 +65,11 @@ abstract class Template {
|
|||||||
*
|
*
|
||||||
* @abstract
|
* @abstract
|
||||||
*
|
*
|
||||||
* @param \Mustache\Context $context
|
* @param Mustache_Context $context
|
||||||
*
|
*
|
||||||
* @return string Rendered template
|
* @return string Rendered template
|
||||||
*/
|
*/
|
||||||
abstract public function renderInternal(Context $context, $indent = '', $escape = false);
|
abstract public function renderInternal(Mustache_Context $context, $indent = '', $escape = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether a value should be iterated over (e.g. in a section context).
|
* Tests whether a value should be iterated over (e.g. in a section context).
|
||||||
@@ -104,7 +102,7 @@ abstract class Template {
|
|||||||
*/
|
*/
|
||||||
protected function isIterable($value) {
|
protected function isIterable($value) {
|
||||||
if (is_object($value)) {
|
if (is_object($value)) {
|
||||||
return $value instanceof \Traversable;
|
return $value instanceof Traversable;
|
||||||
} elseif (is_array($value)) {
|
} elseif (is_array($value)) {
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
@@ -126,10 +124,10 @@ abstract class Template {
|
|||||||
*
|
*
|
||||||
* @param mixed $context Optional first context frame (default: null)
|
* @param mixed $context Optional first context frame (default: null)
|
||||||
*
|
*
|
||||||
* @return \Mustache\Context
|
* @return Mustache_Context
|
||||||
*/
|
*/
|
||||||
protected function prepareContextStack($context = null) {
|
protected function prepareContextStack($context = null) {
|
||||||
$stack = new Context;
|
$stack = new Mustache_Context;
|
||||||
|
|
||||||
$helpers = $this->mustache->getHelpers();
|
$helpers = $this->mustache->getHelpers();
|
||||||
if (!$helpers->isEmpty()) {
|
if (!$helpers->isEmpty()) {
|
||||||
|
|||||||
@@ -9,14 +9,12 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mustache Tokenizer class.
|
* Mustache Tokenizer class.
|
||||||
*
|
*
|
||||||
* This class is responsible for turning raw template source into a set of Mustache tokens.
|
* This class is responsible for turning raw template source into a set of Mustache tokens.
|
||||||
*/
|
*/
|
||||||
class Tokenizer {
|
class Mustache_Tokenizer {
|
||||||
|
|
||||||
// Finite state machine states
|
// Finite state machine states
|
||||||
const IN_TEXT = 0;
|
const IN_TEXT = 0;
|
||||||
|
|||||||
@@ -9,29 +9,25 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test;
|
|
||||||
|
|
||||||
use Mustache\Autoloader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class AutoloaderTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_AutoloaderTest extends PHPUnit_Framework_TestCase {
|
||||||
public function testRegister() {
|
public function testRegister() {
|
||||||
$loader = Autoloader::register();
|
$loader = Mustache_Autoloader::register();
|
||||||
$this->assertTrue(spl_autoload_unregister(array($loader, 'autoload')));
|
$this->assertTrue(spl_autoload_unregister(array($loader, 'autoload')));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAutoloader() {
|
public function testAutoloader() {
|
||||||
$loader = new Autoloader(__DIR__.'/../../fixtures/autoloader');
|
$loader = new Mustache_Autoloader(__DIR__.'/../../fixtures/autoloader');
|
||||||
|
|
||||||
$this->assertNull($loader->autoload('NonMustacheClass'));
|
$this->assertNull($loader->autoload('NonMustacheClass'));
|
||||||
$this->assertFalse(class_exists('NonMustacheClass'));
|
$this->assertFalse(class_exists('NonMustacheClass'));
|
||||||
|
|
||||||
$loader->autoload('Mustache\Foo');
|
$loader->autoload('Mustache_Foo');
|
||||||
$this->assertTrue(class_exists('Mustache\Foo'));
|
$this->assertTrue(class_exists('Mustache_Foo'));
|
||||||
|
|
||||||
$loader->autoload('\Mustache\Bar');
|
$loader->autoload('\Mustache_Bar');
|
||||||
$this->assertTrue(class_exists('Mustache\Bar'));
|
$this->assertTrue(class_exists('Mustache_Bar'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,21 +9,16 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test;
|
|
||||||
|
|
||||||
use Mustache\Compiler;
|
|
||||||
use Mustache\Tokenizer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class CompilerTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_CompilerTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getCompileValues
|
* @dataProvider getCompileValues
|
||||||
*/
|
*/
|
||||||
public function testCompile($source, array $tree, $name, $customEscaper, $charset, $expected) {
|
public function testCompile($source, array $tree, $name, $customEscaper, $charset, $expected) {
|
||||||
$compiler = new Compiler;
|
$compiler = new Mustache_Compiler;
|
||||||
|
|
||||||
$compiled = $compiler->compile($source, $tree, $name, $customEscaper, $charset);
|
$compiled = $compiler->compile($source, $tree, $name, $customEscaper, $charset);
|
||||||
foreach ($expected as $contains) {
|
foreach ($expected as $contains) {
|
||||||
@@ -34,20 +29,20 @@ class CompilerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
public function getCompileValues() {
|
public function getCompileValues() {
|
||||||
return array(
|
return array(
|
||||||
array('', array(), 'Banana', false, 'ISO-8859-1', array(
|
array('', array(), 'Banana', false, 'ISO-8859-1', array(
|
||||||
"\nclass Banana extends \Mustache\Template",
|
"\nclass Banana extends Mustache_Template",
|
||||||
'return htmlspecialchars($buffer, ENT_COMPAT, \'ISO-8859-1\');',
|
'return htmlspecialchars($buffer, ENT_COMPAT, \'ISO-8859-1\');',
|
||||||
'return $buffer;',
|
'return $buffer;',
|
||||||
)),
|
)),
|
||||||
|
|
||||||
array('', array('TEXT'), 'Monkey', false, 'UTF-8', array(
|
array('', array('TEXT'), 'Monkey', false, 'UTF-8', array(
|
||||||
"\nclass Monkey extends \Mustache\Template",
|
"\nclass Monkey extends Mustache_Template",
|
||||||
'return htmlspecialchars($buffer, ENT_COMPAT, \'UTF-8\');',
|
'return htmlspecialchars($buffer, ENT_COMPAT, \'UTF-8\');',
|
||||||
'$buffer .= $indent . \'TEXT\';',
|
'$buffer .= $indent . \'TEXT\';',
|
||||||
'return $buffer;',
|
'return $buffer;',
|
||||||
)),
|
)),
|
||||||
|
|
||||||
array('', array('TEXT'), 'Monkey', true, 'ISO-8859-1', array(
|
array('', array('TEXT'), 'Monkey', true, 'ISO-8859-1', array(
|
||||||
"\nclass Monkey extends \Mustache\Template",
|
"\nclass Monkey extends Mustache_Template",
|
||||||
'$buffer .= $indent . \'TEXT\';',
|
'$buffer .= $indent . \'TEXT\';',
|
||||||
'return call_user_func($this->mustache->getEscape(), $buffer);',
|
'return call_user_func($this->mustache->getEscape(), $buffer);',
|
||||||
'return $buffer;',
|
'return $buffer;',
|
||||||
@@ -59,12 +54,12 @@ class CompilerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'foo',
|
'foo',
|
||||||
"\n",
|
"\n",
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_ESCAPED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
|
||||||
Tokenizer::NAME => 'name',
|
Mustache_Tokenizer::NAME => 'name',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_ESCAPED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
|
||||||
Tokenizer::NAME => '.',
|
Mustache_Tokenizer::NAME => '.',
|
||||||
),
|
),
|
||||||
"'bar'",
|
"'bar'",
|
||||||
),
|
),
|
||||||
@@ -72,7 +67,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
false,
|
false,
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
array(
|
array(
|
||||||
"\nclass Monkey extends \Mustache\Template",
|
"\nclass Monkey extends Mustache_Template",
|
||||||
'$buffer .= $indent . \'foo\'',
|
'$buffer .= $indent . \'foo\'',
|
||||||
'$buffer .= "\n"',
|
'$buffer .= "\n"',
|
||||||
'$value = $context->find(\'name\');',
|
'$value = $context->find(\'name\');',
|
||||||
@@ -90,7 +85,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testCompilerThrowsUnknownNodeTypeException() {
|
public function testCompilerThrowsUnknownNodeTypeException() {
|
||||||
$compiler = new Compiler;
|
$compiler = new Mustache_Compiler;
|
||||||
$compiler->compile('', array(array(Tokenizer::TYPE => 'invalid')), 'SomeClass');
|
$compiler->compile('', array(array(Mustache_Tokenizer::TYPE => 'invalid')), 'SomeClass');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,44 +9,40 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test;
|
|
||||||
|
|
||||||
use Mustache\Context;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class ContextTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_ContextTest extends PHPUnit_Framework_TestCase {
|
||||||
public function testConstructor() {
|
public function testConstructor() {
|
||||||
$one = new Context;
|
$one = new Mustache_Context;
|
||||||
$this->assertSame('', $one->find('foo'));
|
$this->assertSame('', $one->find('foo'));
|
||||||
$this->assertSame('', $one->find('bar'));
|
$this->assertSame('', $one->find('bar'));
|
||||||
|
|
||||||
$two = new Context(array(
|
$two = new Mustache_Context(array(
|
||||||
'foo' => 'FOO',
|
'foo' => 'FOO',
|
||||||
'bar' => '<BAR>'
|
'bar' => '<BAR>'
|
||||||
));
|
));
|
||||||
$this->assertEquals('FOO', $two->find('foo'));
|
$this->assertEquals('FOO', $two->find('foo'));
|
||||||
$this->assertEquals('<BAR>', $two->find('bar'));
|
$this->assertEquals('<BAR>', $two->find('bar'));
|
||||||
|
|
||||||
$obj = new \StdClass;
|
$obj = new StdClass;
|
||||||
$obj->name = 'NAME';
|
$obj->name = 'NAME';
|
||||||
$three = new Context($obj);
|
$three = new Mustache_Context($obj);
|
||||||
$this->assertSame($obj, $three->last());
|
$this->assertSame($obj, $three->last());
|
||||||
$this->assertEquals('NAME', $three->find('name'));
|
$this->assertEquals('NAME', $three->find('name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPushPopAndLast() {
|
public function testPushPopAndLast() {
|
||||||
$context = new Context;
|
$context = new Mustache_Context;
|
||||||
$this->assertFalse($context->last());
|
$this->assertFalse($context->last());
|
||||||
|
|
||||||
$dummy = new TestDummy;
|
$dummy = new Mustache_Test_TestDummy;
|
||||||
$context->push($dummy);
|
$context->push($dummy);
|
||||||
$this->assertSame($dummy, $context->last());
|
$this->assertSame($dummy, $context->last());
|
||||||
$this->assertSame($dummy, $context->pop());
|
$this->assertSame($dummy, $context->pop());
|
||||||
$this->assertFalse($context->last());
|
$this->assertFalse($context->last());
|
||||||
|
|
||||||
$obj = new \StdClass;
|
$obj = new StdClass;
|
||||||
$context->push($dummy);
|
$context->push($dummy);
|
||||||
$this->assertSame($dummy, $context->last());
|
$this->assertSame($dummy, $context->last());
|
||||||
$context->push($obj);
|
$context->push($obj);
|
||||||
@@ -57,11 +53,11 @@ class ContextTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testFind() {
|
public function testFind() {
|
||||||
$context = new Context;
|
$context = new Mustache_Context;
|
||||||
|
|
||||||
$dummy = new TestDummy;
|
$dummy = new Mustache_Test_TestDummy;
|
||||||
|
|
||||||
$obj = new \StdClass;
|
$obj = new StdClass;
|
||||||
$obj->name = 'obj';
|
$obj->name = 'obj';
|
||||||
|
|
||||||
$arr = array(
|
$arr = array(
|
||||||
@@ -98,7 +94,7 @@ class ContextTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestDummy {
|
class Mustache_Test_TestDummy {
|
||||||
public $name = 'dummy';
|
public $name = 'dummy';
|
||||||
|
|
||||||
public function __invoke() {
|
public function __invoke() {
|
||||||
|
|||||||
@@ -9,21 +9,17 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test\Functional;
|
|
||||||
|
|
||||||
use Mustache\Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group magic_methods
|
* @group magic_methods
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class CallTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_Functional_CallTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
public function testCallEatsContext() {
|
public function testCallEatsContext() {
|
||||||
$m = new Mustache;
|
$m = new Mustache_Mustache;
|
||||||
$tpl = $m->loadTemplate('{{# foo }}{{ label }}: {{ name }}{{/ foo }}');
|
$tpl = $m->loadTemplate('{{# foo }}{{ label }}: {{ name }}{{/ foo }}');
|
||||||
|
|
||||||
$foo = new ClassWithCall();
|
$foo = new Mustache_Test_Functional_ClassWithCall();
|
||||||
$foo->name = 'Bob';
|
$foo->name = 'Bob';
|
||||||
|
|
||||||
$data = array('label' => 'name', 'foo' => $foo);
|
$data = array('label' => 'name', 'foo' => $foo);
|
||||||
@@ -32,7 +28,7 @@ class CallTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWithCall {
|
class Mustache_Test_Functional_ClassWithCall {
|
||||||
public $name;
|
public $name;
|
||||||
public function __call($method, $args) {
|
public function __call($method, $args) {
|
||||||
return 'unknown value';
|
return 'unknown value';
|
||||||
|
|||||||
@@ -9,15 +9,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test\Functional;
|
|
||||||
|
|
||||||
use Mustache\Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group examples
|
* @group examples
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class ExamplesTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_Functional_ExamplesTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test everything in the `examples` directory.
|
* Test everything in the `examples` directory.
|
||||||
@@ -30,7 +26,7 @@ class ExamplesTest extends \PHPUnit_Framework_TestCase {
|
|||||||
* @param string $expected
|
* @param string $expected
|
||||||
*/
|
*/
|
||||||
public function testExamples($context, $source, $partials, $expected) {
|
public function testExamples($context, $source, $partials, $expected) {
|
||||||
$mustache = new Mustache(array(
|
$mustache = new Mustache_Mustache(array(
|
||||||
'partials' => $partials
|
'partials' => $partials
|
||||||
));
|
));
|
||||||
$this->assertEquals($expected, $mustache->loadTemplate($source)->render($context));
|
$this->assertEquals($expected, $mustache->loadTemplate($source)->render($context));
|
||||||
|
|||||||
@@ -9,26 +9,22 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test\Functional;
|
|
||||||
|
|
||||||
use Mustache\Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group lambdas
|
* @group lambdas
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
private $mustache;
|
private $mustache;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->mustache = new Mustache;
|
$this->mustache = new Mustache_Mustache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAnonymousFunctionSectionCallback() {
|
public function testAnonymousFunctionSectionCallback() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{#wrapper}}{{name}}{{/wrapper}}');
|
$tpl = $this->mustache->loadTemplate('{{#wrapper}}{{name}}{{/wrapper}}');
|
||||||
|
|
||||||
$foo = new Foo;
|
$foo = new Mustache_Test_Functional_Foo;
|
||||||
$foo->name = 'Mario';
|
$foo->name = 'Mario';
|
||||||
$foo->wrapper = function($text) {
|
$foo->wrapper = function($text) {
|
||||||
return sprintf('<div class="anonymous">%s</div>', $text);
|
return sprintf('<div class="anonymous">%s</div>', $text);
|
||||||
@@ -41,7 +37,7 @@ class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$one = $this->mustache->loadTemplate('{{name}}');
|
$one = $this->mustache->loadTemplate('{{name}}');
|
||||||
$two = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
|
$two = $this->mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
|
||||||
|
|
||||||
$foo = new Foo;
|
$foo = new Mustache_Test_Functional_Foo;
|
||||||
$foo->name = 'Luigi';
|
$foo->name = 'Luigi';
|
||||||
|
|
||||||
$this->assertEquals($foo->name, $one->render($foo));
|
$this->assertEquals($foo->name, $one->render($foo));
|
||||||
@@ -51,7 +47,7 @@ class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
|
|||||||
public function testRuntimeSectionCallback() {
|
public function testRuntimeSectionCallback() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{#doublewrap}}{{name}}{{/doublewrap}}');
|
$tpl = $this->mustache->loadTemplate('{{#doublewrap}}{{name}}{{/doublewrap}}');
|
||||||
|
|
||||||
$foo = new Foo;
|
$foo = new Mustache_Test_Functional_Foo;
|
||||||
$foo->doublewrap = array($foo, 'wrapWithBoth');
|
$foo->doublewrap = array($foo, 'wrapWithBoth');
|
||||||
|
|
||||||
$this->assertEquals(sprintf('<strong><em>%s</em></strong>', $foo->name), $tpl->render($foo));
|
$this->assertEquals(sprintf('<strong><em>%s</em></strong>', $foo->name), $tpl->render($foo));
|
||||||
@@ -60,7 +56,7 @@ class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
|
|||||||
public function testStaticSectionCallback() {
|
public function testStaticSectionCallback() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{#trimmer}} {{name}} {{/trimmer}}');
|
$tpl = $this->mustache->loadTemplate('{{#trimmer}} {{name}} {{/trimmer}}');
|
||||||
|
|
||||||
$foo = new Foo;
|
$foo = new Mustache_Test_Functional_Foo;
|
||||||
$foo->trimmer = array(get_class($foo), 'staticTrim');
|
$foo->trimmer = array(get_class($foo), 'staticTrim');
|
||||||
|
|
||||||
$this->assertEquals($foo->name, $tpl->render($foo));
|
$this->assertEquals($foo->name, $tpl->render($foo));
|
||||||
@@ -69,7 +65,7 @@ class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
|
|||||||
public function testViewArraySectionCallback() {
|
public function testViewArraySectionCallback() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{#trim}} {{name}} {{/trim}}');
|
$tpl = $this->mustache->loadTemplate('{{#trim}} {{name}} {{/trim}}');
|
||||||
|
|
||||||
$foo = new Foo;
|
$foo = new Mustache_Test_Functional_Foo;
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'name' => 'Bob',
|
'name' => 'Bob',
|
||||||
@@ -95,19 +91,19 @@ class HigherOrderSectionsTest extends \PHPUnit_Framework_TestCase {
|
|||||||
public function testMonsters() {
|
public function testMonsters() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{#title}}{{title}} {{/title}}{{name}}');
|
$tpl = $this->mustache->loadTemplate('{{#title}}{{title}} {{/title}}{{name}}');
|
||||||
|
|
||||||
$frank = new Monster();
|
$frank = new Mustache_Test_Functional_Monster();
|
||||||
$frank->title = 'Dr.';
|
$frank->title = 'Dr.';
|
||||||
$frank->name = 'Frankenstein';
|
$frank->name = 'Frankenstein';
|
||||||
$this->assertEquals('Dr. Frankenstein', $tpl->render($frank));
|
$this->assertEquals('Dr. Frankenstein', $tpl->render($frank));
|
||||||
|
|
||||||
$dracula = new Monster();
|
$dracula = new Mustache_Test_Functional_Monster();
|
||||||
$dracula->title = 'Count';
|
$dracula->title = 'Count';
|
||||||
$dracula->name = 'Dracula';
|
$dracula->name = 'Dracula';
|
||||||
$this->assertEquals('Count Dracula', $tpl->render($dracula));
|
$this->assertEquals('Count Dracula', $tpl->render($dracula));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Foo {
|
class Mustache_Test_Functional_Foo {
|
||||||
public $name = 'Justin';
|
public $name = 'Justin';
|
||||||
public $lorem = 'Lorem ipsum dolor sit amet,';
|
public $lorem = 'Lorem ipsum dolor sit amet,';
|
||||||
public $wrap;
|
public $wrap;
|
||||||
@@ -135,7 +131,7 @@ class Foo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Monster {
|
class Mustache_Test_Functional_Monster {
|
||||||
public $title;
|
public $title;
|
||||||
public $name;
|
public $name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,16 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test\Functional;
|
|
||||||
|
|
||||||
use Mustache\Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group mustache_injection
|
* @group mustache_injection
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class MustacheInjectionTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
private $mustache;
|
private $mustache;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->mustache = new Mustache;
|
$this->mustache = new Mustache_Mustache;
|
||||||
}
|
}
|
||||||
|
|
||||||
// interpolation
|
// interpolation
|
||||||
|
|||||||
@@ -9,23 +9,18 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test\Functional;
|
|
||||||
|
|
||||||
use Mustache\Mustache;
|
|
||||||
use Mustache\Loader\StringLoader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A PHPUnit test case wrapping the Mustache Spec
|
* A PHPUnit test case wrapping the Mustache Spec
|
||||||
*
|
*
|
||||||
* @group mustache-spec
|
* @group mustache-spec
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class MustacheSpecTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
private static $mustache;
|
private static $mustache;
|
||||||
|
|
||||||
public static function setUpBeforeClass() {
|
public static function setUpBeforeClass() {
|
||||||
self::$mustache = new Mustache;
|
self::$mustache = new Mustache_Mustache;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,7 +162,7 @@ class MustacheSpecTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
$yaml = new \sfYamlParser;
|
$yaml = new sfYamlParser;
|
||||||
$file = file_get_contents($filename);
|
$file = file_get_contents($filename);
|
||||||
|
|
||||||
// @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain.
|
// @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain.
|
||||||
|
|||||||
@@ -9,24 +9,20 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test\Functional;
|
|
||||||
|
|
||||||
use Mustache\Mustache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group sections
|
* @group sections
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class ObjectSectionTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_Functional_ObjectSectionTest extends PHPUnit_Framework_TestCase {
|
||||||
private $mustache;
|
private $mustache;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->mustache = new Mustache;
|
$this->mustache = new Mustache_Mustache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBasicObject() {
|
public function testBasicObject() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
|
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
|
||||||
$this->assertEquals('Foo', $tpl->render(new Alpha));
|
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Alpha));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,7 +30,7 @@ class ObjectSectionTest extends \PHPUnit_Framework_TestCase {
|
|||||||
*/
|
*/
|
||||||
public function testObjectWithGet() {
|
public function testObjectWithGet() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
|
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
|
||||||
$this->assertEquals('Foo', $tpl->render(new Beta));
|
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Beta));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,32 +38,32 @@ class ObjectSectionTest extends \PHPUnit_Framework_TestCase {
|
|||||||
*/
|
*/
|
||||||
public function testSectionObjectWithGet() {
|
public function testSectionObjectWithGet() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{#bar}}{{#foo}}{{name}}{{/foo}}{{/bar}}');
|
$tpl = $this->mustache->loadTemplate('{{#bar}}{{#foo}}{{name}}{{/foo}}{{/bar}}');
|
||||||
$this->assertEquals('Foo', $tpl->render(new Gamma));
|
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Gamma));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSectionObjectWithFunction() {
|
public function testSectionObjectWithFunction() {
|
||||||
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
|
$tpl = $this->mustache->loadTemplate('{{#foo}}{{name}}{{/foo}}');
|
||||||
$alpha = new Alpha;
|
$alpha = new Mustache_Test_Functional_Alpha;
|
||||||
$alpha->foo = new Delta;
|
$alpha->foo = new Mustache_Test_Functional_Delta;
|
||||||
$this->assertEquals('Foo', $tpl->render($alpha));
|
$this->assertEquals('Foo', $tpl->render($alpha));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Alpha {
|
class Mustache_Test_Functional_Alpha {
|
||||||
public $foo;
|
public $foo;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->foo = new \StdClass();
|
$this->foo = new StdClass();
|
||||||
$this->foo->name = 'Foo';
|
$this->foo->name = 'Foo';
|
||||||
$this->foo->number = 1;
|
$this->foo->number = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Beta {
|
class Mustache_Test_Functional_Beta {
|
||||||
protected $_data = array();
|
protected $_data = array();
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->_data['foo'] = new \StdClass();
|
$this->_data['foo'] = new StdClass();
|
||||||
$this->_data['foo']->name = 'Foo';
|
$this->_data['foo']->name = 'Foo';
|
||||||
$this->_data['foo']->number = 1;
|
$this->_data['foo']->number = 1;
|
||||||
}
|
}
|
||||||
@@ -81,15 +77,15 @@ class Beta {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Gamma {
|
class Mustache_Test_Functional_Gamma {
|
||||||
public $bar;
|
public $bar;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->bar = new Beta();
|
$this->bar = new Mustache_Test_Functional_Beta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Delta {
|
class Mustache_Test_Functional_Delta {
|
||||||
protected $_name = 'Foo';
|
protected $_name = 'Foo';
|
||||||
|
|
||||||
public function name() {
|
public function name() {
|
||||||
|
|||||||
@@ -9,16 +9,12 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test;
|
class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
use Mustache\HelperCollection;
|
|
||||||
|
|
||||||
class HelperCollectionTest extends \PHPUnit_Framework_TestCase {
|
|
||||||
public function testConstructor() {
|
public function testConstructor() {
|
||||||
$foo = function() { echo 'foo'; };
|
$foo = function() { echo 'foo'; };
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
|
|
||||||
$helpers = new HelperCollection(array(
|
$helpers = new Mustache_HelperCollection(array(
|
||||||
'foo' => $foo,
|
'foo' => $foo,
|
||||||
'bar' => $bar,
|
'bar' => $bar,
|
||||||
));
|
));
|
||||||
@@ -31,7 +27,7 @@ class HelperCollectionTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$foo = function() { echo 'foo'; };
|
$foo = function() { echo 'foo'; };
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
|
|
||||||
$helpers = new HelperCollection;
|
$helpers = new Mustache_HelperCollection;
|
||||||
$this->assertTrue($helpers->isEmpty());
|
$this->assertTrue($helpers->isEmpty());
|
||||||
$this->assertFalse($helpers->has('foo'));
|
$this->assertFalse($helpers->has('foo'));
|
||||||
$this->assertFalse($helpers->has('bar'));
|
$this->assertFalse($helpers->has('bar'));
|
||||||
@@ -56,7 +52,7 @@ class HelperCollectionTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$foo = function() { echo 'foo'; };
|
$foo = function() { echo 'foo'; };
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
|
|
||||||
$helpers = new HelperCollection;
|
$helpers = new Mustache_HelperCollection;
|
||||||
$this->assertTrue($helpers->isEmpty());
|
$this->assertTrue($helpers->isEmpty());
|
||||||
$this->assertFalse($helpers->has('foo'));
|
$this->assertFalse($helpers->has('foo'));
|
||||||
$this->assertFalse($helpers->has('bar'));
|
$this->assertFalse($helpers->has('bar'));
|
||||||
@@ -93,7 +89,7 @@ class HelperCollectionTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->setExpectedException($exception);
|
$this->setExpectedException($exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
$helpers = new HelperCollection($helpers);
|
$helpers = new Mustache_HelperCollection($helpers);
|
||||||
|
|
||||||
foreach ($actions as $method => $args) {
|
foreach ($actions as $method => $args) {
|
||||||
call_user_func_array(array($helpers, $method), $args);
|
call_user_func_array(array($helpers, $method), $args);
|
||||||
|
|||||||
@@ -9,16 +9,12 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test\Loader;
|
|
||||||
|
|
||||||
use Mustache\Loader\ArrayLoader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class ArrayLoaderTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_Loader_ArrayLoaderTest extends PHPUnit_Framework_TestCase {
|
||||||
public function testConstructor() {
|
public function testConstructor() {
|
||||||
$loader = new ArrayLoader(array(
|
$loader = new Mustache_Loader_ArrayLoader(array(
|
||||||
'foo' => 'bar'
|
'foo' => 'bar'
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -26,7 +22,7 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSetAndLoadTemplates() {
|
public function testSetAndLoadTemplates() {
|
||||||
$loader = new ArrayLoader(array(
|
$loader = new Mustache_Loader_ArrayLoader(array(
|
||||||
'foo' => 'bar'
|
'foo' => 'bar'
|
||||||
));
|
));
|
||||||
$this->assertEquals('bar', $loader->load('foo'));
|
$this->assertEquals('bar', $loader->load('foo'));
|
||||||
@@ -46,7 +42,7 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase {
|
|||||||
* @expectedException \InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testMissingTemplatesThrowExceptions() {
|
public function testMissingTemplatesThrowExceptions() {
|
||||||
$loader = new ArrayLoader;
|
$loader = new Mustache_Loader_ArrayLoader;
|
||||||
$loader->load('not_a_real_template');
|
$loader->load('not_a_real_template');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,24 +9,20 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test\Loader;
|
|
||||||
|
|
||||||
use Mustache\Loader\FilesystemLoader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class FilesystemLoaderTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_Loader_FilesystemLoaderTest extends PHPUnit_Framework_TestCase {
|
||||||
public function testConstructor() {
|
public function testConstructor() {
|
||||||
$baseDir = realpath(__DIR__.'/../../../fixtures/templates');
|
$baseDir = realpath(__DIR__.'/../../../fixtures/templates');
|
||||||
$loader = new FilesystemLoader($baseDir, array('extension' => '.ms'));
|
$loader = new Mustache_Loader_FilesystemLoader($baseDir, array('extension' => '.ms'));
|
||||||
$this->assertEquals('alpha contents', $loader->load('alpha'));
|
$this->assertEquals('alpha contents', $loader->load('alpha'));
|
||||||
$this->assertEquals('beta contents', $loader->load('beta.ms'));
|
$this->assertEquals('beta contents', $loader->load('beta.ms'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadTemplates() {
|
public function testLoadTemplates() {
|
||||||
$baseDir = realpath(__DIR__.'/../../../fixtures/templates');
|
$baseDir = realpath(__DIR__.'/../../../fixtures/templates');
|
||||||
$loader = new FilesystemLoader($baseDir);
|
$loader = new Mustache_Loader_FilesystemLoader($baseDir);
|
||||||
$this->assertEquals('one contents', $loader->load('one'));
|
$this->assertEquals('one contents', $loader->load('one'));
|
||||||
$this->assertEquals('two contents', $loader->load('two.mustache'));
|
$this->assertEquals('two contents', $loader->load('two.mustache'));
|
||||||
}
|
}
|
||||||
@@ -35,7 +31,7 @@ class FilesystemLoaderTest extends \PHPUnit_Framework_TestCase {
|
|||||||
* @expectedException \RuntimeException
|
* @expectedException \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function testMissingBaseDirThrowsException() {
|
public function testMissingBaseDirThrowsException() {
|
||||||
$loader = new FilesystemLoader(__DIR__.'/not_a_directory');
|
$loader = new Mustache_Loader_FilesystemLoader(__DIR__.'/not_a_directory');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,7 +39,7 @@ class FilesystemLoaderTest extends \PHPUnit_Framework_TestCase {
|
|||||||
*/
|
*/
|
||||||
public function testMissingTemplateThrowsException() {
|
public function testMissingTemplateThrowsException() {
|
||||||
$baseDir = realpath(__DIR__.'/../../../fixtures/templates');
|
$baseDir = realpath(__DIR__.'/../../../fixtures/templates');
|
||||||
$loader = new FilesystemLoader($baseDir);
|
$loader = new Mustache_Loader_FilesystemLoader($baseDir);
|
||||||
|
|
||||||
$loader->load('fake');
|
$loader->load('fake');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,16 +9,12 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test\Loader;
|
|
||||||
|
|
||||||
use Mustache\Loader\StringLoader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class StringLoaderTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_Loader_StringLoaderTest extends PHPUnit_Framework_TestCase {
|
||||||
public function testLoadTemplates() {
|
public function testLoadTemplates() {
|
||||||
$loader = new StringLoader;
|
$loader = new Mustache_Loader_StringLoader;
|
||||||
|
|
||||||
$this->assertEquals('foo', $loader->load('foo'));
|
$this->assertEquals('foo', $loader->load('foo'));
|
||||||
$this->assertEquals('{{ bar }}', $loader->load('{{ bar }}'));
|
$this->assertEquals('{{ bar }}', $loader->load('{{ bar }}'));
|
||||||
|
|||||||
@@ -9,19 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test;
|
|
||||||
|
|
||||||
use Mustache\Compiler;
|
|
||||||
use Mustache\Mustache;
|
|
||||||
use Mustache\Loader\StringLoader;
|
|
||||||
use Mustache\Loader\ArrayLoader;
|
|
||||||
use Mustache\Parser;
|
|
||||||
use Mustache\Tokenizer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class MustacheTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_MustacheTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
private static $tempDir;
|
private static $tempDir;
|
||||||
|
|
||||||
@@ -33,9 +24,9 @@ class MustacheTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testConstructor() {
|
public function testConstructor() {
|
||||||
$loader = new StringLoader;
|
$loader = new Mustache_Loader_StringLoader;
|
||||||
$partialsLoader = new ArrayLoader;
|
$partialsLoader = new Mustache_Loader_ArrayLoader;
|
||||||
$mustache = new Mustache(array(
|
$mustache = new Mustache_Mustache(array(
|
||||||
'template_class_prefix' => '__whot__',
|
'template_class_prefix' => '__whot__',
|
||||||
'cache' => self::$tempDir,
|
'cache' => self::$tempDir,
|
||||||
'loader' => $loader,
|
'loader' => $loader,
|
||||||
@@ -67,7 +58,7 @@ class MustacheTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$data = array('bar' => 'baz');
|
$data = array('bar' => 'baz');
|
||||||
$output = 'TEH OUTPUT';
|
$output = 'TEH OUTPUT';
|
||||||
|
|
||||||
$template = $this->getMockBuilder('Mustache\Template')
|
$template = $this->getMockBuilder('Mustache_Template')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
@@ -84,11 +75,11 @@ class MustacheTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSettingServices() {
|
public function testSettingServices() {
|
||||||
$loader = new StringLoader;
|
$loader = new Mustache_Loader_StringLoader;
|
||||||
$tokenizer = new Tokenizer;
|
$tokenizer = new Mustache_Tokenizer;
|
||||||
$parser = new Parser;
|
$parser = new Mustache_Parser;
|
||||||
$compiler = new Compiler;
|
$compiler = new Mustache_Compiler;
|
||||||
$mustache = new Mustache;
|
$mustache = new Mustache_Mustache;
|
||||||
|
|
||||||
$this->assertNotSame($loader, $mustache->getLoader());
|
$this->assertNotSame($loader, $mustache->getLoader());
|
||||||
$mustache->setLoader($loader);
|
$mustache->setLoader($loader);
|
||||||
@@ -115,7 +106,7 @@ class MustacheTest extends \PHPUnit_Framework_TestCase {
|
|||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
public function testCache() {
|
public function testCache() {
|
||||||
$mustache = new Mustache(array(
|
$mustache = new Mustache_Mustache(array(
|
||||||
'template_class_prefix' => '__whot__',
|
'template_class_prefix' => '__whot__',
|
||||||
'cache' => self::$tempDir,
|
'cache' => self::$tempDir,
|
||||||
));
|
));
|
||||||
@@ -126,7 +117,7 @@ class MustacheTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$fileName = self::$tempDir . '/' . $className . '.php';
|
$fileName = self::$tempDir . '/' . $className . '.php';
|
||||||
$this->assertInstanceOf($className, $template);
|
$this->assertInstanceOf($className, $template);
|
||||||
$this->assertFileExists($fileName);
|
$this->assertFileExists($fileName);
|
||||||
$this->assertContains("\nclass $className extends \Mustache\Template", file_get_contents($fileName));
|
$this->assertContains("\nclass $className extends Mustache_Template", file_get_contents($fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,7 +125,7 @@ class MustacheTest extends \PHPUnit_Framework_TestCase {
|
|||||||
* @dataProvider getBadEscapers
|
* @dataProvider getBadEscapers
|
||||||
*/
|
*/
|
||||||
public function testNonCallableEscapeThrowsException($escape) {
|
public function testNonCallableEscapeThrowsException($escape) {
|
||||||
new Mustache(array('escape' => $escape));
|
new Mustache_Mustache(array('escape' => $escape));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBadEscapers() {
|
public function getBadEscapers() {
|
||||||
@@ -144,25 +135,12 @@ class MustacheTest extends \PHPUnit_Framework_TestCase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group functional
|
|
||||||
* @expectedException \RuntimeException
|
|
||||||
*/
|
|
||||||
public function testCacheFailsThrowException() {
|
|
||||||
global $mustacheFilesystemRenameHax;
|
|
||||||
|
|
||||||
$mustacheFilesystemRenameHax = true;
|
|
||||||
|
|
||||||
$mustache = new Mustache(array('cache' => self::$tempDir));
|
|
||||||
$mustache->loadTemplate('{{ foo }}');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \RuntimeException
|
* @expectedException \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function testImmutablePartialsLoadersThrowException() {
|
public function testImmutablePartialsLoadersThrowException() {
|
||||||
$mustache = new Mustache(array(
|
$mustache = new Mustache_Mustache(array(
|
||||||
'partials_loader' => new StringLoader,
|
'partials_loader' => new Mustache_Loader_StringLoader,
|
||||||
));
|
));
|
||||||
|
|
||||||
$mustache->setPartials(array('foo' => '{{ foo }}'));
|
$mustache->setPartials(array('foo' => '{{ foo }}'));
|
||||||
@@ -171,7 +149,7 @@ class MustacheTest extends \PHPUnit_Framework_TestCase {
|
|||||||
public function testHelpers() {
|
public function testHelpers() {
|
||||||
$foo = function() { return 'foo'; };
|
$foo = function() { return 'foo'; };
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
$mustache = new Mustache(array('helpers' => array(
|
$mustache = new Mustache_Mustache(array('helpers' => array(
|
||||||
'foo' => $foo,
|
'foo' => $foo,
|
||||||
'bar' => $bar,
|
'bar' => $bar,
|
||||||
)));
|
)));
|
||||||
@@ -207,7 +185,7 @@ class MustacheTest extends \PHPUnit_Framework_TestCase {
|
|||||||
* @expectedException \InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testSetHelpersThrowsExceptions() {
|
public function testSetHelpersThrowsExceptions() {
|
||||||
$mustache = new Mustache;
|
$mustache = new Mustache_Mustache;
|
||||||
$mustache->setHelpers('monkeymonkeymonkey');
|
$mustache->setHelpers('monkeymonkeymonkey');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +210,7 @@ class MustacheTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MustacheStub extends Mustache {
|
class MustacheStub extends Mustache_Mustache {
|
||||||
public $source;
|
public $source;
|
||||||
public $template;
|
public $template;
|
||||||
public function loadTemplate($source) {
|
public function loadTemplate($source) {
|
||||||
@@ -241,14 +219,3 @@ class MustacheStub extends Mustache {
|
|||||||
return $this->template;
|
return $this->template;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// It's prob'ly best if you ignore this bit.
|
|
||||||
|
|
||||||
namespace Mustache;
|
|
||||||
|
|
||||||
function rename($a, $b) {
|
|
||||||
global $mustacheFilesystemRenameHax;
|
|
||||||
|
|
||||||
return ($mustacheFilesystemRenameHax) ? false : \rename($a, $b);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,22 +9,17 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test;
|
|
||||||
|
|
||||||
use Mustache\Parser;
|
|
||||||
use Mustache\Tokenizer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class ParserTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_ParserTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getTokenSets
|
* @dataProvider getTokenSets
|
||||||
*/
|
*/
|
||||||
public function testParse($tokens, $expected)
|
public function testParse($tokens, $expected)
|
||||||
{
|
{
|
||||||
$parser = new Parser;
|
$parser = new Mustache_Parser;
|
||||||
$this->assertEquals($expected, $parser->parse($tokens));
|
$this->assertEquals($expected, $parser->parse($tokens));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,12 +38,12 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
array(
|
array(
|
||||||
array(array(
|
array(array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_ESCAPED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
|
||||||
Tokenizer::NAME => 'name'
|
Mustache_Tokenizer::NAME => 'name'
|
||||||
)),
|
)),
|
||||||
array(array(
|
array(array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_ESCAPED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
|
||||||
Tokenizer::NAME => 'name'
|
Mustache_Tokenizer::NAME => 'name'
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -56,32 +51,32 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
|
|||||||
array(
|
array(
|
||||||
'foo',
|
'foo',
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_INVERTED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_INVERTED,
|
||||||
Tokenizer::INDEX => 123,
|
Mustache_Tokenizer::INDEX => 123,
|
||||||
Tokenizer::NAME => 'parent'
|
Mustache_Tokenizer::NAME => 'parent'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_ESCAPED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
|
||||||
Tokenizer::NAME => 'name'
|
Mustache_Tokenizer::NAME => 'name'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_END_SECTION,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
|
||||||
Tokenizer::INDEX => 456,
|
Mustache_Tokenizer::INDEX => 456,
|
||||||
Tokenizer::NAME => 'parent'
|
Mustache_Tokenizer::NAME => 'parent'
|
||||||
),
|
),
|
||||||
'bar',
|
'bar',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'foo',
|
'foo',
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_INVERTED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_INVERTED,
|
||||||
Tokenizer::NAME => 'parent',
|
Mustache_Tokenizer::NAME => 'parent',
|
||||||
Tokenizer::INDEX => 123,
|
Mustache_Tokenizer::INDEX => 123,
|
||||||
Tokenizer::END => 456,
|
Mustache_Tokenizer::END => 456,
|
||||||
Tokenizer::NODES => array(
|
Mustache_Tokenizer::NODES => array(
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_ESCAPED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
|
||||||
Tokenizer::NAME => 'name'
|
Mustache_Tokenizer::NAME => 'name'
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -97,7 +92,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
|
|||||||
* @expectedException \LogicException
|
* @expectedException \LogicException
|
||||||
*/
|
*/
|
||||||
public function testParserThrowsExceptions($tokens) {
|
public function testParserThrowsExceptions($tokens) {
|
||||||
$parser = new Parser;
|
$parser = new Mustache_Parser;
|
||||||
$parser->parse($tokens);
|
$parser->parse($tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,9 +102,9 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
|
|||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_SECTION,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
|
||||||
Tokenizer::NAME => 'parent',
|
Mustache_Tokenizer::NAME => 'parent',
|
||||||
Tokenizer::INDEX => 123,
|
Mustache_Tokenizer::INDEX => 123,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -118,9 +113,9 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
|
|||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_INVERTED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_INVERTED,
|
||||||
Tokenizer::NAME => 'parent',
|
Mustache_Tokenizer::NAME => 'parent',
|
||||||
Tokenizer::INDEX => 123,
|
Mustache_Tokenizer::INDEX => 123,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -129,9 +124,9 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
|
|||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_END_SECTION,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
|
||||||
Tokenizer::NAME => 'parent',
|
Mustache_Tokenizer::NAME => 'parent',
|
||||||
Tokenizer::INDEX => 123,
|
Mustache_Tokenizer::INDEX => 123,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -140,24 +135,24 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
|
|||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_SECTION,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
|
||||||
Tokenizer::NAME => 'parent',
|
Mustache_Tokenizer::NAME => 'parent',
|
||||||
Tokenizer::INDEX => 123,
|
Mustache_Tokenizer::INDEX => 123,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_SECTION,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
|
||||||
Tokenizer::NAME => 'child',
|
Mustache_Tokenizer::NAME => 'child',
|
||||||
Tokenizer::INDEX => 123,
|
Mustache_Tokenizer::INDEX => 123,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_END_SECTION,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
|
||||||
Tokenizer::NAME => 'parent',
|
Mustache_Tokenizer::NAME => 'parent',
|
||||||
Tokenizer::INDEX => 123,
|
Mustache_Tokenizer::INDEX => 123,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_END_SECTION,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
|
||||||
Tokenizer::NAME => 'child',
|
Mustache_Tokenizer::NAME => 'child',
|
||||||
Tokenizer::INDEX => 123,
|
Mustache_Tokenizer::INDEX => 123,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -9,28 +9,22 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test;
|
|
||||||
|
|
||||||
use Mustache\Context;
|
|
||||||
use Mustache\Mustache;
|
|
||||||
use Mustache\Template;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class TemplateTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_TemplateTest extends PHPUnit_Framework_TestCase {
|
||||||
public function testConstructor() {
|
public function testConstructor() {
|
||||||
$mustache = new Mustache;
|
$mustache = new Mustache_Mustache;
|
||||||
$template = new TemplateStub($mustache);
|
$template = new Mustache_Test_TemplateStub($mustache);
|
||||||
$this->assertSame($mustache, $template->getMustache());
|
$this->assertSame($mustache, $template->getMustache());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRendering() {
|
public function testRendering() {
|
||||||
$rendered = '<< wheee >>';
|
$rendered = '<< wheee >>';
|
||||||
$mustache = new Mustache;
|
$mustache = new Mustache_Mustache;
|
||||||
$template = new TemplateStub($mustache);
|
$template = new Mustache_Test_TemplateStub($mustache);
|
||||||
$template->rendered = $rendered;
|
$template->rendered = $rendered;
|
||||||
$context = new Context;
|
$context = new Mustache_Context;
|
||||||
|
|
||||||
$this->assertEquals($rendered, $template());
|
$this->assertEquals($rendered, $template());
|
||||||
$this->assertEquals($rendered, $template->render());
|
$this->assertEquals($rendered, $template->render());
|
||||||
@@ -39,14 +33,14 @@ class TemplateTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TemplateStub extends Template {
|
class Mustache_Test_TemplateStub extends Mustache_Template {
|
||||||
public $rendered;
|
public $rendered;
|
||||||
|
|
||||||
public function getMustache() {
|
public function getMustache() {
|
||||||
return $this->mustache;
|
return $this->mustache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderInternal(Context $context, $indent = '', $escape = false) {
|
public function renderInternal(Mustache_Context $context, $indent = '', $escape = false) {
|
||||||
return $this->rendered;
|
return $this->rendered;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,16 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache\Test;
|
|
||||||
|
|
||||||
use Mustache\Tokenizer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class TokenizerTest extends \PHPUnit_Framework_TestCase {
|
class Mustache_Test_TokenizerTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getTokens
|
* @dataProvider getTokens
|
||||||
*/
|
*/
|
||||||
public function testScan($text, $delimiters, $expected) {
|
public function testScan($text, $delimiters, $expected) {
|
||||||
$tokenizer = new Tokenizer;
|
$tokenizer = new Mustache_Tokenizer;
|
||||||
$this->assertSame($expected, $tokenizer->scan($text, $delimiters));
|
$this->assertSame($expected, $tokenizer->scan($text, $delimiters));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,11 +41,11 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
null,
|
null,
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_ESCAPED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
|
||||||
Tokenizer::NAME => 'name',
|
Mustache_Tokenizer::NAME => 'name',
|
||||||
Tokenizer::OTAG => '{{',
|
Mustache_Tokenizer::OTAG => '{{',
|
||||||
Tokenizer::CTAG => '}}',
|
Mustache_Tokenizer::CTAG => '}}',
|
||||||
Tokenizer::INDEX => 10,
|
Mustache_Tokenizer::INDEX => 10,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@@ -65,11 +61,11 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'<<< >>>',
|
'<<< >>>',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_ESCAPED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
|
||||||
Tokenizer::NAME => 'name',
|
Mustache_Tokenizer::NAME => 'name',
|
||||||
Tokenizer::OTAG => '<<<',
|
Mustache_Tokenizer::OTAG => '<<<',
|
||||||
Tokenizer::CTAG => '>>>',
|
Mustache_Tokenizer::CTAG => '>>>',
|
||||||
Tokenizer::INDEX => 12,
|
Mustache_Tokenizer::INDEX => 12,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@@ -79,42 +75,42 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
null,
|
null,
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_UNESCAPED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_UNESCAPED,
|
||||||
Tokenizer::NAME => 'a',
|
Mustache_Tokenizer::NAME => 'a',
|
||||||
Tokenizer::OTAG => '{{',
|
Mustache_Tokenizer::OTAG => '{{',
|
||||||
Tokenizer::CTAG => '}}',
|
Mustache_Tokenizer::CTAG => '}}',
|
||||||
Tokenizer::INDEX => 8,
|
Mustache_Tokenizer::INDEX => 8,
|
||||||
),
|
),
|
||||||
"\n",
|
"\n",
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_SECTION,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_SECTION,
|
||||||
Tokenizer::NAME => 'b',
|
Mustache_Tokenizer::NAME => 'b',
|
||||||
Tokenizer::OTAG => '{{',
|
Mustache_Tokenizer::OTAG => '{{',
|
||||||
Tokenizer::CTAG => '}}',
|
Mustache_Tokenizer::CTAG => '}}',
|
||||||
Tokenizer::INDEX => 18,
|
Mustache_Tokenizer::INDEX => 18,
|
||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_ESCAPED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED,
|
||||||
Tokenizer::NAME => 'c',
|
Mustache_Tokenizer::NAME => 'c',
|
||||||
Tokenizer::OTAG => '|',
|
Mustache_Tokenizer::OTAG => '|',
|
||||||
Tokenizer::CTAG => '|',
|
Mustache_Tokenizer::CTAG => '|',
|
||||||
Tokenizer::INDEX => 37,
|
Mustache_Tokenizer::INDEX => 37,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_END_SECTION,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_END_SECTION,
|
||||||
Tokenizer::NAME => 'b',
|
Mustache_Tokenizer::NAME => 'b',
|
||||||
Tokenizer::OTAG => '|',
|
Mustache_Tokenizer::OTAG => '|',
|
||||||
Tokenizer::CTAG => '|',
|
Mustache_Tokenizer::CTAG => '|',
|
||||||
Tokenizer::INDEX => 37,
|
Mustache_Tokenizer::INDEX => 37,
|
||||||
),
|
),
|
||||||
"\n",
|
"\n",
|
||||||
array(
|
array(
|
||||||
Tokenizer::TYPE => Tokenizer::T_UNESCAPED,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_UNESCAPED,
|
||||||
Tokenizer::NAME => 'd',
|
Mustache_Tokenizer::NAME => 'd',
|
||||||
Tokenizer::OTAG => '|',
|
Mustache_Tokenizer::OTAG => '|',
|
||||||
Tokenizer::CTAG => '|',
|
Mustache_Tokenizer::CTAG => '|',
|
||||||
Tokenizer::INDEX => 51,
|
Mustache_Tokenizer::INDEX => 51,
|
||||||
),
|
),
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -10,6 +10,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
require __DIR__.'/../src/Mustache/Autoloader.php';
|
require __DIR__.'/../src/Mustache/Autoloader.php';
|
||||||
\Mustache\Autoloader::register();
|
Mustache_Autoloader::register();
|
||||||
|
|
||||||
require __DIR__.'/../vendor/yaml/lib/sfYamlParser.php';
|
require __DIR__.'/../vendor/yaml/lib/sfYamlParser.php';
|
||||||
|
|||||||
+1
-3
@@ -9,8 +9,6 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache;
|
class Mustache_Bar {
|
||||||
|
|
||||||
class Bar {
|
|
||||||
// nada
|
// nada
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -9,8 +9,6 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mustache;
|
class Mustache_Foo {
|
||||||
|
|
||||||
class Foo {
|
|
||||||
// nada
|
// nada
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user