コード例 #1
0
 public function testPragmaReset()
 {
     $m = new Mustache('', array('symbol' => '>>>'));
     $this->assertEquals('>>>', $m->render('{{{symbol}}}'));
     $this->assertEquals('>>>', $m->render('{{%UNESCAPED}}{{symbol}}'));
     $this->assertEquals('>>>', $m->render('{{{symbol}}}'));
 }
コード例 #2
0
 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}}'));
 }
コード例 #3
0
 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}}}'));
 }
コード例 #4
0
 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}}'));
 }
コード例 #5
0
ファイル: view.php プロジェクト: ryanto/RecipeCan-Recipes
 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')));
 }
コード例 #6
0
ファイル: Bluebox_View.php プロジェクト: swk/bluebox
 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);
     }
 }
コード例 #7
0
ファイル: MustacheView.php プロジェクト: Jud/Slim
 /**
  * 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);
 }
コード例 #8
0
ファイル: Mustache.php プロジェクト: rubberneck/slim-extras
 /**
  * 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);
 }
コード例 #9
0
 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));
 }
コード例 #10
0
 public function getMarkup(&$args = null)
 {
     if (!is_array($args)) {
         $args = $this->getTemplateVars();
     }
     $m = new Mustache();
     return $m->render($this->template, $args);
 }
コード例 #11
0
 public static function render($output, $variables)
 {
     try {
         $m = new Mustache();
         return $m->render($output, $variables);
     } catch (Exception $e) {
         return '';
     }
 }
コード例 #12
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);
 }
コード例 #13
0
 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));
 }
コード例 #14
0
ファイル: kostache.php プロジェクト: raeldc/kojo-plugin
 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);
 }
コード例 #15
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;
 }
コード例 #16
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());
	}
コード例 #17
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);
     }
 }
コード例 #18
0
ファイル: View.php プロジェクト: nlindblad/putaspot
 /**
  * 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');
 }
コード例 #19
0
ファイル: index.php プロジェクト: pkdevboxy/jsbin
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())))));
コード例 #20
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);
 }
コード例 #21
0
ファイル: request.php プロジェクト: JamesLinus/platform
     }
     if (isset($_GET['geo'])) {
         $embed_geo = $_GET['geo'];
     }
     $template_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'getelementtemplate', 'element_id' => $requests[1], 'return_template' => 1));
     $template = $template_request->response['payload'];
     $embed_data = array();
     $element_markup = false;
     ob_start();
     CASHSystem::embedElement($requests[1], 'embed', $embed_location, $embed_geo);
     $embed_data['element_markup'] = ob_get_contents();
     $embed_data['cdn_url'] = defined('CDN_URL') ? CDN_URL : CASH_ADMIN_URL;
     ob_end_clean();
     header('Content-Type: text/html; charset=utf-8');
     $template = str_replace('</head>', '<script type="text/javascript" src="' . CASH_PUBLIC_URL . '/cashmusic.js"></script></head>', $template);
     $encoded_html = $freddiemercury->render($template, $embed_data);
     echo $encoded_html;
 } else {
     if ($initial_page_request) {
         if (in_array('payload', $requests)) {
             $output = $initial_page_request['response']['payload'];
         } else {
             $output = array('response' => $initial_page_request['response']);
         }
     } else {
         $output = array('response' => false);
     }
     if (in_array('payload', $requests)) {
         header('Content-Type: text/plain; charset=utf-8');
         if (is_array($output)) {
             echo json_encode($output);
コード例 #22
0
 /**
  * @dataProvider recursiveSectionData
  */
 public function testRecursiveSections($template, $view, $result)
 {
     $m = new Mustache();
     $this->assertEquals($result, $m->render($template, $view));
 }
コード例 #23
0
ファイル: MustacheTest.php プロジェクト: packfire/mustache
 public function testStandalone4()
 {
     $mustache = new Mustache();
     $mustache->template("Testing\n    {{#test}}\n    Testing\n    {{/test}}\nTesting");
     $output = $mustache->render();
     $this->assertEquals("Testing\nTesting", $output);
 }
コード例 #24
0
 /**
  * Renders the mustache
  * @return string
  */
 public function render()
 {
     $m = new \Mustache();
     return $m->render($this->markup, $this->data, $this->partials);
 }
コード例 #25
0
ファイル: MustacheTest.php プロジェクト: syamk/mustache.php
 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 %>'));
 }
コード例 #26
0
ファイル: entity.php プロジェクト: Slaals/Steatite
<?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);
コード例 #27
0
ファイル: index.php プロジェクト: voitto/eggs
 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));
 }
コード例 #28
0
ファイル: Mustache.php プロジェクト: packfire/mustache
 /**
  * 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;
 }
コード例 #29
0
ファイル: jira.php プロジェクト: rkbodenner/jira_cli
 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);
 }
コード例 #30
0
 /**
  * @group sections
  * @dataProvider loadSectionsSpec
  */
 public function testSectionsSpec($desc, $template, $data, $partials, $expected)
 {
     $m = new Mustache($template, $data, $partials);
     $this->assertEquals($expected, $m->render(), $desc);
 }