public function testPragmaReset()
 {
     $m = new Mustache('', array('symbol' => '>>>'));
     $this->assertEquals('>>>', $m->render('{{{symbol}}}'));
     $this->assertEquals('>>>', $m->render('{{%UNESCAPED}}{{symbol}}'));
     $this->assertEquals('>>>', $m->render('{{{symbol}}}'));
 }
 public function testDotNotationContext()
 {
     $m = new Mustache(null, array('items' => array(array('index' => 1, 'name' => 'foo'), array('index' => 2, 'name' => 'bar'), array('index' => 3, 'name' => 'baz'))));
     $this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR}}{{#items}}{{#.}}{{name}}{{/.}}{{/items}}'));
     $this->assertEquals('123', $m->render('{{%IMPLICIT-ITERATOR iterator=i}}{{%DOT-NOTATION}}{{#items}}{{i.index}}{{/items}}'));
     $this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR iterator=i}}{{%DOT-NOTATION}}{{#items}}{{i.name}}{{/items}}'));
 }
Example #3
0
 public function mustache($file)
 {
     $m = new Mustache();
     $this->helpers();
     $template = file_get_contents($this->options['path'] . '/views/' . $file . '.mustache');
     return $m->render($template, $this->value, array('recipe_preview' => file_get_contents($this->options['path'] . '/views/recipes/_preview.mustache'), 'recipe_preview_group' => file_get_contents($this->options['path'] . '/views/recipes/_preview_group.mustache'), 'form_errors' => file_get_contents($this->options['path'] . '/views/shared/_form_errors.mustache'), 'recipe_form' => file_get_contents($this->options['path'] . '/views/admin/recipes/_form.mustache')));
 }
Example #4
0
 /**
  * Renders a template using Mustache.php.
  *
  * @see View::render()
  * @param string $template The template name specified in Slim::render()
  * @return void
  */
 public function render($template)
 {
     require_once self::$mustacheDirectory . '/Mustache.php';
     $m = new Mustache();
     $contents = file_get_contents($this->templatesDirectory() . $template);
     echo $m->render($contents, $this->data);
 }
Example #5
0
 public function render($print = FALSE, $renderer = FALSE)
 {
     // Give helpers an entry to this view instance
     self::$instance = $this;
     if ($this->is_set('mustache_template') or stristr($this->kohana_filename, '.mus')) {
         if (isset($this->kohana_local_data['mustache_template']) and $this->kohana_local_data['mustache_template'] === FALSE) {
             return parent::render($print, $renderer);
         }
         $mustache_data = arr::merge(self::$kohana_global_data, $this->kohana_local_data);
         if (empty($this->kohana_local_data['mustache_partials'])) {
             $mustache_partials = array();
         } else {
             $mustache_partials = $this->kohana_local_data['mustache_partials'];
             unset($mustache_data['mustache_partials']);
         }
         $mustache = new Mustache();
         $output = $mustache->render(parent::render(FALSE), $mustache_data, $mustache_partials);
         $output = str_replace(array("\n", '  '), '', $output);
         if (!empty($this->kohana_local_data['mustache_escape_apostrophes'])) {
             $output = str_replace('\'', '\\\'', $output);
         }
         if ($print === TRUE) {
             // Display the output
             echo $output;
             return;
         }
         return $output;
     } else {
         return parent::render($print, $renderer);
     }
 }
Example #6
0
 /**
  * Renders a template using Mustache.php.
  *
  * @see View::render()
  * @param string $template The template name specified in Slim::render()
  * @return string
  */
 public function render($template)
 {
     require_once $this->mustacheDirectory . '/Mustache.php';
     $m = new Mustache();
     $contents = file_get_contents($this->getTemplatesDirectory() . '/' . ltrim($template, '/'));
     return $m->render($contents, $this->data);
 }
 public function testDotNotationSectionNames()
 {
     $data = array('parent' => array('items' => array(array('item' => array('index' => 1)), array('item' => array('index' => 2)), array('item' => array('index' => 3)), array('item' => array('index' => 4)), array('item' => array('index' => 5)))));
     $m = new Mustache('', $data);
     $this->assertEquals('.....', $m->render('{{%DOT-NOTATION}}{{#parent.items}}.{{/parent.items}}'));
     $this->assertEquals('12345', $m->render('{{%DOT-NOTATION}}{{#parent.items}}{{item.index}}{{/parent.items}}'));
     $this->assertEquals('12345', $m->render('{{%DOT-NOTATION}}{{#parent.items}}{{#item}}{{index}}{{/item}}{{/parent.items}}'));
 }
 public function testPragmaUnescaped()
 {
     $m = new Mustache(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}}}'));
 }
 public function testLambdaSectionInjection()
 {
     $data = array('a' => array($this, 'sectionLambda'), 'b' => '{{ c }}', 'c' => 'FAIL');
     $template = '{{# a }}b{{/ a }}';
     $output = '{{ c }}';
     $m = new Mustache();
     $this->assertEquals($output, $m->render($template, $data));
 }
