예제 #1
0
 public function testPragmaReset()
 {
     $m = new MustachePHP('', array('symbol' => '>>>'));
     $this->assertEquals('>>>', $m->render('{{{symbol}}}'));
     $this->assertEquals('>>>', $m->render('{{%UNESCAPED}}{{symbol}}'));
     $this->assertEquals('>>>', $m->render('{{{symbol}}}'));
 }
예제 #2
0
 public function testLambdaSectionInjection()
 {
     $data = array('a' => array($this, 'sectionLambda'), 'b' => '{{ c }}', 'c' => 'FAIL');
     $template = '{{# a }}b{{/ a }}';
     $output = '{{ c }}';
     $m = new MustachePHP();
     $this->assertEquals($output, $m->render($template, $data));
 }
 public function testPragmaUnescaped()
 {
     $m = new MustachePHP(null, array('title' => 'Bear > Shark'));
     $this->assertEquals('Bear > Shark', $m->render('{{%UNESCAPED}}{{title}}'));
     $this->assertEquals('Bear > Shark', $m->render('{{title}}'));
     $this->assertEquals('Bear > Shark', $m->render('{{%UNESCAPED}}{{{title}}}'));
     $this->assertEquals('Bear > Shark', $m->render('{{{title}}}'));
 }
예제 #4
0
 public function testMustacheUsesDifferentLoadersToo()
 {
     $template = '{{> foo }} {{> bar }}';
     $data = array('truthy' => true, 'foo' => 'FOO', 'bar' => 'BAR');
     $output = 'FOO BAR';
     $m = new MustachePHP();
     $partials = new DifferentMustacheLoader();
     $this->assertEquals($output, $m->render($template, $data, $partials));
 }
예제 #5
0
 public function testCallEatsContext()
 {
     $foo = new ClassWithCall();
     $foo->name = 'Bob';
     $template = '{{# foo }}{{ label }}: {{ name }}{{/ foo }}';
     $data = array('label' => 'name', 'foo' => $foo);
     $m = new MustachePHP($template, $data);
     $this->assertEquals('name: Bob', $m->render());
 }
예제 #6
0
 public function __construct($template = null, $view = null, $partials = null)
 {
     // Use an object of an arbitrary class as a View for this Mustache instance:
     $view = new StdClass();
     $view->name = 'ilmich';
     $view->data = array(array('name' => 'federica', 'age' => 27, 'gender' => 'female'), array('name' => 'marco', 'age' => 32, 'gender' => 'male'));
     $partials = array('children' => "{{#data}}{{name}} - {{age}} - {{gender}}\n{{/data}}");
     parent::__construct($template, $view, $partials);
 }
예제 #7
0
 /**
  * Ensure that Mustache doesn't double-render sections (allowing mustache injection).
  *
  * @group sections
  */
 public function testMustacheInjection()
 {
     $template = '{{#foo}}{{bar}}{{/foo}}';
     $view = array('foo' => true, 'bar' => '{{win}}', 'win' => 'FAIL');
     $m = new MustachePHP($template, $view);
     $this->assertEquals('{{win}}', $m->render());
 }
예제 #8
0
<?php

/*
AUTHENTICATING VIA THE BLOCKCHAINS
Using - http://blockstrap.com
*/
error_reporting(-1);
$php_base = dirname(__FILE__);
$template = file_get_contents($php_base . '/html/index.html');
$options = json_decode(file_get_contents($php_base . '/json/index.json'), true);
include_once $php_base . '/php/uploads.php';
include_once $php_base . '/php/mustache.php';
$uploads = new bs_uploads();
$mustache = new MustachePHP();
$html = $mustache->render($template, $options);
echo $html;
예제 #9
0
 public function display($html, $data)
 {
     $template = new MustachePHP();
     echo $template->render($html, $data);
 }
예제 #10
0
 /**
  * Render given template using supplied data
  *
  * @param $fileName string Template file path (absolute)
  * @param $data array Data to be rendered
  * @return string Template output
  * @throws Exception Thrown if any partial cannot be found
  */
 public function render($fileName, $data)
 {
     $realFileName = realpath($fileName);
     if (empty($realFileName)) {
         throw new Exception("Template \"{$fileName}\" was not found.");
     }
     $partials = $this->getDependencies($realFileName);
     $template = $partials[$realFileName];
     // Note: php-mustache segfaults when objects are present in data
     // so pre-process them before sending to renderer
     $data = $this->parseData($data);
     if (class_exists('Mustache')) {
         $mustache = new Mustache();
     } else {
         $mustache = new MustachePHP();
     }
     return $mustache->render($template, $data, $partials);
 }
예제 #11
0
 /**
  * @group sections
  * @dataProvider loadSectionsSpec
  */
 public function testSectionsSpec($desc, $template, $data, $partials, $expected)
 {
     $m = new MustachePHP($template, $data, $partials);
     $this->assertEquals($expected, $m->render(), $desc);
 }
 public function __construct($template = null, $view = null, $partials = null)
 {
     $this->wrap = array($this, 'wrapWithEm');
     parent::__construct($template, $view, $partials);
 }