Update to proposed PSR-1 coding standard.
* 4 space (no tab) indent * K&R-style braces
This commit is contained in:
@@ -12,7 +12,8 @@
|
|||||||
/**
|
/**
|
||||||
* Mustache class autoloader.
|
* Mustache class autoloader.
|
||||||
*/
|
*/
|
||||||
class Mustache_Autoloader {
|
class Mustache_Autoloader
|
||||||
|
{
|
||||||
|
|
||||||
private $baseDir;
|
private $baseDir;
|
||||||
|
|
||||||
@@ -21,7 +22,8 @@ class Mustache_Autoloader {
|
|||||||
*
|
*
|
||||||
* @param string $baseDir Mustache library base directory (default: dirname(__FILE__).'/..')
|
* @param string $baseDir Mustache library base directory (default: dirname(__FILE__).'/..')
|
||||||
*/
|
*/
|
||||||
public function __construct($baseDir = null) {
|
public function __construct($baseDir = null)
|
||||||
|
{
|
||||||
if ($baseDir === null) {
|
if ($baseDir === null) {
|
||||||
$this->baseDir = dirname(__FILE__).'/..';
|
$this->baseDir = dirname(__FILE__).'/..';
|
||||||
} else {
|
} else {
|
||||||
@@ -36,7 +38,8 @@ class Mustache_Autoloader {
|
|||||||
*
|
*
|
||||||
* @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);
|
||||||
spl_autoload_register(array($loader, 'autoload'));
|
spl_autoload_register(array($loader, 'autoload'));
|
||||||
|
|
||||||
@@ -48,7 +51,8 @@ class Mustache_Autoloader {
|
|||||||
*
|
*
|
||||||
* @param string $class
|
* @param string $class
|
||||||
*/
|
*/
|
||||||
public function autoload($class) {
|
public function autoload($class)
|
||||||
|
{
|
||||||
if ($class[0] === '\\') {
|
if ($class[0] === '\\') {
|
||||||
$class = substr($class, 1);
|
$class = substr($class, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-16
@@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* 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 Mustache_Compiler {
|
class Mustache_Compiler
|
||||||
|
{
|
||||||
|
|
||||||
private $sections;
|
private $sections;
|
||||||
private $source;
|
private $source;
|
||||||
@@ -31,7 +32,8 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string Generated PHP source code
|
* @return string Generated PHP source code
|
||||||
*/
|
*/
|
||||||
public function compile($source, array $tree, $name, $customEscape = false, $charset = 'UTF-8') {
|
public function compile($source, array $tree, $name, $customEscape = false, $charset = 'UTF-8')
|
||||||
|
{
|
||||||
$this->sections = array();
|
$this->sections = array();
|
||||||
$this->source = $source;
|
$this->source = $source;
|
||||||
$this->indentNextLine = true;
|
$this->indentNextLine = true;
|
||||||
@@ -51,7 +53,8 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string Generated PHP source code;
|
* @return string Generated PHP source code;
|
||||||
*/
|
*/
|
||||||
private function walk(array $tree, $level = 0) {
|
private function walk(array $tree, $level = 0)
|
||||||
|
{
|
||||||
$code = '';
|
$code = '';
|
||||||
$level++;
|
$level++;
|
||||||
foreach ($tree as $node) {
|
foreach ($tree as $node) {
|
||||||
@@ -112,8 +115,10 @@ class Mustache_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
|
||||||
|
|
||||||
@@ -134,7 +139,8 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string Generated PHP source code
|
* @return string Generated PHP source code
|
||||||
*/
|
*/
|
||||||
private function writeCode($tree, $name) {
|
private function writeCode($tree, $name)
|
||||||
|
{
|
||||||
$code = $this->walk($tree);
|
$code = $this->walk($tree);
|
||||||
$sections = implode("\n", $this->sections);
|
$sections = implode("\n", $this->sections);
|
||||||
|
|
||||||
@@ -178,7 +184,8 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string Generated section PHP source code
|
* @return string Generated section PHP source code
|
||||||
*/
|
*/
|
||||||
private function section($nodes, $id, $start, $end, $otag, $ctag, $level) {
|
private function section($nodes, $id, $start, $end, $otag, $ctag, $level)
|
||||||
|
{
|
||||||
$method = $this->getFindMethod($id);
|
$method = $this->getFindMethod($id);
|
||||||
$id = var_export($id, true);
|
$id = var_export($id, true);
|
||||||
$source = var_export(substr($this->source, $start, $end - $start), true);
|
$source = var_export(substr($this->source, $start, $end - $start), true);
|
||||||
@@ -214,7 +221,8 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string Generated inverted section PHP source code
|
* @return string Generated inverted section PHP source code
|
||||||
*/
|
*/
|
||||||
private function invertedSection($nodes, $id, $level) {
|
private function invertedSection($nodes, $id, $level)
|
||||||
|
{
|
||||||
$method = $this->getFindMethod($id);
|
$method = $this->getFindMethod($id);
|
||||||
$id = var_export($id, true);
|
$id = var_export($id, true);
|
||||||
|
|
||||||
@@ -236,7 +244,8 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string Generated partial call PHP source code
|
* @return string Generated partial call PHP source code
|
||||||
*/
|
*/
|
||||||
private function partial($id, $indent, $level) {
|
private function partial($id, $indent, $level)
|
||||||
|
{
|
||||||
return sprintf(
|
return sprintf(
|
||||||
$this->prepare(self::PARTIAL, $level),
|
$this->prepare(self::PARTIAL, $level),
|
||||||
var_export($id, true),
|
var_export($id, true),
|
||||||
@@ -263,7 +272,8 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string Generated variable interpolation PHP source
|
* @return string Generated variable interpolation PHP source
|
||||||
*/
|
*/
|
||||||
private function variable($id, $escape, $level) {
|
private function variable($id, $escape, $level)
|
||||||
|
{
|
||||||
$method = $this->getFindMethod($id);
|
$method = $this->getFindMethod($id);
|
||||||
$id = ($method !== 'last') ? var_export($id, true) : '';
|
$id = ($method !== 'last') ? var_export($id, true) : '';
|
||||||
$value = $escape ? $this->getEscape() : '$value';
|
$value = $escape ? $this->getEscape() : '$value';
|
||||||
@@ -282,7 +292,8 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string Generated output Buffer call PHP source
|
* @return string Generated output Buffer call PHP source
|
||||||
*/
|
*/
|
||||||
private function text($text, $level) {
|
private function text($text, $level)
|
||||||
|
{
|
||||||
if ($text === "\n") {
|
if ($text === "\n") {
|
||||||
$this->indentNextLine = true;
|
$this->indentNextLine = true;
|
||||||
|
|
||||||
@@ -301,13 +312,14 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string PHP source code snippet
|
* @return string PHP source code snippet
|
||||||
*/
|
*/
|
||||||
private function prepare($text, $bonus = 0, $prependNewline = true) {
|
private function prepare($text, $bonus = 0, $prependNewline = true)
|
||||||
|
{
|
||||||
$text = ($prependNewline ? "\n" : '').trim($text);
|
$text = ($prependNewline ? "\n" : '').trim($text);
|
||||||
if ($prependNewline) {
|
if ($prependNewline) {
|
||||||
$bonus++;
|
$bonus++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return preg_replace("/\n(\t\t)?/", "\n".str_repeat("\t", $bonus), $text);
|
return preg_replace("/\n( {8})?/", "\n".str_repeat(" ", $bonus * 4), $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_ESCAPE = 'htmlspecialchars(%s, ENT_COMPAT, %s)';
|
const DEFAULT_ESCAPE = 'htmlspecialchars(%s, ENT_COMPAT, %s)';
|
||||||
@@ -318,7 +330,8 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string Either a custom callback, or an inline call to `htmlspecialchars`
|
* @return string Either a custom callback, or an inline call to `htmlspecialchars`
|
||||||
*/
|
*/
|
||||||
private function getEscape($value = '$value') {
|
private function getEscape($value = '$value')
|
||||||
|
{
|
||||||
if ($this->customEscape) {
|
if ($this->customEscape) {
|
||||||
return sprintf(self::CUSTOM_ESCAPE, $value);
|
return sprintf(self::CUSTOM_ESCAPE, $value);
|
||||||
} else {
|
} else {
|
||||||
@@ -339,7 +352,8 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string `find` method name
|
* @return string `find` method name
|
||||||
*/
|
*/
|
||||||
private function getFindMethod($id) {
|
private function getFindMethod($id)
|
||||||
|
{
|
||||||
if ($id === '.') {
|
if ($id === '.') {
|
||||||
return 'last';
|
return 'last';
|
||||||
} elseif (strpos($id, '.') === false) {
|
} elseif (strpos($id, '.') === false) {
|
||||||
@@ -356,7 +370,8 @@ class Mustache_Compiler {
|
|||||||
*
|
*
|
||||||
* @return string "$indent . " or ""
|
* @return string "$indent . " or ""
|
||||||
*/
|
*/
|
||||||
private function flushIndent() {
|
private function flushIndent()
|
||||||
|
{
|
||||||
if ($this->indentNextLine) {
|
if ($this->indentNextLine) {
|
||||||
$this->indentNextLine = false;
|
$this->indentNextLine = false;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
/**
|
/**
|
||||||
* Mustache Template rendering Context.
|
* Mustache Template rendering Context.
|
||||||
*/
|
*/
|
||||||
class Mustache_Context {
|
class Mustache_Context
|
||||||
|
{
|
||||||
private $stack = array();
|
private $stack = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,7 +21,8 @@ class Mustache_Context {
|
|||||||
*
|
*
|
||||||
* @param mixed $context Default rendering context (default: null)
|
* @param mixed $context Default rendering context (default: null)
|
||||||
*/
|
*/
|
||||||
public function __construct($context = null) {
|
public function __construct($context = null)
|
||||||
|
{
|
||||||
if ($context !== null) {
|
if ($context !== null) {
|
||||||
$this->stack = array($context);
|
$this->stack = array($context);
|
||||||
}
|
}
|
||||||
@@ -31,7 +33,8 @@ class Mustache_Context {
|
|||||||
*
|
*
|
||||||
* @param mixed $value Object or array to use for context
|
* @param mixed $value Object or array to use for context
|
||||||
*/
|
*/
|
||||||
public function push($value) {
|
public function push($value)
|
||||||
|
{
|
||||||
array_push($this->stack, $value);
|
array_push($this->stack, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +43,8 @@ class Mustache_Context {
|
|||||||
*
|
*
|
||||||
* @return mixed Last Context frame (object or array)
|
* @return mixed Last Context frame (object or array)
|
||||||
*/
|
*/
|
||||||
public function pop() {
|
public function pop()
|
||||||
|
{
|
||||||
return array_pop($this->stack);
|
return array_pop($this->stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +53,8 @@ class Mustache_Context {
|
|||||||
*
|
*
|
||||||
* @return mixed Last Context frame (object or array)
|
* @return mixed Last Context frame (object or array)
|
||||||
*/
|
*/
|
||||||
public function last() {
|
public function last()
|
||||||
|
{
|
||||||
return end($this->stack);
|
return end($this->stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +73,8 @@ class Mustache_Context {
|
|||||||
*
|
*
|
||||||
* @return mixed Variable value, or '' if not found
|
* @return mixed Variable value, or '' if not found
|
||||||
*/
|
*/
|
||||||
public function find($id) {
|
public function find($id)
|
||||||
|
{
|
||||||
return $this->findVariableInStack($id, $this->stack);
|
return $this->findVariableInStack($id, $this->stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +103,8 @@ class Mustache_Context {
|
|||||||
*
|
*
|
||||||
* @return mixed Variable value, or '' if not found
|
* @return mixed Variable value, or '' if not found
|
||||||
*/
|
*/
|
||||||
public function findDot($id) {
|
public function findDot($id)
|
||||||
|
{
|
||||||
$chunks = explode('.', $id);
|
$chunks = explode('.', $id);
|
||||||
$first = array_shift($chunks);
|
$first = array_shift($chunks);
|
||||||
$value = $this->findVariableInStack($first, $this->stack);
|
$value = $this->findVariableInStack($first, $this->stack);
|
||||||
@@ -123,7 +130,8 @@ class Mustache_Context {
|
|||||||
*
|
*
|
||||||
* @return mixed Variable value, or '' if not found
|
* @return mixed Variable value, or '' if not found
|
||||||
*/
|
*/
|
||||||
private function findVariableInStack($id, array $stack) {
|
private function findVariableInStack($id, array $stack)
|
||||||
|
{
|
||||||
for ($i = count($stack) - 1; $i >= 0; $i--) {
|
for ($i = count($stack) - 1; $i >= 0; $i--) {
|
||||||
if (is_object($stack[$i])) {
|
if (is_object($stack[$i])) {
|
||||||
if (method_exists($stack[$i], $id)) {
|
if (method_exists($stack[$i], $id)) {
|
||||||
|
|||||||
+64
-32
@@ -21,7 +21,8 @@
|
|||||||
*
|
*
|
||||||
* @author Justin Hileman {@link http://justinhileman.com}
|
* @author Justin Hileman {@link http://justinhileman.com}
|
||||||
*/
|
*/
|
||||||
class Mustache_Engine {
|
class Mustache_Engine
|
||||||
|
{
|
||||||
const VERSION = '2.0.0-dev';
|
const VERSION = '2.0.0-dev';
|
||||||
const SPEC_VERSION = '1.1.2';
|
const SPEC_VERSION = '1.1.2';
|
||||||
|
|
||||||
@@ -77,7 +78,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @param array $options (default: array())
|
* @param array $options (default: array())
|
||||||
*/
|
*/
|
||||||
public function __construct(array $options = array()) {
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
if (isset($options['template_class_prefix'])) {
|
if (isset($options['template_class_prefix'])) {
|
||||||
$this->templateClassPrefix = $options['template_class_prefix'];
|
$this->templateClassPrefix = $options['template_class_prefix'];
|
||||||
}
|
}
|
||||||
@@ -128,7 +130,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return string Rendered template
|
* @return string Rendered template
|
||||||
*/
|
*/
|
||||||
public function render($template, $data) {
|
public function render($template, $data)
|
||||||
|
{
|
||||||
return $this->loadTemplate($template)->render($data);
|
return $this->loadTemplate($template)->render($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +140,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return mixed Callable or null
|
* @return mixed Callable or null
|
||||||
*/
|
*/
|
||||||
public function getEscape() {
|
public function getEscape()
|
||||||
|
{
|
||||||
return $this->escape;
|
return $this->escape;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +150,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getCharset() {
|
public function getCharset()
|
||||||
|
{
|
||||||
return $this->charset;
|
return $this->charset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +160,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @param Mustache_Loader $loader
|
* @param Mustache_Loader $loader
|
||||||
*/
|
*/
|
||||||
public function setLoader(Mustache_Loader $loader) {
|
public function setLoader(Mustache_Loader $loader)
|
||||||
|
{
|
||||||
$this->loader = $loader;
|
$this->loader = $loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +173,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return Mustache_Loader
|
* @return Mustache_Loader
|
||||||
*/
|
*/
|
||||||
public function getLoader() {
|
public function getLoader()
|
||||||
|
{
|
||||||
if (!isset($this->loader)) {
|
if (!isset($this->loader)) {
|
||||||
$this->loader = new Mustache_Loader_StringLoader;
|
$this->loader = new Mustache_Loader_StringLoader;
|
||||||
}
|
}
|
||||||
@@ -180,7 +187,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @param Mustache_Loader $partialsLoader
|
* @param Mustache_Loader $partialsLoader
|
||||||
*/
|
*/
|
||||||
public function setPartialsLoader(Mustache_Loader $partialsLoader) {
|
public function setPartialsLoader(Mustache_Loader $partialsLoader)
|
||||||
|
{
|
||||||
$this->partialsLoader = $partialsLoader;
|
$this->partialsLoader = $partialsLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +200,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return Mustache_Loader
|
* @return Mustache_Loader
|
||||||
*/
|
*/
|
||||||
public function getPartialsLoader() {
|
public function getPartialsLoader()
|
||||||
|
{
|
||||||
if (!isset($this->partialsLoader)) {
|
if (!isset($this->partialsLoader)) {
|
||||||
$this->partialsLoader = new Mustache_Loader_ArrayLoader;
|
$this->partialsLoader = new Mustache_Loader_ArrayLoader;
|
||||||
}
|
}
|
||||||
@@ -207,7 +216,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @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 Mustache_Loader_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');
|
||||||
@@ -227,7 +237,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @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');
|
||||||
}
|
}
|
||||||
@@ -246,7 +257,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return Mustache_HelperCollection
|
* @return Mustache_HelperCollection
|
||||||
*/
|
*/
|
||||||
public function getHelpers() {
|
public function getHelpers()
|
||||||
|
{
|
||||||
if (!isset($this->helpers)) {
|
if (!isset($this->helpers)) {
|
||||||
$this->helpers = new Mustache_HelperCollection;
|
$this->helpers = new Mustache_HelperCollection;
|
||||||
}
|
}
|
||||||
@@ -262,7 +274,8 @@ class Mustache_Engine {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $helper
|
* @param mixed $helper
|
||||||
*/
|
*/
|
||||||
public function addHelper($name, $helper) {
|
public function addHelper($name, $helper)
|
||||||
|
{
|
||||||
$this->getHelpers()->add($name, $helper);
|
$this->getHelpers()->add($name, $helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +288,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return mixed Helper
|
* @return mixed Helper
|
||||||
*/
|
*/
|
||||||
public function getHelper($name) {
|
public function getHelper($name)
|
||||||
|
{
|
||||||
return $this->getHelpers()->get($name);
|
return $this->getHelpers()->get($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,7 +302,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return boolean True if the helper is present
|
* @return boolean True if the helper is present
|
||||||
*/
|
*/
|
||||||
public function hasHelper($name) {
|
public function hasHelper($name)
|
||||||
|
{
|
||||||
return $this->getHelpers()->has($name);
|
return $this->getHelpers()->has($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,7 +314,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
public function removeHelper($name) {
|
public function removeHelper($name)
|
||||||
|
{
|
||||||
$this->getHelpers()->remove($name);
|
$this->getHelpers()->remove($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,7 +324,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @param Mustache_Tokenizer $tokenizer
|
* @param Mustache_Tokenizer $tokenizer
|
||||||
*/
|
*/
|
||||||
public function setTokenizer(Mustache_Tokenizer $tokenizer) {
|
public function setTokenizer(Mustache_Tokenizer $tokenizer)
|
||||||
|
{
|
||||||
$this->tokenizer = $tokenizer;
|
$this->tokenizer = $tokenizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +336,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return Mustache_Tokenizer
|
* @return Mustache_Tokenizer
|
||||||
*/
|
*/
|
||||||
public function getTokenizer() {
|
public function getTokenizer()
|
||||||
|
{
|
||||||
if (!isset($this->tokenizer)) {
|
if (!isset($this->tokenizer)) {
|
||||||
$this->tokenizer = new Mustache_Tokenizer;
|
$this->tokenizer = new Mustache_Tokenizer;
|
||||||
}
|
}
|
||||||
@@ -332,7 +350,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @param Mustache_Parser $parser
|
* @param Mustache_Parser $parser
|
||||||
*/
|
*/
|
||||||
public function setParser(Mustache_Parser $parser) {
|
public function setParser(Mustache_Parser $parser)
|
||||||
|
{
|
||||||
$this->parser = $parser;
|
$this->parser = $parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,7 +362,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return Mustache_Parser
|
* @return Mustache_Parser
|
||||||
*/
|
*/
|
||||||
public function getParser() {
|
public function getParser()
|
||||||
|
{
|
||||||
if (!isset($this->parser)) {
|
if (!isset($this->parser)) {
|
||||||
$this->parser = new Mustache_Parser;
|
$this->parser = new Mustache_Parser;
|
||||||
}
|
}
|
||||||
@@ -356,7 +376,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @param Mustache_Compiler $compiler
|
* @param Mustache_Compiler $compiler
|
||||||
*/
|
*/
|
||||||
public function setCompiler(Mustache_Compiler $compiler) {
|
public function setCompiler(Mustache_Compiler $compiler)
|
||||||
|
{
|
||||||
$this->compiler = $compiler;
|
$this->compiler = $compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +388,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return Mustache_Compiler
|
* @return Mustache_Compiler
|
||||||
*/
|
*/
|
||||||
public function getCompiler() {
|
public function getCompiler()
|
||||||
|
{
|
||||||
if (!isset($this->compiler)) {
|
if (!isset($this->compiler)) {
|
||||||
$this->compiler = new Mustache_Compiler;
|
$this->compiler = new Mustache_Compiler;
|
||||||
}
|
}
|
||||||
@@ -382,7 +404,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return string Mustache Template class name
|
* @return string Mustache Template class name
|
||||||
*/
|
*/
|
||||||
public function getTemplateClassName($source) {
|
public function getTemplateClassName($source)
|
||||||
|
{
|
||||||
return $this->templateClassPrefix . md5(sprintf(
|
return $this->templateClassPrefix . md5(sprintf(
|
||||||
'version:%s,escape:%s,charset:%s,source:%s',
|
'version:%s,escape:%s,charset:%s,source:%s',
|
||||||
self::VERSION,
|
self::VERSION,
|
||||||
@@ -399,7 +422,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,7 +437,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return Mustache_Template
|
* @return Mustache_Template
|
||||||
*/
|
*/
|
||||||
public function loadPartial($name) {
|
public function loadPartial($name)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
return $this->loadSource($this->getPartialsLoader()->load($name));
|
return $this->loadSource($this->getPartialsLoader()->load($name));
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
@@ -432,7 +457,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return Mustache_Template
|
* @return Mustache_Template
|
||||||
*/
|
*/
|
||||||
public function loadLambda($source, $delims = null) {
|
public function loadLambda($source, $delims = null)
|
||||||
|
{
|
||||||
if ($delims !== null) {
|
if ($delims !== null) {
|
||||||
$source = $delims . "\n" . $source;
|
$source = $delims . "\n" . $source;
|
||||||
}
|
}
|
||||||
@@ -451,7 +477,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return Mustache_Template
|
* @return Mustache_Template
|
||||||
*/
|
*/
|
||||||
private function loadSource($source) {
|
private function loadSource($source)
|
||||||
|
{
|
||||||
$className = $this->getTemplateClassName($source);
|
$className = $this->getTemplateClassName($source);
|
||||||
|
|
||||||
if (!isset($this->templates[$className])) {
|
if (!isset($this->templates[$className])) {
|
||||||
@@ -482,7 +509,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return array Tokens
|
* @return array Tokens
|
||||||
*/
|
*/
|
||||||
private function tokenize($source) {
|
private function tokenize($source)
|
||||||
|
{
|
||||||
return $this->getTokenizer()->scan($source);
|
return $this->getTokenizer()->scan($source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,7 +523,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return array Token tree
|
* @return array Token tree
|
||||||
*/
|
*/
|
||||||
private function parse($source) {
|
private function parse($source)
|
||||||
|
{
|
||||||
return $this->getParser()->parse($this->tokenize($source));
|
return $this->getParser()->parse($this->tokenize($source));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,7 +537,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return string generated Mustache template class code
|
* @return string generated Mustache template class code
|
||||||
*/
|
*/
|
||||||
private function compile($source) {
|
private function compile($source)
|
||||||
|
{
|
||||||
$tree = $this->parse($source);
|
$tree = $this->parse($source);
|
||||||
$name = $this->getTemplateClassName($source);
|
$name = $this->getTemplateClassName($source);
|
||||||
|
|
||||||
@@ -522,7 +552,8 @@ class Mustache_Engine {
|
|||||||
*
|
*
|
||||||
* @return string Mustache Template class cache filename
|
* @return string Mustache Template class cache filename
|
||||||
*/
|
*/
|
||||||
private function getCacheFilename($source) {
|
private function getCacheFilename($source)
|
||||||
|
{
|
||||||
if ($this->cache) {
|
if ($this->cache) {
|
||||||
return sprintf('%s/%s.php', $this->cache, $this->getTemplateClassName($source));
|
return sprintf('%s/%s.php', $this->cache, $this->getTemplateClassName($source));
|
||||||
}
|
}
|
||||||
@@ -536,7 +567,8 @@ class Mustache_Engine {
|
|||||||
* @param string $fileName
|
* @param string $fileName
|
||||||
* @param string $source
|
* @param string $source
|
||||||
*/
|
*/
|
||||||
private function writeCacheFile($fileName, $source) {
|
private function writeCacheFile($fileName, $source)
|
||||||
|
{
|
||||||
if (!is_dir(dirname($fileName))) {
|
if (!is_dir(dirname($fileName))) {
|
||||||
mkdir(dirname($fileName), 0777, true);
|
mkdir(dirname($fileName), 0777, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
/**
|
/**
|
||||||
* A collection of helpers for a Mustache instance.
|
* A collection of helpers for a Mustache instance.
|
||||||
*/
|
*/
|
||||||
class Mustache_HelperCollection {
|
class Mustache_HelperCollection
|
||||||
|
{
|
||||||
private $helpers = array();
|
private $helpers = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +25,8 @@ class Mustache_HelperCollection {
|
|||||||
*
|
*
|
||||||
* @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');
|
||||||
@@ -44,7 +46,8 @@ class Mustache_HelperCollection {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $helper
|
* @param mixed $helper
|
||||||
*/
|
*/
|
||||||
public function __set($name, $helper) {
|
public function __set($name, $helper)
|
||||||
|
{
|
||||||
$this->add($name, $helper);
|
$this->add($name, $helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +57,8 @@ class Mustache_HelperCollection {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $helper
|
* @param mixed $helper
|
||||||
*/
|
*/
|
||||||
public function add($name, $helper) {
|
public function add($name, $helper)
|
||||||
|
{
|
||||||
$this->helpers[$name] = $helper;
|
$this->helpers[$name] = $helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +71,8 @@ class Mustache_HelperCollection {
|
|||||||
*
|
*
|
||||||
* @return mixed Helper
|
* @return mixed Helper
|
||||||
*/
|
*/
|
||||||
public function __get($name) {
|
public function __get($name)
|
||||||
|
{
|
||||||
return $this->get($name);
|
return $this->get($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +83,8 @@ class Mustache_HelperCollection {
|
|||||||
*
|
*
|
||||||
* @return mixed Helper
|
* @return mixed Helper
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -95,7 +101,8 @@ class Mustache_HelperCollection {
|
|||||||
*
|
*
|
||||||
* @return boolean True if helper is present
|
* @return boolean True if helper is present
|
||||||
*/
|
*/
|
||||||
public function __isset($name) {
|
public function __isset($name)
|
||||||
|
{
|
||||||
return $this->has($name);
|
return $this->has($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +113,8 @@ class Mustache_HelperCollection {
|
|||||||
*
|
*
|
||||||
* @return boolean True if helper is present
|
* @return boolean True if helper is present
|
||||||
*/
|
*/
|
||||||
public function has($name) {
|
public function has($name)
|
||||||
|
{
|
||||||
return array_key_exists($name, $this->helpers);
|
return array_key_exists($name, $this->helpers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +125,8 @@ class Mustache_HelperCollection {
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
public function __unset($name) {
|
public function __unset($name)
|
||||||
|
{
|
||||||
$this->remove($name);
|
$this->remove($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +137,8 @@ class Mustache_HelperCollection {
|
|||||||
*
|
*
|
||||||
* @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);
|
||||||
}
|
}
|
||||||
@@ -141,7 +151,8 @@ class Mustache_HelperCollection {
|
|||||||
*
|
*
|
||||||
* Removes all helpers from this collection
|
* Removes all helpers from this collection
|
||||||
*/
|
*/
|
||||||
public function clear() {
|
public function clear()
|
||||||
|
{
|
||||||
$this->helpers = array();
|
$this->helpers = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +161,8 @@ class Mustache_HelperCollection {
|
|||||||
*
|
*
|
||||||
* @return boolean True if the collection is empty
|
* @return boolean True if the collection is empty
|
||||||
*/
|
*/
|
||||||
public function isEmpty() {
|
public function isEmpty()
|
||||||
|
{
|
||||||
return empty($this->helpers);
|
return empty($this->helpers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
/**
|
/**
|
||||||
* Mustache Template Loader interface.
|
* Mustache Template Loader interface.
|
||||||
*/
|
*/
|
||||||
interface Mustache_Loader {
|
interface Mustache_Loader
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a Template by name.
|
* Load a Template by name.
|
||||||
@@ -21,5 +22,5 @@ interface Mustache_Loader {
|
|||||||
*
|
*
|
||||||
* @return string Mustache Template source
|
* @return string Mustache Template source
|
||||||
*/
|
*/
|
||||||
function load($name);
|
public function load($name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,14 +27,16 @@
|
|||||||
* @implements Loader
|
* @implements Loader
|
||||||
* @implements MutableLoader
|
* @implements MutableLoader
|
||||||
*/
|
*/
|
||||||
class Mustache_Loader_ArrayLoader implements Mustache_Loader, Mustache_Loader_MutableLoader {
|
class Mustache_Loader_ArrayLoader implements Mustache_Loader, Mustache_Loader_MutableLoader
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ArrayLoader constructor.
|
* ArrayLoader constructor.
|
||||||
*
|
*
|
||||||
* @param array $templates Associative array of Template source (default: array())
|
* @param array $templates Associative array of Template source (default: array())
|
||||||
*/
|
*/
|
||||||
public function __construct(array $templates = array()) {
|
public function __construct(array $templates = array())
|
||||||
|
{
|
||||||
$this->templates = $templates;
|
$this->templates = $templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +47,8 @@ class Mustache_Loader_ArrayLoader implements Mustache_Loader, Mustache_Loader_Mu
|
|||||||
*
|
*
|
||||||
* @return string Mustache Template source
|
* @return string Mustache Template source
|
||||||
*/
|
*/
|
||||||
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.');
|
||||||
}
|
}
|
||||||
@@ -58,7 +61,8 @@ class Mustache_Loader_ArrayLoader implements Mustache_Loader, Mustache_Loader_Mu
|
|||||||
*
|
*
|
||||||
* @param array $templates
|
* @param array $templates
|
||||||
*/
|
*/
|
||||||
public function setTemplates(array $templates) {
|
public function setTemplates(array $templates)
|
||||||
|
{
|
||||||
$this->templates = $templates;
|
$this->templates = $templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +72,8 @@ class Mustache_Loader_ArrayLoader implements Mustache_Loader, Mustache_Loader_Mu
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $template Mustache Template source
|
* @param string $template Mustache Template source
|
||||||
*/
|
*/
|
||||||
public function setTemplate($name, $template) {
|
public function setTemplate($name, $template)
|
||||||
|
{
|
||||||
$this->templates[$name] = $template;
|
$this->templates[$name] = $template;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,8 @@
|
|||||||
*
|
*
|
||||||
* @implements Loader
|
* @implements Loader
|
||||||
*/
|
*/
|
||||||
class Mustache_Loader_FilesystemLoader implements Mustache_Loader {
|
class Mustache_Loader_FilesystemLoader implements Mustache_Loader
|
||||||
|
{
|
||||||
private $baseDir;
|
private $baseDir;
|
||||||
private $extension = '.mustache';
|
private $extension = '.mustache';
|
||||||
private $templates = array();
|
private $templates = array();
|
||||||
@@ -46,7 +47,8 @@ class Mustache_Loader_FilesystemLoader implements Mustache_Loader {
|
|||||||
* @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())
|
||||||
*/
|
*/
|
||||||
public function __construct($baseDir, array $options = array()) {
|
public function __construct($baseDir, array $options = array())
|
||||||
|
{
|
||||||
$this->baseDir = rtrim(realpath($baseDir), '/');
|
$this->baseDir = rtrim(realpath($baseDir), '/');
|
||||||
|
|
||||||
if (!is_dir($this->baseDir)) {
|
if (!is_dir($this->baseDir)) {
|
||||||
@@ -68,7 +70,8 @@ class Mustache_Loader_FilesystemLoader implements Mustache_Loader {
|
|||||||
*
|
*
|
||||||
* @return string Mustache Template source
|
* @return string Mustache Template source
|
||||||
*/
|
*/
|
||||||
public function load($name) {
|
public function load($name)
|
||||||
|
{
|
||||||
if (!isset($this->templates[$name])) {
|
if (!isset($this->templates[$name])) {
|
||||||
$this->templates[$name] = $this->loadFile($name);
|
$this->templates[$name] = $this->loadFile($name);
|
||||||
}
|
}
|
||||||
@@ -85,7 +88,8 @@ class Mustache_Loader_FilesystemLoader implements Mustache_Loader {
|
|||||||
*
|
*
|
||||||
* @return string Mustache Template source
|
* @return string Mustache Template source
|
||||||
*/
|
*/
|
||||||
private function loadFile($name) {
|
private function loadFile($name)
|
||||||
|
{
|
||||||
$fileName = $this->getFileName($name);
|
$fileName = $this->getFileName($name);
|
||||||
|
|
||||||
if (!file_exists($fileName)) {
|
if (!file_exists($fileName)) {
|
||||||
@@ -102,7 +106,8 @@ class Mustache_Loader_FilesystemLoader implements Mustache_Loader {
|
|||||||
*
|
*
|
||||||
* @return string Template file name
|
* @return string Template file name
|
||||||
*/
|
*/
|
||||||
private function getFileName($name) {
|
private function getFileName($name)
|
||||||
|
{
|
||||||
$fileName = $this->baseDir . '/' . $name;
|
$fileName = $this->baseDir . '/' . $name;
|
||||||
if (substr($fileName, 0 - strlen($this->extension)) !== $this->extension) {
|
if (substr($fileName, 0 - strlen($this->extension)) !== $this->extension) {
|
||||||
$fileName .= $this->extension;
|
$fileName .= $this->extension;
|
||||||
|
|||||||
@@ -12,14 +12,15 @@
|
|||||||
/**
|
/**
|
||||||
* Mustache Template mutable Loader interface.
|
* Mustache Template mutable Loader interface.
|
||||||
*/
|
*/
|
||||||
interface Mustache_Loader_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.
|
||||||
*
|
*
|
||||||
* @param array $templates
|
* @param array $templates
|
||||||
*/
|
*/
|
||||||
function setTemplates(array $templates);
|
public function setTemplates(array $templates);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a Template source by name.
|
* Set a Template source by name.
|
||||||
@@ -27,5 +28,5 @@ interface Mustache_Loader_MutableLoader {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $template Mustache Template source
|
* @param string $template Mustache Template source
|
||||||
*/
|
*/
|
||||||
function setTemplate($name, $template);
|
public function setTemplate($name, $template);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,8 @@
|
|||||||
*
|
*
|
||||||
* @implements Loader
|
* @implements Loader
|
||||||
*/
|
*/
|
||||||
class Mustache_Loader_StringLoader implements Mustache_Loader {
|
class Mustache_Loader_StringLoader implements Mustache_Loader
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a Template by source.
|
* Load a Template by source.
|
||||||
@@ -34,7 +35,8 @@ class Mustache_Loader_StringLoader implements Mustache_Loader {
|
|||||||
*
|
*
|
||||||
* @return string Mustache Template source
|
* @return string Mustache Template source
|
||||||
*/
|
*/
|
||||||
public function load($name) {
|
public function load($name)
|
||||||
|
{
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* 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 Mustache_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.
|
||||||
@@ -23,7 +24,8 @@ class Mustache_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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +39,8 @@ class Mustache_Parser {
|
|||||||
*
|
*
|
||||||
* @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 {
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* @abstract
|
* @abstract
|
||||||
*/
|
*/
|
||||||
abstract class Mustache_Template {
|
abstract class Mustache_Template
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Mustache_Engine
|
* @var Mustache_Engine
|
||||||
@@ -26,7 +27,8 @@ abstract class Mustache_Template {
|
|||||||
*
|
*
|
||||||
* @param Mustache_Engine $mustache
|
* @param Mustache_Engine $mustache
|
||||||
*/
|
*/
|
||||||
public function __construct(Mustache_Engine $mustache) {
|
public function __construct(Mustache_Engine $mustache)
|
||||||
|
{
|
||||||
$this->mustache = $mustache;
|
$this->mustache = $mustache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +45,8 @@ abstract class Mustache_Template {
|
|||||||
*
|
*
|
||||||
* @return string Rendered template
|
* @return string Rendered template
|
||||||
*/
|
*/
|
||||||
public function __invoke($context = array()) {
|
public function __invoke($context = array())
|
||||||
|
{
|
||||||
return $this->render($context);
|
return $this->render($context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +57,8 @@ abstract class Mustache_Template {
|
|||||||
*
|
*
|
||||||
* @return string Rendered template
|
* @return string Rendered template
|
||||||
*/
|
*/
|
||||||
public function render($context = array()) {
|
public function render($context = array())
|
||||||
|
{
|
||||||
return $this->renderInternal($this->prepareContextStack($context));
|
return $this->renderInternal($this->prepareContextStack($context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +104,8 @@ abstract class Mustache_Template {
|
|||||||
*
|
*
|
||||||
* @return boolean True if the value is 'iterable'
|
* @return boolean True if the value is 'iterable'
|
||||||
*/
|
*/
|
||||||
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)) {
|
||||||
@@ -126,7 +131,8 @@ abstract class Mustache_Template {
|
|||||||
*
|
*
|
||||||
* @return Mustache_Context
|
* @return Mustache_Context
|
||||||
*/
|
*/
|
||||||
protected function prepareContextStack($context = null) {
|
protected function prepareContextStack($context = null)
|
||||||
|
{
|
||||||
$stack = new Mustache_Context;
|
$stack = new Mustache_Context;
|
||||||
|
|
||||||
$helpers = $this->mustache->getHelpers();
|
$helpers = $this->mustache->getHelpers();
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ class Mustache_Tokenizer {
|
|||||||
*
|
*
|
||||||
* @return array Set of Mustache tokens
|
* @return array Set of Mustache tokens
|
||||||
*/
|
*/
|
||||||
public function scan($text, $delimiters = null) {
|
public function scan($text, $delimiters = null)
|
||||||
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
|
|
||||||
if ($delimiters = trim($delimiters)) {
|
if ($delimiters = trim($delimiters)) {
|
||||||
@@ -172,7 +173,8 @@ class Mustache_Tokenizer {
|
|||||||
/**
|
/**
|
||||||
* Helper function to reset tokenizer internal state.
|
* Helper function to reset tokenizer internal state.
|
||||||
*/
|
*/
|
||||||
private function reset() {
|
private function reset()
|
||||||
|
{
|
||||||
$this->state = self::IN_TEXT;
|
$this->state = self::IN_TEXT;
|
||||||
$this->tagType = null;
|
$this->tagType = null;
|
||||||
$this->tag = null;
|
$this->tag = null;
|
||||||
@@ -187,7 +189,8 @@ class Mustache_Tokenizer {
|
|||||||
/**
|
/**
|
||||||
* Flush the current buffer to a token.
|
* Flush the current buffer to a token.
|
||||||
*/
|
*/
|
||||||
private function flushBuffer() {
|
private function flushBuffer()
|
||||||
|
{
|
||||||
if (!empty($this->buffer)) {
|
if (!empty($this->buffer)) {
|
||||||
$this->tokens[] = array(self::TYPE => self::T_TEXT, self::VALUE => $this->buffer);
|
$this->tokens[] = array(self::TYPE => self::T_TEXT, self::VALUE => $this->buffer);
|
||||||
$this->buffer = '';
|
$this->buffer = '';
|
||||||
@@ -199,7 +202,8 @@ class Mustache_Tokenizer {
|
|||||||
*
|
*
|
||||||
* @return boolean True if the current line is all whitespace
|
* @return boolean True if the current line is all whitespace
|
||||||
*/
|
*/
|
||||||
private function lineIsWhitespace() {
|
private function lineIsWhitespace()
|
||||||
|
{
|
||||||
$tokensCount = count($this->tokens);
|
$tokensCount = count($this->tokens);
|
||||||
for ($j = $this->lineStart; $j < $tokensCount; $j++) {
|
for ($j = $this->lineStart; $j < $tokensCount; $j++) {
|
||||||
$token = $this->tokens[$j];
|
$token = $this->tokens[$j];
|
||||||
@@ -222,7 +226,8 @@ class Mustache_Tokenizer {
|
|||||||
*
|
*
|
||||||
* @param bool $noNewLine Suppress the newline? (default: false)
|
* @param bool $noNewLine Suppress the newline? (default: false)
|
||||||
*/
|
*/
|
||||||
private function filterLine($noNewLine = false) {
|
private function filterLine($noNewLine = false)
|
||||||
|
{
|
||||||
$this->flushBuffer();
|
$this->flushBuffer();
|
||||||
if ($this->seenTag && $this->lineIsWhitespace()) {
|
if ($this->seenTag && $this->lineIsWhitespace()) {
|
||||||
$tokensCount = count($this->tokens);
|
$tokensCount = count($this->tokens);
|
||||||
@@ -251,7 +256,8 @@ class Mustache_Tokenizer {
|
|||||||
*
|
*
|
||||||
* @return int New index value
|
* @return int New index value
|
||||||
*/
|
*/
|
||||||
private function changeDelimiters($text, $index) {
|
private function changeDelimiters($text, $index)
|
||||||
|
{
|
||||||
$startIndex = strpos($text, '=', $index) + 1;
|
$startIndex = strpos($text, '=', $index) + 1;
|
||||||
$close = '='.$this->ctag;
|
$close = '='.$this->ctag;
|
||||||
$closeIndex = strpos($text, $close, $index);
|
$closeIndex = strpos($text, $close, $index);
|
||||||
@@ -272,7 +278,8 @@ class Mustache_Tokenizer {
|
|||||||
*
|
*
|
||||||
* @return boolean True if this is a closing section tag
|
* @return boolean True if this is a closing section tag
|
||||||
*/
|
*/
|
||||||
private function tagChange($tag, $text, $index) {
|
private function tagChange($tag, $text, $index)
|
||||||
|
{
|
||||||
return substr($text, $index, strlen($tag)) === $tag;
|
return substr($text, $index, strlen($tag)) === $tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,16 @@
|
|||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_AutoloaderTest extends PHPUnit_Framework_TestCase {
|
class Mustache_Test_AutoloaderTest extends PHPUnit_Framework_TestCase
|
||||||
public function testRegister() {
|
{
|
||||||
|
public function testRegister()
|
||||||
|
{
|
||||||
$loader = Mustache_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 Mustache_Autoloader(dirname(__FILE__).'/../../fixtures/autoloader');
|
$loader = new Mustache_Autoloader(dirname(__FILE__).'/../../fixtures/autoloader');
|
||||||
|
|
||||||
$this->assertNull($loader->autoload('NonMustacheClass'));
|
$this->assertNull($loader->autoload('NonMustacheClass'));
|
||||||
|
|||||||
@@ -12,12 +12,14 @@
|
|||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_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 Mustache_Compiler;
|
$compiler = new Mustache_Compiler;
|
||||||
|
|
||||||
$compiled = $compiler->compile($source, $tree, $name, $customEscaper, $charset);
|
$compiled = $compiler->compile($source, $tree, $name, $customEscaper, $charset);
|
||||||
@@ -26,7 +28,8 @@ class Mustache_Test_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",
|
||||||
@@ -84,12 +87,14 @@ class Mustache_Test_CompilerTest extends PHPUnit_Framework_TestCase {
|
|||||||
/**
|
/**
|
||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testCompilerThrowsUnknownNodeTypeException() {
|
public function testCompilerThrowsUnknownNodeTypeException()
|
||||||
|
{
|
||||||
$compiler = new Mustache_Compiler;
|
$compiler = new Mustache_Compiler;
|
||||||
$compiler->compile('', array(array(Mustache_Tokenizer::TYPE => 'invalid')), 'SomeClass');
|
$compiler->compile('', array(array(Mustache_Tokenizer::TYPE => 'invalid')), 'SomeClass');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createTextToken($value) {
|
private function createTextToken($value)
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
|
Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT,
|
||||||
Mustache_Tokenizer::VALUE => $value,
|
Mustache_Tokenizer::VALUE => $value,
|
||||||
|
|||||||
@@ -12,8 +12,10 @@
|
|||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_ContextTest extends PHPUnit_Framework_TestCase {
|
class Mustache_Test_ContextTest extends PHPUnit_Framework_TestCase
|
||||||
public function testConstructor() {
|
{
|
||||||
|
public function testConstructor()
|
||||||
|
{
|
||||||
$one = new Mustache_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'));
|
||||||
@@ -32,7 +34,8 @@ class Mustache_Test_ContextTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('NAME', $three->find('name'));
|
$this->assertEquals('NAME', $three->find('name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPushPopAndLast() {
|
public function testPushPopAndLast()
|
||||||
|
{
|
||||||
$context = new Mustache_Context;
|
$context = new Mustache_Context;
|
||||||
$this->assertFalse($context->last());
|
$this->assertFalse($context->last());
|
||||||
|
|
||||||
@@ -52,7 +55,8 @@ class Mustache_Test_ContextTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertFalse($context->last());
|
$this->assertFalse($context->last());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFind() {
|
public function testFind()
|
||||||
|
{
|
||||||
$context = new Mustache_Context;
|
$context = new Mustache_Context;
|
||||||
|
|
||||||
$dummy = new Mustache_Test_TestDummy;
|
$dummy = new Mustache_Test_TestDummy;
|
||||||
@@ -94,18 +98,22 @@ class Mustache_Test_ContextTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Mustache_Test_TestDummy {
|
class Mustache_Test_TestDummy
|
||||||
|
{
|
||||||
public $name = 'dummy';
|
public $name = 'dummy';
|
||||||
|
|
||||||
public function __invoke() {
|
public function __invoke()
|
||||||
|
{
|
||||||
// nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function foo() {
|
public static function foo()
|
||||||
|
{
|
||||||
return '<foo>';
|
return '<foo>';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function bar() {
|
public function bar()
|
||||||
|
{
|
||||||
return '<bar>';
|
return '<bar>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,18 +12,21 @@
|
|||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase {
|
class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
private static $tempDir;
|
private static $tempDir;
|
||||||
|
|
||||||
public static function setUpBeforeClass() {
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
self::$tempDir = sys_get_temp_dir() . '/mustache_test';
|
self::$tempDir = sys_get_temp_dir() . '/mustache_test';
|
||||||
if (file_exists(self::$tempDir)) {
|
if (file_exists(self::$tempDir)) {
|
||||||
self::rmdir(self::$tempDir);
|
self::rmdir(self::$tempDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConstructor() {
|
public function testConstructor()
|
||||||
|
{
|
||||||
$loader = new Mustache_Loader_StringLoader;
|
$loader = new Mustache_Loader_StringLoader;
|
||||||
$partialsLoader = new Mustache_Loader_ArrayLoader;
|
$partialsLoader = new Mustache_Loader_ArrayLoader;
|
||||||
$mustache = new Mustache_Engine(array(
|
$mustache = new Mustache_Engine(array(
|
||||||
@@ -53,11 +56,13 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertFalse($mustache->hasHelper('baz'));
|
$this->assertFalse($mustache->hasHelper('baz'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFoo() {
|
public static function getFoo()
|
||||||
|
{
|
||||||
return 'foo';
|
return 'foo';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRender() {
|
public function testRender()
|
||||||
|
{
|
||||||
$source = '{{ foo }}';
|
$source = '{{ foo }}';
|
||||||
$data = array('bar' => 'baz');
|
$data = array('bar' => 'baz');
|
||||||
$output = 'TEH OUTPUT';
|
$output = 'TEH OUTPUT';
|
||||||
@@ -78,7 +83,8 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals($source, $mustache->source);
|
$this->assertEquals($source, $mustache->source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSettingServices() {
|
public function testSettingServices()
|
||||||
|
{
|
||||||
$loader = new Mustache_Loader_StringLoader;
|
$loader = new Mustache_Loader_StringLoader;
|
||||||
$tokenizer = new Mustache_Tokenizer;
|
$tokenizer = new Mustache_Tokenizer;
|
||||||
$parser = new Mustache_Parser;
|
$parser = new Mustache_Parser;
|
||||||
@@ -109,7 +115,8 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase {
|
|||||||
/**
|
/**
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
public function testCache() {
|
public function testCache()
|
||||||
|
{
|
||||||
$mustache = new Mustache_Engine(array(
|
$mustache = new Mustache_Engine(array(
|
||||||
'template_class_prefix' => '__whot__',
|
'template_class_prefix' => '__whot__',
|
||||||
'cache' => self::$tempDir,
|
'cache' => self::$tempDir,
|
||||||
@@ -128,11 +135,13 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase {
|
|||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
* @dataProvider getBadEscapers
|
* @dataProvider getBadEscapers
|
||||||
*/
|
*/
|
||||||
public function testNonCallableEscapeThrowsException($escape) {
|
public function testNonCallableEscapeThrowsException($escape)
|
||||||
|
{
|
||||||
new Mustache_Engine(array('escape' => $escape));
|
new Mustache_Engine(array('escape' => $escape));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBadEscapers() {
|
public function getBadEscapers()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
array('nothing'),
|
array('nothing'),
|
||||||
array('foo', 'bar'),
|
array('foo', 'bar'),
|
||||||
@@ -142,7 +151,8 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase {
|
|||||||
/**
|
/**
|
||||||
* @expectedException RuntimeException
|
* @expectedException RuntimeException
|
||||||
*/
|
*/
|
||||||
public function testImmutablePartialsLoadersThrowException() {
|
public function testImmutablePartialsLoadersThrowException()
|
||||||
|
{
|
||||||
$mustache = new Mustache_Engine(array(
|
$mustache = new Mustache_Engine(array(
|
||||||
'partials_loader' => new Mustache_Loader_StringLoader,
|
'partials_loader' => new Mustache_Loader_StringLoader,
|
||||||
));
|
));
|
||||||
@@ -150,7 +160,8 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase {
|
|||||||
$mustache->setPartials(array('foo' => '{{ foo }}'));
|
$mustache->setPartials(array('foo' => '{{ foo }}'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMissingPartialsTreatedAsEmptyString() {
|
public function testMissingPartialsTreatedAsEmptyString()
|
||||||
|
{
|
||||||
$mustache = new Mustache_Engine(array(
|
$mustache = new Mustache_Engine(array(
|
||||||
'partials_loader' => new Mustache_Loader_ArrayLoader(array(
|
'partials_loader' => new Mustache_Loader_ArrayLoader(array(
|
||||||
'foo' => 'FOO',
|
'foo' => 'FOO',
|
||||||
@@ -161,7 +172,8 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('FOOBAZ', $mustache->render('{{>foo}}{{>bar}}{{>baz}}', array()));
|
$this->assertEquals('FOOBAZ', $mustache->render('{{>foo}}{{>bar}}{{>baz}}', array()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHelpers() {
|
public function testHelpers()
|
||||||
|
{
|
||||||
$foo = array($this, 'getFoo');
|
$foo = array($this, 'getFoo');
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
$mustache = new Mustache_Engine(array('helpers' => array(
|
$mustache = new Mustache_Engine(array('helpers' => array(
|
||||||
@@ -196,19 +208,22 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('foo - BAR - __qux__', $tpl->render(array('qux' => "won't mess things up")));
|
$this->assertEquals('foo - BAR - __qux__', $tpl->render(array('qux' => "won't mess things up")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function wrapWithUnderscores($text) {
|
public static function wrapWithUnderscores($text)
|
||||||
|
{
|
||||||
return '__'.$text.'__';
|
return '__'.$text.'__';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testSetHelpersThrowsExceptions() {
|
public function testSetHelpersThrowsExceptions()
|
||||||
|
{
|
||||||
$mustache = new Mustache_Engine;
|
$mustache = new Mustache_Engine;
|
||||||
$mustache->setHelpers('monkeymonkeymonkey');
|
$mustache->setHelpers('monkeymonkeymonkey');
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function rmdir($path) {
|
private static function rmdir($path)
|
||||||
|
{
|
||||||
$path = rtrim($path, '/').'/';
|
$path = rtrim($path, '/').'/';
|
||||||
$handle = opendir($path);
|
$handle = opendir($path);
|
||||||
while (($file = readdir($handle)) !== false) {
|
while (($file = readdir($handle)) !== false) {
|
||||||
@@ -232,7 +247,8 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase {
|
|||||||
class MustacheStub extends Mustache_Engine {
|
class MustacheStub extends Mustache_Engine {
|
||||||
public $source;
|
public $source;
|
||||||
public $template;
|
public $template;
|
||||||
public function loadTemplate($source) {
|
public function loadTemplate($source)
|
||||||
|
{
|
||||||
$this->source = $source;
|
$this->source = $source;
|
||||||
|
|
||||||
return $this->template;
|
return $this->template;
|
||||||
|
|||||||
@@ -13,9 +13,11 @@
|
|||||||
* @group magic_methods
|
* @group magic_methods
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_Functional_CallTest extends PHPUnit_Framework_TestCase {
|
class Mustache_Test_Functional_CallTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
public function testCallEatsContext() {
|
public function testCallEatsContext()
|
||||||
|
{
|
||||||
$m = new Mustache_Engine;
|
$m = new Mustache_Engine;
|
||||||
$tpl = $m->loadTemplate('{{# foo }}{{ label }}: {{ name }}{{/ foo }}');
|
$tpl = $m->loadTemplate('{{# foo }}{{ label }}: {{ name }}{{/ foo }}');
|
||||||
|
|
||||||
@@ -28,9 +30,11 @@ class Mustache_Test_Functional_CallTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Mustache_Test_Functional_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';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
* @group examples
|
* @group examples
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_Functional_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.
|
||||||
@@ -25,7 +26,8 @@ class Mustache_Test_Functional_ExamplesTest extends PHPUnit_Framework_TestCase {
|
|||||||
* @param array $partials
|
* @param array $partials
|
||||||
* @param string $expected
|
* @param string $expected
|
||||||
*/
|
*/
|
||||||
public function testExamples($context, $source, $partials, $expected) {
|
public function testExamples($context, $source, $partials, $expected)
|
||||||
|
{
|
||||||
$mustache = new Mustache_Engine(array(
|
$mustache = new Mustache_Engine(array(
|
||||||
'partials' => $partials
|
'partials' => $partials
|
||||||
));
|
));
|
||||||
@@ -43,7 +45,8 @@ class Mustache_Test_Functional_ExamplesTest extends PHPUnit_Framework_TestCase {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getExamples() {
|
public function getExamples()
|
||||||
|
{
|
||||||
$path = realpath(dirname(__FILE__).'/../../../fixtures/examples');
|
$path = realpath(dirname(__FILE__).'/../../../fixtures/examples');
|
||||||
$examples = array();
|
$examples = array();
|
||||||
|
|
||||||
@@ -70,7 +73,8 @@ class Mustache_Test_Functional_ExamplesTest extends PHPUnit_Framework_TestCase {
|
|||||||
*
|
*
|
||||||
* @return array arguments for testExamples
|
* @return array arguments for testExamples
|
||||||
*/
|
*/
|
||||||
private function loadExample($path) {
|
private function loadExample($path)
|
||||||
|
{
|
||||||
$context = null;
|
$context = null;
|
||||||
$source = null;
|
$source = null;
|
||||||
$partials = array();
|
$partials = array();
|
||||||
@@ -114,7 +118,8 @@ class Mustache_Test_Functional_ExamplesTest extends PHPUnit_Framework_TestCase {
|
|||||||
*
|
*
|
||||||
* @return array $partials
|
* @return array $partials
|
||||||
*/
|
*/
|
||||||
private function loadPartials($path) {
|
private function loadPartials($path)
|
||||||
|
{
|
||||||
$partials = array();
|
$partials = array();
|
||||||
|
|
||||||
$handle = opendir($path);
|
$handle = opendir($path);
|
||||||
|
|||||||
@@ -13,15 +13,18 @@
|
|||||||
* @group lambdas
|
* @group lambdas
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_Functional_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_Engine;
|
$this->mustache = new Mustache_Engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRuntimeSectionCallback() {
|
public function testRuntimeSectionCallback()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{#doublewrap}}{{name}}{{/doublewrap}}');
|
$tpl = $this->mustache->loadTemplate('{{#doublewrap}}{{name}}{{/doublewrap}}');
|
||||||
|
|
||||||
$foo = new Mustache_Test_Functional_Foo;
|
$foo = new Mustache_Test_Functional_Foo;
|
||||||
@@ -30,7 +33,8 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework
|
|||||||
$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));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStaticSectionCallback() {
|
public function testStaticSectionCallback()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{#trimmer}} {{name}} {{/trimmer}}');
|
$tpl = $this->mustache->loadTemplate('{{#trimmer}} {{name}} {{/trimmer}}');
|
||||||
|
|
||||||
$foo = new Mustache_Test_Functional_Foo;
|
$foo = new Mustache_Test_Functional_Foo;
|
||||||
@@ -39,7 +43,8 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework
|
|||||||
$this->assertEquals($foo->name, $tpl->render($foo));
|
$this->assertEquals($foo->name, $tpl->render($foo));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testViewArraySectionCallback() {
|
public function testViewArraySectionCallback()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{#trim}} {{name}} {{/trim}}');
|
$tpl = $this->mustache->loadTemplate('{{#trim}} {{name}} {{/trim}}');
|
||||||
|
|
||||||
$foo = new Mustache_Test_Functional_Foo;
|
$foo = new Mustache_Test_Functional_Foo;
|
||||||
@@ -52,7 +57,8 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework
|
|||||||
$this->assertEquals($data['name'], $tpl->render($data));
|
$this->assertEquals($data['name'], $tpl->render($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMonsters() {
|
public function testMonsters()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{#title}}{{title}} {{/title}}{{name}}');
|
$tpl = $this->mustache->loadTemplate('{{#title}}{{title}} {{/title}}{{name}}');
|
||||||
|
|
||||||
$frank = new Mustache_Test_Functional_Monster();
|
$frank = new Mustache_Test_Functional_Monster();
|
||||||
@@ -67,28 +73,34 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Mustache_Test_Functional_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 function wrapWithEm($text) {
|
public function wrapWithEm($text)
|
||||||
|
{
|
||||||
return sprintf('<em>%s</em>', $text);
|
return sprintf('<em>%s</em>', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function wrapWithStrong($text) {
|
public function wrapWithStrong($text)
|
||||||
|
{
|
||||||
return sprintf('<strong>%s</strong>', $text);
|
return sprintf('<strong>%s</strong>', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function wrapWithBoth($text) {
|
public function wrapWithBoth($text)
|
||||||
|
{
|
||||||
return self::wrapWithStrong(self::wrapWithEm($text));
|
return self::wrapWithStrong(self::wrapWithEm($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function staticTrim($text) {
|
public static function staticTrim($text)
|
||||||
|
{
|
||||||
return trim($text);
|
return trim($text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Mustache_Test_Functional_Monster {
|
class Mustache_Test_Functional_Monster
|
||||||
|
{
|
||||||
public $title;
|
public $title;
|
||||||
public $name;
|
public $name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,17 +13,20 @@
|
|||||||
* @group mustache_injection
|
* @group mustache_injection
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_Functional_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_Engine;
|
$this->mustache = new Mustache_Engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
// interpolation
|
// interpolation
|
||||||
|
|
||||||
public function testInterpolationInjection() {
|
public function testInterpolationInjection()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{ a }}');
|
$tpl = $this->mustache->loadTemplate('{{ a }}');
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
@@ -34,7 +37,8 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|||||||
$this->assertEquals('{{ b }}', $tpl->render($data));
|
$this->assertEquals('{{ b }}', $tpl->render($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnescapedInterpolationInjection() {
|
public function testUnescapedInterpolationInjection()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{{ a }}}');
|
$tpl = $this->mustache->loadTemplate('{{{ a }}}');
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
@@ -48,7 +52,8 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|||||||
|
|
||||||
// sections
|
// sections
|
||||||
|
|
||||||
public function testSectionInjection() {
|
public function testSectionInjection()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{# a }}{{ b }}{{/ a }}');
|
$tpl = $this->mustache->loadTemplate('{{# a }}{{ b }}{{/ a }}');
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
@@ -60,7 +65,8 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|||||||
$this->assertEquals('{{ c }}', $tpl->render($data));
|
$this->assertEquals('{{ c }}', $tpl->render($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnescapedSectionInjection() {
|
public function testUnescapedSectionInjection()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{# a }}{{{ b }}}{{/ a }}');
|
$tpl = $this->mustache->loadTemplate('{{# a }}{{{ b }}}{{/ a }}');
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
@@ -75,7 +81,8 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|||||||
|
|
||||||
// partials
|
// partials
|
||||||
|
|
||||||
public function testPartialInjection() {
|
public function testPartialInjection()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{> partial }}');
|
$tpl = $this->mustache->loadTemplate('{{> partial }}');
|
||||||
$this->mustache->setPartials(array(
|
$this->mustache->setPartials(array(
|
||||||
'partial' => '{{ a }}',
|
'partial' => '{{ a }}',
|
||||||
@@ -89,7 +96,8 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|||||||
$this->assertEquals('{{ b }}', $tpl->render($data));
|
$this->assertEquals('{{ b }}', $tpl->render($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPartialUnescapedInjection() {
|
public function testPartialUnescapedInjection()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{> partial }}');
|
$tpl = $this->mustache->loadTemplate('{{> partial }}');
|
||||||
$this->mustache->setPartials(array(
|
$this->mustache->setPartials(array(
|
||||||
'partial' => '{{{ a }}}',
|
'partial' => '{{{ a }}}',
|
||||||
@@ -106,7 +114,8 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|||||||
|
|
||||||
// lambdas
|
// lambdas
|
||||||
|
|
||||||
public function testLambdaInterpolationInjection() {
|
public function testLambdaInterpolationInjection()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{ a }}');
|
$tpl = $this->mustache->loadTemplate('{{ a }}');
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
@@ -118,11 +127,13 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|||||||
$this->assertEquals('{{ c }}', $tpl->render($data));
|
$this->assertEquals('{{ c }}', $tpl->render($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function lambdaInterpolationCallback() {
|
public static function lambdaInterpolationCallback()
|
||||||
|
{
|
||||||
return '{{ b }}';
|
return '{{ b }}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLambdaSectionInjection() {
|
public function testLambdaSectionInjection()
|
||||||
|
{
|
||||||
$tpl = $this->mustache->loadTemplate('{{# a }}b{{/ a }}');
|
$tpl = $this->mustache->loadTemplate('{{# a }}b{{/ a }}');
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
@@ -134,7 +145,8 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T
|
|||||||
$this->assertEquals('{{ c }}', $tpl->render($data));
|
$this->assertEquals('{{ c }}', $tpl->render($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function lambdaSectionCallback($text) {
|
public static function lambdaSectionCallback($text)
|
||||||
|
{
|
||||||
return '{{ ' . $text . ' }}';
|
return '{{ ' . $text . ' }}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,13 @@
|
|||||||
* @group mustache-spec
|
* @group mustache-spec
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_Functional_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_Engine;
|
self::$mustache = new Mustache_Engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +29,8 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa
|
|||||||
* For some reason data providers can't mark tests skipped, so this test exists
|
* For some reason data providers can't mark tests skipped, so this test exists
|
||||||
* simply to provide a 'skipped' test if the `spec` submodule isn't initialized.
|
* simply to provide a 'skipped' test if the `spec` submodule isn't initialized.
|
||||||
*/
|
*/
|
||||||
public function testSpecInitialized() {
|
public function testSpecInitialized()
|
||||||
|
{
|
||||||
if (!file_exists(dirname(__FILE__).'/../../../../vendor/spec/specs/')) {
|
if (!file_exists(dirname(__FILE__).'/../../../../vendor/spec/specs/')) {
|
||||||
$this->markTestSkipped('Mustache spec submodule not initialized: run "git submodule update --init"');
|
$this->markTestSkipped('Mustache spec submodule not initialized: run "git submodule update --init"');
|
||||||
}
|
}
|
||||||
@@ -37,12 +40,14 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa
|
|||||||
* @group comments
|
* @group comments
|
||||||
* @dataProvider loadCommentSpec
|
* @dataProvider loadCommentSpec
|
||||||
*/
|
*/
|
||||||
public function testCommentSpec($desc, $source, $partials, $data, $expected) {
|
public function testCommentSpec($desc, $source, $partials, $data, $expected)
|
||||||
|
{
|
||||||
$template = self::loadTemplate($source, $partials);
|
$template = self::loadTemplate($source, $partials);
|
||||||
$this->assertEquals($expected, $template->render($data), $desc);
|
$this->assertEquals($expected, $template->render($data), $desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadCommentSpec() {
|
public function loadCommentSpec()
|
||||||
|
{
|
||||||
return $this->loadSpec('comments');
|
return $this->loadSpec('comments');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +55,14 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa
|
|||||||
* @group delimiters
|
* @group delimiters
|
||||||
* @dataProvider loadDelimitersSpec
|
* @dataProvider loadDelimitersSpec
|
||||||
*/
|
*/
|
||||||
public function testDelimitersSpec($desc, $source, $partials, $data, $expected) {
|
public function testDelimitersSpec($desc, $source, $partials, $data, $expected)
|
||||||
|
{
|
||||||
$template = self::loadTemplate($source, $partials);
|
$template = self::loadTemplate($source, $partials);
|
||||||
$this->assertEquals($expected, $template->render($data), $desc);
|
$this->assertEquals($expected, $template->render($data), $desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadDelimitersSpec() {
|
public function loadDelimitersSpec()
|
||||||
|
{
|
||||||
return $this->loadSpec('delimiters');
|
return $this->loadSpec('delimiters');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,12 +70,14 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa
|
|||||||
* @group interpolation
|
* @group interpolation
|
||||||
* @dataProvider loadInterpolationSpec
|
* @dataProvider loadInterpolationSpec
|
||||||
*/
|
*/
|
||||||
public function testInterpolationSpec($desc, $source, $partials, $data, $expected) {
|
public function testInterpolationSpec($desc, $source, $partials, $data, $expected)
|
||||||
|
{
|
||||||
$template = self::loadTemplate($source, $partials);
|
$template = self::loadTemplate($source, $partials);
|
||||||
$this->assertEquals($expected, $template->render($data), $desc);
|
$this->assertEquals($expected, $template->render($data), $desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadInterpolationSpec() {
|
public function loadInterpolationSpec()
|
||||||
|
{
|
||||||
return $this->loadSpec('interpolation');
|
return $this->loadSpec('interpolation');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,12 +86,14 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa
|
|||||||
* @group inverted-sections
|
* @group inverted-sections
|
||||||
* @dataProvider loadInvertedSpec
|
* @dataProvider loadInvertedSpec
|
||||||
*/
|
*/
|
||||||
public function testInvertedSpec($desc, $source, $partials, $data, $expected) {
|
public function testInvertedSpec($desc, $source, $partials, $data, $expected)
|
||||||
|
{
|
||||||
$template = self::loadTemplate($source, $partials);
|
$template = self::loadTemplate($source, $partials);
|
||||||
$this->assertEquals($expected, $template->render($data), $desc);
|
$this->assertEquals($expected, $template->render($data), $desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadInvertedSpec() {
|
public function loadInvertedSpec()
|
||||||
|
{
|
||||||
return $this->loadSpec('inverted');
|
return $this->loadSpec('inverted');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,12 +101,14 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa
|
|||||||
* @group partials
|
* @group partials
|
||||||
* @dataProvider loadPartialsSpec
|
* @dataProvider loadPartialsSpec
|
||||||
*/
|
*/
|
||||||
public function testPartialsSpec($desc, $source, $partials, $data, $expected) {
|
public function testPartialsSpec($desc, $source, $partials, $data, $expected)
|
||||||
|
{
|
||||||
$template = self::loadTemplate($source, $partials);
|
$template = self::loadTemplate($source, $partials);
|
||||||
$this->assertEquals($expected, $template->render($data), $desc);
|
$this->assertEquals($expected, $template->render($data), $desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadPartialsSpec() {
|
public function loadPartialsSpec()
|
||||||
|
{
|
||||||
return $this->loadSpec('partials');
|
return $this->loadSpec('partials');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,12 +116,14 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa
|
|||||||
* @group sections
|
* @group sections
|
||||||
* @dataProvider loadSectionsSpec
|
* @dataProvider loadSectionsSpec
|
||||||
*/
|
*/
|
||||||
public function testSectionsSpec($desc, $source, $partials, $data, $expected) {
|
public function testSectionsSpec($desc, $source, $partials, $data, $expected)
|
||||||
|
{
|
||||||
$template = self::loadTemplate($source, $partials);
|
$template = self::loadTemplate($source, $partials);
|
||||||
$this->assertEquals($expected, $template->render($data), $desc);
|
$this->assertEquals($expected, $template->render($data), $desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadSectionsSpec() {
|
public function loadSectionsSpec()
|
||||||
|
{
|
||||||
return $this->loadSpec('sections');
|
return $this->loadSpec('sections');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +135,8 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa
|
|||||||
* @access public
|
* @access public
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function loadSpec($name) {
|
private function loadSpec($name)
|
||||||
|
{
|
||||||
$filename = dirname(__FILE__) . '/../../../../vendor/spec/specs/' . $name . '.yml';
|
$filename = dirname(__FILE__) . '/../../../../vendor/spec/specs/' . $name . '.yml';
|
||||||
if (!file_exists($filename)) {
|
if (!file_exists($filename)) {
|
||||||
return array();
|
return array();
|
||||||
@@ -150,7 +166,8 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function loadTemplate($source, $partials) {
|
private static function loadTemplate($source, $partials)
|
||||||
|
{
|
||||||
self::$mustache->setPartials($partials);
|
self::$mustache->setPartials($partials);
|
||||||
|
|
||||||
return self::$mustache->loadTemplate($source);
|
return self::$mustache->loadTemplate($source);
|
||||||
|
|||||||
@@ -13,14 +13,17 @@
|
|||||||
* @group sections
|
* @group sections
|
||||||
* @group functional
|
* @group functional
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_Functional_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_Engine;
|
$this->mustache = new Mustache_Engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 Mustache_Test_Functional_Alpha));
|
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Alpha));
|
||||||
}
|
}
|
||||||
@@ -28,7 +31,8 @@ class Mustache_Test_Functional_ObjectSectionTest extends PHPUnit_Framework_TestC
|
|||||||
/**
|
/**
|
||||||
* @group magic_methods
|
* @group magic_methods
|
||||||
*/
|
*/
|
||||||
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 Mustache_Test_Functional_Beta));
|
$this->assertEquals('Foo', $tpl->render(new Mustache_Test_Functional_Beta));
|
||||||
}
|
}
|
||||||
@@ -36,12 +40,14 @@ class Mustache_Test_Functional_ObjectSectionTest extends PHPUnit_Framework_TestC
|
|||||||
/**
|
/**
|
||||||
* @group magic_methods
|
* @group magic_methods
|
||||||
*/
|
*/
|
||||||
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 Mustache_Test_Functional_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 Mustache_Test_Functional_Alpha;
|
$alpha = new Mustache_Test_Functional_Alpha;
|
||||||
$alpha->foo = new Mustache_Test_Functional_Delta;
|
$alpha->foo = new Mustache_Test_Functional_Delta;
|
||||||
@@ -49,46 +55,56 @@ class Mustache_Test_Functional_ObjectSectionTest extends PHPUnit_Framework_TestC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Mustache_Test_Functional_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 Mustache_Test_Functional_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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __isset($name) {
|
public function __isset($name)
|
||||||
|
{
|
||||||
return array_key_exists($name, $this->_data);
|
return array_key_exists($name, $this->_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __get($name) {
|
public function __get($name)
|
||||||
|
{
|
||||||
return $this->_data[$name];
|
return $this->_data[$name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Mustache_Test_Functional_Gamma {
|
class Mustache_Test_Functional_Gamma
|
||||||
|
{
|
||||||
public $bar;
|
public $bar;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct()
|
||||||
|
{
|
||||||
$this->bar = new Mustache_Test_Functional_Beta;
|
$this->bar = new Mustache_Test_Functional_Beta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Mustache_Test_Functional_Delta {
|
class Mustache_Test_Functional_Delta
|
||||||
|
{
|
||||||
protected $_name = 'Foo';
|
protected $_name = 'Foo';
|
||||||
|
|
||||||
public function name() {
|
public function name()
|
||||||
|
{
|
||||||
return $this->_name;
|
return $this->_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
|
class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase
|
||||||
public function testConstructor() {
|
{
|
||||||
|
public function testConstructor()
|
||||||
|
{
|
||||||
$foo = array($this, 'getFoo');
|
$foo = array($this, 'getFoo');
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
|
|
||||||
@@ -23,11 +25,13 @@ class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertSame($bar, $helpers->get('bar'));
|
$this->assertSame($bar, $helpers->get('bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFoo() {
|
public static function getFoo()
|
||||||
|
{
|
||||||
echo 'foo';
|
echo 'foo';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAccessorsAndMutators() {
|
public function testAccessorsAndMutators()
|
||||||
|
{
|
||||||
$foo = array($this, 'getFoo');
|
$foo = array($this, 'getFoo');
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
|
|
||||||
@@ -52,7 +56,8 @@ class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertTrue($helpers->has('bar'));
|
$this->assertTrue($helpers->has('bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMagicMethods() {
|
public function testMagicMethods()
|
||||||
|
{
|
||||||
$foo = array($this, 'getFoo');
|
$foo = array($this, 'getFoo');
|
||||||
$bar = 'BAR';
|
$bar = 'BAR';
|
||||||
|
|
||||||
@@ -88,7 +93,8 @@ class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
|
|||||||
/**
|
/**
|
||||||
* @dataProvider getInvalidHelperArguments
|
* @dataProvider getInvalidHelperArguments
|
||||||
*/
|
*/
|
||||||
public function testHelperCollectionIsntAfraidToThrowExceptions($helpers = array(), $actions = array(), $exception = null) {
|
public function testHelperCollectionIsntAfraidToThrowExceptions($helpers = array(), $actions = array(), $exception = null)
|
||||||
|
{
|
||||||
if ($exception) {
|
if ($exception) {
|
||||||
$this->setExpectedException($exception);
|
$this->setExpectedException($exception);
|
||||||
}
|
}
|
||||||
@@ -100,7 +106,8 @@ class Mustache_Test_HelperCollectionTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInvalidHelperArguments() {
|
public function getInvalidHelperArguments()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
'not helpers',
|
'not helpers',
|
||||||
|
|||||||
@@ -12,8 +12,10 @@
|
|||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_Loader_ArrayLoaderTest extends PHPUnit_Framework_TestCase {
|
class Mustache_Test_Loader_ArrayLoaderTest extends PHPUnit_Framework_TestCase
|
||||||
public function testConstructor() {
|
{
|
||||||
|
public function testConstructor()
|
||||||
|
{
|
||||||
$loader = new Mustache_Loader_ArrayLoader(array(
|
$loader = new Mustache_Loader_ArrayLoader(array(
|
||||||
'foo' => 'bar'
|
'foo' => 'bar'
|
||||||
));
|
));
|
||||||
@@ -21,7 +23,8 @@ class Mustache_Test_Loader_ArrayLoaderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('bar', $loader->load('foo'));
|
$this->assertEquals('bar', $loader->load('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetAndLoadTemplates() {
|
public function testSetAndLoadTemplates()
|
||||||
|
{
|
||||||
$loader = new Mustache_Loader_ArrayLoader(array(
|
$loader = new Mustache_Loader_ArrayLoader(array(
|
||||||
'foo' => 'bar'
|
'foo' => 'bar'
|
||||||
));
|
));
|
||||||
@@ -41,7 +44,8 @@ class Mustache_Test_Loader_ArrayLoaderTest extends PHPUnit_Framework_TestCase {
|
|||||||
/**
|
/**
|
||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testMissingTemplatesThrowExceptions() {
|
public function testMissingTemplatesThrowExceptions()
|
||||||
|
{
|
||||||
$loader = new Mustache_Loader_ArrayLoader;
|
$loader = new Mustache_Loader_ArrayLoader;
|
||||||
$loader->load('not_a_real_template');
|
$loader->load('not_a_real_template');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,15 +12,18 @@
|
|||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_Loader_FilesystemLoaderTest extends PHPUnit_Framework_TestCase {
|
class Mustache_Test_Loader_FilesystemLoaderTest extends PHPUnit_Framework_TestCase
|
||||||
public function testConstructor() {
|
{
|
||||||
|
public function testConstructor()
|
||||||
|
{
|
||||||
$baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
|
$baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
|
||||||
$loader = new Mustache_Loader_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(dirname(__FILE__).'/../../../fixtures/templates');
|
$baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
|
||||||
$loader = new Mustache_Loader_FilesystemLoader($baseDir);
|
$loader = new Mustache_Loader_FilesystemLoader($baseDir);
|
||||||
$this->assertEquals('one contents', $loader->load('one'));
|
$this->assertEquals('one contents', $loader->load('one'));
|
||||||
@@ -30,14 +33,16 @@ class Mustache_Test_Loader_FilesystemLoaderTest extends PHPUnit_Framework_TestCa
|
|||||||
/**
|
/**
|
||||||
* @expectedException RuntimeException
|
* @expectedException RuntimeException
|
||||||
*/
|
*/
|
||||||
public function testMissingBaseDirThrowsException() {
|
public function testMissingBaseDirThrowsException()
|
||||||
|
{
|
||||||
$loader = new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/not_a_directory');
|
$loader = new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/not_a_directory');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testMissingTemplateThrowsException() {
|
public function testMissingTemplateThrowsException()
|
||||||
|
{
|
||||||
$baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
|
$baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');
|
||||||
$loader = new Mustache_Loader_FilesystemLoader($baseDir);
|
$loader = new Mustache_Loader_FilesystemLoader($baseDir);
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,10 @@
|
|||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_Loader_StringLoaderTest extends PHPUnit_Framework_TestCase {
|
class Mustache_Test_Loader_StringLoaderTest extends PHPUnit_Framework_TestCase
|
||||||
public function testLoadTemplates() {
|
{
|
||||||
|
public function testLoadTemplates()
|
||||||
|
{
|
||||||
$loader = new Mustache_Loader_StringLoader;
|
$loader = new Mustache_Loader_StringLoader;
|
||||||
|
|
||||||
$this->assertEquals('foo', $loader->load('foo'));
|
$this->assertEquals('foo', $loader->load('foo'));
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_ParserTest extends PHPUnit_Framework_TestCase {
|
class Mustache_Test_ParserTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getTokenSets
|
* @dataProvider getTokenSets
|
||||||
@@ -109,12 +110,14 @@ class Mustache_Test_ParserTest extends PHPUnit_Framework_TestCase {
|
|||||||
* @dataProvider getBadParseTrees
|
* @dataProvider getBadParseTrees
|
||||||
* @expectedException LogicException
|
* @expectedException LogicException
|
||||||
*/
|
*/
|
||||||
public function testParserThrowsExceptions($tokens) {
|
public function testParserThrowsExceptions($tokens)
|
||||||
|
{
|
||||||
$parser = new Mustache_Parser;
|
$parser = new Mustache_Parser;
|
||||||
$parser->parse($tokens);
|
$parser->parse($tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBadParseTrees() {
|
public function getBadParseTrees()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
// no close
|
// no close
|
||||||
array(
|
array(
|
||||||
|
|||||||
@@ -12,14 +12,17 @@
|
|||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_TemplateTest extends PHPUnit_Framework_TestCase {
|
class Mustache_Test_TemplateTest extends PHPUnit_Framework_TestCase
|
||||||
public function testConstructor() {
|
{
|
||||||
|
public function testConstructor()
|
||||||
|
{
|
||||||
$mustache = new Mustache_Engine;
|
$mustache = new Mustache_Engine;
|
||||||
$template = new Mustache_Test_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_Engine;
|
$mustache = new Mustache_Engine;
|
||||||
$template = new Mustache_Test_TemplateStub($mustache);
|
$template = new Mustache_Test_TemplateStub($mustache);
|
||||||
@@ -36,14 +39,17 @@ class Mustache_Test_TemplateTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Mustache_Test_TemplateStub extends Mustache_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(Mustache_Context $context, $indent = '', $escape = false) {
|
public function renderInternal(Mustache_Context $context, $indent = '', $escape = false)
|
||||||
|
{
|
||||||
return $this->rendered;
|
return $this->rendered;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,17 +12,20 @@
|
|||||||
/**
|
/**
|
||||||
* @group unit
|
* @group unit
|
||||||
*/
|
*/
|
||||||
class Mustache_Test_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 Mustache_Tokenizer;
|
$tokenizer = new Mustache_Tokenizer;
|
||||||
$this->assertSame($expected, $tokenizer->scan($text, $delimiters));
|
$this->assertSame($expected, $tokenizer->scan($text, $delimiters));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTokens() {
|
public function getTokens()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
'text',
|
'text',
|
||||||
|
|||||||
+2
-1
@@ -9,6 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Mustache_Bar {
|
class Mustache_Bar
|
||||||
|
{
|
||||||
// nada
|
// nada
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -9,6 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Mustache_Foo {
|
class Mustache_Foo
|
||||||
|
{
|
||||||
// nada
|
// nada
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -9,6 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class NonMustacheClass {
|
class NonMustacheClass
|
||||||
|
{
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ChildContext {
|
class ChildContext
|
||||||
|
{
|
||||||
public $parent = array(
|
public $parent = array(
|
||||||
'child' => 'child works',
|
'child' => 'child works',
|
||||||
);
|
);
|
||||||
|
|||||||
+4
-2
@@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Comments {
|
class Comments
|
||||||
public function title() {
|
{
|
||||||
|
public function title()
|
||||||
|
{
|
||||||
return 'A Comedy of Errors';
|
return 'A Comedy of Errors';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-3
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Complex {
|
class Complex
|
||||||
|
{
|
||||||
public $header = 'Colors';
|
public $header = 'Colors';
|
||||||
|
|
||||||
public $item = array(
|
public $item = array(
|
||||||
@@ -9,11 +10,13 @@ class Complex {
|
|||||||
array('name' => 'blue', 'current' => false, 'url' => '#Blue'),
|
array('name' => 'blue', 'current' => false, 'url' => '#Blue'),
|
||||||
);
|
);
|
||||||
|
|
||||||
public function notEmpty() {
|
public function notEmpty()
|
||||||
|
{
|
||||||
return !($this->isEmpty());
|
return !($this->isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isEmpty() {
|
public function isEmpty()
|
||||||
|
{
|
||||||
return count($this->item) === 0;
|
return count($this->item) === 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -1,9 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Delimiters {
|
class Delimiters
|
||||||
|
{
|
||||||
public $start = "It worked the first time.";
|
public $start = "It worked the first time.";
|
||||||
|
|
||||||
public function middle() {
|
public function middle()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
array('item' => "And it worked the second time."),
|
array('item' => "And it worked the second time."),
|
||||||
array('item' => "As well as the third."),
|
array('item' => "As well as the third."),
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class DotNotation {
|
class DotNotation
|
||||||
|
{
|
||||||
public $person = array(
|
public $person = array(
|
||||||
'name' => array('first' => 'Chris', 'last' => 'Firescythe'),
|
'name' => array('first' => 'Chris', 'last' => 'Firescythe'),
|
||||||
'age' => 24,
|
'age' => 24,
|
||||||
|
|||||||
+4
-2
@@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class DoubleSection {
|
class DoubleSection
|
||||||
public function t() {
|
{
|
||||||
|
public function t()
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Escaped {
|
class Escaped
|
||||||
|
{
|
||||||
public $title = '"Bear" > "Shark"';
|
public $title = '"Bear" > "Shark"';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class GrandParentContext {
|
class GrandParentContext
|
||||||
|
{
|
||||||
public $grand_parent_id = 'grand_parent1';
|
public $grand_parent_id = 'grand_parent1';
|
||||||
public $parent_contexts = array();
|
public $parent_contexts = array();
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct()
|
||||||
|
{
|
||||||
$this->parent_contexts[] = array('parent_id' => 'parent1', 'child_contexts' => array(
|
$this->parent_contexts[] = array('parent_id' => 'parent1', 'child_contexts' => array(
|
||||||
array('child_id' => 'parent1-child1'),
|
array('child_id' => 'parent1-child1'),
|
||||||
array('child_id' => 'parent1-child2')
|
array('child_id' => 'parent1-child2')
|
||||||
|
|||||||
Vendored
+4
-2
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class I18n {
|
class I18n
|
||||||
|
{
|
||||||
|
|
||||||
// Variable to be interpolated
|
// Variable to be interpolated
|
||||||
public $name = 'Bob';
|
public $name = 'Bob';
|
||||||
@@ -14,7 +15,8 @@ class I18n {
|
|||||||
'My name is {{ name }}.' => 'Me llamo {{ name }}.',
|
'My name is {{ name }}.' => 'Me llamo {{ name }}.',
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function __trans($text) {
|
public static function __trans($text)
|
||||||
|
{
|
||||||
return isset(self::$dictionary[$text]) ? self::$dictionary[$text] : $text;
|
return isset(self::$dictionary[$text]) ? self::$dictionary[$text] : $text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ImplicitIterator {
|
class ImplicitIterator
|
||||||
|
{
|
||||||
public $data = array('Donkey Kong', 'Luigi', 'Mario', 'Peach', 'Yoshi');
|
public $data = array('Donkey Kong', 'Luigi', 'Mario', 'Peach', 'Yoshi');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class InvertedDoubleSection {
|
class InvertedDoubleSection
|
||||||
|
{
|
||||||
public $t = false;
|
public $t = false;
|
||||||
public $two = 'second';
|
public $two = 'second';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class InvertedSection {
|
class InvertedSection
|
||||||
|
{
|
||||||
public $repo = array();
|
public $repo = array();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class RecursivePartials {
|
class RecursivePartials
|
||||||
|
{
|
||||||
public $name = 'George';
|
public $name = 'George';
|
||||||
public $child = array(
|
public $child = array(
|
||||||
'name' => 'Dan',
|
'name' => 'Dan',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class SectionIteratorObjects {
|
class SectionIteratorObjects
|
||||||
|
{
|
||||||
public $start = "It worked the first time.";
|
public $start = "It worked the first time.";
|
||||||
|
|
||||||
protected $_data = array(
|
protected $_data = array(
|
||||||
@@ -8,7 +9,8 @@ class SectionIteratorObjects {
|
|||||||
array('item' => 'As well as the third.'),
|
array('item' => 'As well as the third.'),
|
||||||
);
|
);
|
||||||
|
|
||||||
public function middle() {
|
public function middle()
|
||||||
|
{
|
||||||
return new ArrayIterator($this->_data);
|
return new ArrayIterator($this->_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class SectionMagicObjects {
|
class SectionMagicObjects
|
||||||
|
{
|
||||||
public $start = "It worked the first time.";
|
public $start = "It worked the first time.";
|
||||||
|
|
||||||
public function middle() {
|
public function middle()
|
||||||
|
{
|
||||||
return new MagicObject();
|
return new MagicObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public $final = "Then, surprisingly, it worked the final time.";
|
public $final = "Then, surprisingly, it worked the final time.";
|
||||||
}
|
}
|
||||||
|
|
||||||
class MagicObject {
|
class MagicObject
|
||||||
|
{
|
||||||
protected $_data = array(
|
protected $_data = array(
|
||||||
'foo' => 'And it worked the second time.',
|
'foo' => 'And it worked the second time.',
|
||||||
'bar' => 'As well as the third.'
|
'bar' => 'As well as the third.'
|
||||||
);
|
);
|
||||||
|
|
||||||
public function __get($key) {
|
public function __get($key)
|
||||||
|
{
|
||||||
return isset($this->_data[$key]) ? $this->_data[$key] : NULL;
|
return isset($this->_data[$key]) ? $this->_data[$key] : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __isset($key) {
|
public function __isset($key)
|
||||||
|
{
|
||||||
return isset($this->_data[$key]);
|
return isset($this->_data[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class SectionObjects {
|
class SectionObjects
|
||||||
|
{
|
||||||
public $start = "It worked the first time.";
|
public $start = "It worked the first time.";
|
||||||
|
|
||||||
public function middle() {
|
public function middle()
|
||||||
|
{
|
||||||
return new SectionObject;
|
return new SectionObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public $final = "Then, surprisingly, it worked the final time.";
|
public $final = "Then, surprisingly, it worked the final time.";
|
||||||
}
|
}
|
||||||
|
|
||||||
class SectionObject {
|
class SectionObject
|
||||||
|
{
|
||||||
public $foo = 'And it worked the second time.';
|
public $foo = 'And it worked the second time.';
|
||||||
public $bar = 'As well as the third.';
|
public $bar = 'As well as the third.';
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -1,9 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Sections {
|
class Sections
|
||||||
|
{
|
||||||
public $start = "It worked the first time.";
|
public $start = "It worked the first time.";
|
||||||
|
|
||||||
public function middle() {
|
public function middle()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
array('item' => "And it worked the second time."),
|
array('item' => "And it worked the second time."),
|
||||||
array('item' => "As well as the third."),
|
array('item' => "As well as the third."),
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class SectionsNested {
|
class SectionsNested
|
||||||
|
{
|
||||||
public $name = 'Little Mac';
|
public $name = 'Little Mac';
|
||||||
|
|
||||||
public function enemies() {
|
public function enemies()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
'name' => 'Von Kaiser',
|
'name' => 'Von Kaiser',
|
||||||
|
|||||||
+4
-2
@@ -1,10 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Simple {
|
class Simple
|
||||||
|
{
|
||||||
public $name = "Chris";
|
public $name = "Chris";
|
||||||
public $value = 10000;
|
public $value = 10000;
|
||||||
|
|
||||||
public function taxed_value() {
|
public function taxed_value()
|
||||||
|
{
|
||||||
return $this->value - ($this->value * 0.4);
|
return $this->value - ($this->value * 0.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Unescaped {
|
class Unescaped
|
||||||
|
{
|
||||||
public $title = "Bear > Shark";
|
public $title = "Bear > Shark";
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class UTF8 {
|
class UTF8
|
||||||
|
{
|
||||||
public $test = '中文又来啦';
|
public $test = '中文又来啦';
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class UTF8Unescaped {
|
class UTF8Unescaped
|
||||||
|
{
|
||||||
public $test = '中文又来啦';
|
public $test = '中文又来啦';
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-3
@@ -8,16 +8,19 @@
|
|||||||
*
|
*
|
||||||
* `{{> tag }}` and `{{> tag}}` and `{{>tag}}` should all be equivalent.
|
* `{{> tag }}` and `{{> tag}}` and `{{>tag}}` should all be equivalent.
|
||||||
*/
|
*/
|
||||||
class Whitespace {
|
class Whitespace
|
||||||
|
{
|
||||||
public $foo = 'alpha';
|
public $foo = 'alpha';
|
||||||
|
|
||||||
public $bar = 'beta';
|
public $bar = 'beta';
|
||||||
|
|
||||||
public function baz() {
|
public function baz()
|
||||||
|
{
|
||||||
return 'gamma';
|
return 'gamma';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function qux() {
|
public function qux()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
array('key with space' => 'A'),
|
array('key with space' => 'A'),
|
||||||
array('key with space' => 'B'),
|
array('key with space' => 'B'),
|
||||||
|
|||||||
Reference in New Issue
Block a user