Example #10
0
 public function getMarkup(&$args = null)
 {
     if (!is_array($args)) {
         $args = $this->getTemplateVars();
     }
     $m = new Mustache();
     return $m->render($this->template, $args);
 }
Example #11
0
 private static function mustache_render($file, $data)
 {
     if (!class_exists('Mustache')) {
         require dirname(FEE_MAIN_FILE) . '/lib/mustache/Mustache.php';
     }
     $template_path = dirname(__FILE__) . '/' . $file;
     $m = new Mustache();
     return $m->render(file_get_contents($template_path), $data);
 }
 public function testMustacheUsesDifferentLoadersToo()
 {
     $template = '{{> foo }} {{> bar }}';
     $data = array('truthy' => true, 'foo' => 'FOO', 'bar' => 'BAR');
     $output = 'FOO BAR';
     $m = new Mustache();
     $partials = new DifferentMustacheLoader();
     $this->assertEquals($output, $m->render($template, $data, $partials));
 }
Example #13
0
 public static function render($output, $variables)
 {
     try {
         $m = new Mustache();
         return $m->render($output, $variables);
     } catch (Exception $e) {
         return '';
     }
 }
Example #14
0
	public function testCallEatsContext() {
		$foo = new ClassWithCall();
		$foo->name = 'Bob';

		$template = '{{# foo }}{{ label }}: {{ name }}{{/ foo }}';
		$data = array('label' => 'name', 'foo' => $foo);
		$m = new Mustache($template, $data);

		$this->assertEquals('name: Bob', $m->render());
	}
Example #15
0
 public function render()
 {
     if (isset($_GET['JSON'])) {
         echo json_encode($this->JSON);
     } elseif (isset($_GET['JSONr'])) {
         echo '<pre>';
         print_r($this->JSON);
     } else {
         $mustache = new Mustache();
         echo $mustache->render($this->template, $this->JSON);
     }
 }
Example #16
0
 /**
  * Render given template with Mustache.
  *
  * @param string $templateFileName The filename of the template
  * @param array $data 			   The data to be rendered
  * @param string $suffix 		   Template file extension (default '.mustache')
  * @return void
  * @author Niklas Lindblad
  */
 public static function render($templateFileName, $data, $suffix = '.mustache')
 {
     $m = new Mustache();
     if (defined('APPLICATION_PATH')) {
         $templateFullFilename = APPLICATION_PATH . '/view/' . $templateFileName . $suffix;
     } else {
         $templateFileName = $templateFileName . $suffix;
     }
     if (file_exists($templateFullFilename)) {
         $template = @file_get_contents($templateFullFilename);
         echo $m->render($template, $data);
         return;
     }
     throw new Exception('View ' . $templateFileName . ' not found');
 }
Example #17
0
 protected function _findVariableInContext($tag_name, $context)
 {
     if (substr($tag_name, 0, 1) == '?') {
         return $this->_handleQuestion($tag_name, $context);
     }
     return parent::_findVariableInContext($tag_name, $context);
 }
 public function __construct()
 {
     parent::__construct();
     $this->parent_contexts[] = array('parent_id' => 'parent1', 'child_contexts' => array(array('child_id' => 'parent1-child1'), array('child_id' => 'parent1-child2')));
     $parent2 = new stdClass();
     $parent2->parent_id = 'parent2';
     $parent2->child_contexts = array(array('child_id' => 'parent2-child1'), array('child_id' => 'parent2-child2'));
     $this->parent_contexts[] = $parent2;
 }
 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);
 }
Example #20
0
 public function render($template = null, $view = null, $partials = null)
 {
     foreach (Kostache::$globals as $key => $value) {
         if (!isset($this->{$key}) and !method_exists($this, $key)) {
             $this->set($key, $value);
         }
     }
     return parent::render($template, $view, $partials);
 }
Example #21
0
 public function parse($template, $data = array(), $return = false)
 {
     $v = self::$CI->load->view($template, '', true);
     $t = parent::render($v, $data);
     if ($return == false) {
         $this->_obj =& get_instance();
         $this->_obj->output->append_output($t);
     }
     return $t;
 }
Example #22
0
 function f_issue($issue, $color = true)
 {
     $json = $this->_wgetit($this->_jira_host . '/rest/api/2.0.alpha1/issue/' . $issue, false, true);
     $json = $json->fields;
     # api doesn't redirect like html - so try url for new issue (and pray!)
     if (!$json) {
         list($action, $params, $newIssue) = $this->_getparams($issue, true);
         if ($newIssue && $newIssue != $issue) {
             return $this->f_issue($newIssue);
             // hopefully we don't get stuck in a loop!
         }
         die("404 - Not Found!\n");
     }
     $search = array("/\r/", "/\n*This message,.*?written consent of Advanced Energy Industries, Inc.\n*/s", "/[ ]+\$/m", "/^\\s\\s*/s", "/\\s*\\s\$/s", "/\n{2,}/s");
     $replace = array('', "\n\n", '', '', '', "\n\n");
     $view = array('issue' => $issue, 'wrap' => 74);
     foreach ($this->_colors as $key => $val) {
         $view[$key] = $color ? $val : '';
     }
     $comments = array();
     if ($json->comment->value) {
         foreach ($json->comment->value as $comment) {
             $dt = new DateTime($comment->created, $this->_tz_server());
             $dt->setTimezone($this->_tz_local());
             array_push($comments, array('id' => preg_replace("/^.*\\//", '', $comment->self), 'author' => $comment->author->displayName, 'created' => $dt->format('Y-m-d h:i A'), 'body' => wordwrap(preg_replace($search, $replace, $comment->body), $view['wrap'])));
         }
     }
     $view['comments'] = $comments;
     unset($json->comment);
     foreach (get_object_vars($json) as $key => $val) {
         if (isset($val->value->displayName)) {
             $view[$key] = $val->value->displayName;
         } elseif (isset($val->value->name)) {
             $view[$key] = $val->value->name;
         } elseif ($key == 'fixVersions') {
             $versions = array();
             foreach ($val->value ? $val->value : array() as $v) {
                 array_push($versions, $v->name);
             }
             $view[$key] = join(',', $versions);
         } elseif (isset($val->value)) {
             $value = $val->value;
             if (is_string($value)) {
                 if (preg_match("/^[0-9]{4}[-][0-9]{2}[-][0-9]{2}T/", $value, $dummy)) {
                     $dt = new DateTime($value, $this->_tz_server());
                     $dt->setTimezone($this->_tz_local());
                     $view[$key] = $dt->format('Y-m-d h:i A');
                 } elseif ($key == 'description') {
                     $view[$key] = wordwrap(preg_replace($search, $replace, $value), $view['wrap']);
                 } else {
                     $view[$key] = wordwrap($value, $view['wrap']);
                 }
             } else {
                 $view[$key] = $value;
             }
         }
     }
     # don't report updated if eq to created or resolved date
     if ($view['updated'] == $view['created'] || isset($view['resolutiondate']) && $view['updated'] == $view['resolutiondate']) {
         unset($view['updated']);
     }
     # don't display title and description if eq
     if ($view['summary'] == $view['description']) {
         unset($view['description']);
     }
     # templates using mustache
     $home_template = $this->_home('issue');
     $template = file_exists($home_template) ? file_get_contents($home_template) : file_get_contents($this->_local('issue'));
     $m = new Mustache();
     print $m->render($template, $view);
 }
Example #23
0
 public function testResetDelimiters()
 {
     $m = new Mustache(null, array('result' => 'success'));
     $this->assertEquals('success', $m->render('{{=[[ ]]=}}[[ result ]]'));
     $this->assertEquals('success', $m->render('{{=<< >>=}}<< result >>'));
     $this->assertEquals('success', $m->render('{{=<% %>=}}<% result %>'));
 }
Example #24
0
 public function get()
 {
     $m = new Mustache();
     $resource = 'pages';
     $tpl = 'templates/changes.json';
     /*
         $conn = new Mullet();
         $sources = array();
         $coll = $conn->user->profiles;
         $cursor = $coll->find();
         while( $cursor->hasNext() ) {
           $item = $cursor->getNext();
     */
     $items = array('last' => false, 'id' => '', 'title' => 'page 1', 'link' => '', 'permalink' => '', 'pubdate' => '', 'body' => '', 'has_enc' => false, 'enc_url' => '', 'enc_type' => '', 'enc_length' => 0);
     /*
         }
     */
     $collections[] = array('last' => false, 'title' => $resource, 'feedurl' => '', 'url' => '', 'lastupdate' => '', 'items' => $items);
     header('HTTP/1.1 200 OK');
     header('Content-Type: application/json');
     echo $m->render(file_get_contents($tpl), array('sources' => $collections));
 }
Example #25
0
<?php

/*
STEATITE - Pictures archive for qualitative analysis

Copyright (C) 2010-2012 Aurelien Benel

OFFICIAL WEB SITE
http://www.hypertopic.org/

LEGAL ISSUES
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License as published by the Free 
Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Affero General Public License for more details:
http://www.gnu.org/licenses/agpl.html
*/
include '../lib/Mustache.php';
$db = new PDO('sqlite:../attribute/database');
$query = $db->prepare("SELECT attribute_value FROM attributes " . "WHERE source_id=? AND attribute_name='name'");
$query->execute(array($_GET['id']));
$result = $query->fetch();
preg_match('#(.+)/entity/#', $_SERVER['REQUEST_URI'], $path);
$data = array('item' => $_GET['id'], 'service' => 'http://' . $_SERVER['HTTP_HOST'] . $path[1], 'name' => $result[0]);
$renderer = new Mustache();
header('content-type: text/xml');
echo $renderer->render(file_get_contents('../view/entity.xml'), $data);
Example #26
0
$edit_mode = false;
if ($code_id) {
    list($latest_revision, $html, $javascript, $css) = getCode($code_id, $revision, true);
} else {
    list($latest_revision, $html, $javascript, $css) = defaultCode();
}
$code_id = $code;
// always include revision *if* we have a code_id
if ($code_id && $revision) {
    $code_id .= '/' . $revision;
}
$code_id_path = ROOT;
if ($code_id) {
    $code_id_path = ROOT . '/' . $code_id;
}
// Include and capture the results of the show saved function.
ob_start();
showSaved($home);
$list_history = ob_get_clean();
$code_id_domain = preg_replace('/https?:\\/\\//', '', $code_id_path);
$gravatar = '';
if ($email) {
    $gravatar = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) . '?s=26';
}
$scripts = array();
if (!IS_PRODUCTION) {
    $scripts = json_decode(file_get_contents('../scripts.json'));
}
$view = file_get_contents('../views/index.html');
$mustache = new Mustache();
echo $mustache->render($view, array('token' => $csrf, 'root' => ROOT, 'static' => STATIC_URL, 'scripts' => $scripts, 'version' => VERSION, 'home' => $home, 'email' => $email, 'gravatar' => $gravatar, 'revision' => $revision, 'code_id' => $code_id, 'url' => $_SERVER['REQUEST_URI'], 'code_id_path' => $code_id_path, 'code_id_domain' => $code_id_domain, 'json_template' => json_encode(array('url' => $code_id_path, 'html' => $html, 'css' => $css, 'javascript' => $javascript)), 'custom_css' => isset($custom['css']) ? preg_replace('/^\\//', '', $custom['css']) : null, 'is_production' => IS_PRODUCTION, 'analytics_id' => ANALYTICS_ID, 'embed' => $embed, 'tips' => file_get_contents('../public/tips.json'), 'list_history' => $embed ? '' : $list_history, 'jsbin' => json_encode(array('root' => ROOT, 'version' => VERSION, 'state' => array('stream' => false, 'code' => isset($code) && $code ? $code : null, 'token' => $csrf, 'revision' => $revision), 'settings' => isset($custom['settings']) ? $custom['settings'] : array('panels' => array())))));
Example #27
0
 /**
  * @see TemplateEngine
  * @return string
  */
 public function renderToString($template_name, $presenter)
 {
     return $this->template_engine->render($this->template_loader[$template_name], $presenter, $this->template_loader);
 }
Example #28
0
 	AKA "Smart Jesse"
 
 	PS: you're dumb.
 */
 if (isset($_GET['cash_action']) && isset($_GET['element_id'])) {
     $requests = array('embed', $_GET['element_id']);
 }
 if ($requests) {
     require_once dirname(__FILE__) . '/constants.php';
     require_once CASH_PLATFORM_PATH;
     $cash_page_request = new CASHRequest(null);
     $initial_page_request = $cash_page_request->sessionGet('initial_page_request', 'script');
     if ($requests[0] != 'payload' || $requests[0] != 'json') {
         // open up some mustache in here:
         include_once dirname(CASH_PLATFORM_PATH) . '/lib/mustache/Mustache.php';
         $freddiemercury = new Mustache();
     }
     // pass basic no-cache headers
     header('P3P: CP="ALL CUR OUR"');
     // P3P privacy policy fix
     header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
     header("Cache-Control: post-check=0, pre-check=0", false);
     header("Pragma: no-cache");
     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
     header("Access-Control-Allow-Origin: *");
     header('Access-Control-Allow-Credentials: true');
     header('Access-Control-Allow-Headers: X-Requested-With, Content-Type');
     header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT');
     if ($requests[0] == 'embed' && isset($requests[1])) {
         $embed_location = false;
         $embed_geo = false;
 /**
  * @dataProvider recursiveSectionData
  */
 public function testRecursiveSections($template, $view, $result)
 {
     $m = new Mustache();
     $this->assertEquals($result, $m->render($template, $view));
 }
Example #30
0
 /**
  * Get the partial by name and add to the buffer
  * @param string $name Name of the partial
  * @return string Returns the rendered buffer
  * @since 1.0-sofia
  */
 protected function partial($name, $scope)
 {
     $buffer = '';
     if ($this->loader) {
         $template = $this->loader->load($name);
         if ($template) {
             $partial = new Mustache($template);
             $partial->parameters($this->parameters)->loader($this->loader)->escaper($this->escaper);
             $buffer .= $partial->render($scope);
         }
     }
     return $buffer;
 }